run as local service

This commit is contained in:
mithereal 2022-07-30 21:11:54 -07:00
parent 876bc2136b
commit e9cca35a54
10 changed files with 111 additions and 22 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
export FARSIDE_PORT="4001"

View File

@ -19,6 +19,24 @@ bottlenecks and rate-limiting.
To load custom services, you must paste a base64 encoded string into the FARSIDE_SERVICES_JSON field
you can encode your json at https://www.base64encode.org
## Standalone
One can create a standalone app via
```bash
MIX_ENV=cli && mix deps.get && mix release
cp _build/cli/rel/bakeware/farside /usr/local/bin/.
sudo chmod +x farside
farside
```
Run as a service
```bash
systemctl start farside
systemctl enable farside
```
## Demo
Farside's links work with the following structure: `farside.link/<service>/<path>`

View File

@ -14,4 +14,4 @@ config :farside,
queries: [
"weather",
"time"
]
]

View File

@ -0,0 +1,13 @@
[Unit]
Description=Farside - A redirecting service for FOSS alternative frontends.
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=10
ExecStart=/usr/local/bin/farside
[Install]
WantedBy=multi-user.target

View File

@ -94,15 +94,11 @@ defmodule Farside do
end
def save_results(file, data) do
case System.get_env("MIX_ENV") do
"prod" ->
nil
_ ->
{:ok, file} = File.open(file, [:append])
bin = :erlang.term_to_binary(data)
IO.binwrite(file, bin)
File.close(file)
if System.get_env("MIX_ENV") == "dev" do
{:ok, file} = File.open(file, [:append])
bin = :erlang.term_to_binary(data)
IO.binwrite(file, bin)
File.close(file)
end
end

View File

@ -5,14 +5,10 @@ defmodule Farside.Instances do
update_file = Application.fetch_env!(:farside, :update_file)
update_json = update_file <> ".json"
case System.get_env("MIX_ENV") do
"prod" ->
nil
if System.get_env("MIX_ENV") == "dev" do
File.rename(update_json, "#{update_file}-#{to_string(DateTime.utc_now()) <> ".json"}")
_ ->
File.rename(update_json, "#{update_file}-#{to_string(DateTime.utc_now()) <> ".json"}")
File.write(update_json, "")
File.write(update_json, "")
end
LastUpdated.value(DateTime.utc_now())

51
mix.exs
View File

@ -1,13 +1,24 @@
defmodule Farside.MixProject do
use Mix.Project
@source_url "https://github.com/benbusby/farside.git"
@version "0.1.1"
@app :farside
def project do
[
app: :farside,
version: "0.1.0",
app: @app,
version: @version,
name: "farside",
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
deps: deps()
source_url: @source_url,
start_permanent: Mix.env() == :prod || Mix.env() == :cli,
deps: deps(),
aliases: aliases(),
description: description(),
package: package(),
releases: [{@app, release()}],
preferred_cli_env: [release: :cli]
]
end
@ -19,6 +30,11 @@ defmodule Farside.MixProject do
]
end
defp aliases do
[
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
@ -26,7 +42,32 @@ defmodule Farside.MixProject do
{:jason, "~> 1.1"},
{:plug_attack, "~> 0.4.2"},
{:plug_cowboy, "~> 2.0"},
{:distillery, "~> 2.1"}
{:bakeware, runtime: false, only: :cli}
]
end
defp description() do
"A redirecting service for FOSS alternative frontends."
end
defp package() do
[
name: "farside",
files: ["lib", "mix.exs", "README*"],
maintainers: ["Ben Busby, Jason Clark"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/benbusby/farside"}
]
end
defp release do
[
overwrite: true,
cookie: "#{@app}_cookie",
quiet: true,
steps: [:assemble, &Bakeware.assemble/1],
strip_beams: Mix.env() == :cli
]
end
end

View File

@ -1,11 +1,13 @@
%{
"artificery": {:hex, :artificery, "0.4.3", "0bc4260f988dcb9dda4b23f9fc3c6c8b99a6220a331534fdf5bf2fd0d4333b02", [:mix], [], "hexpm", "12e95333a30e20884e937abdbefa3e7f5e05609c2ba8cf37b33f000b9ffc0504"},
"bakeware": {:hex, :bakeware, "0.2.4", "0aaf49b34f4bab2aa433f9ff1485d9401e421603160abd6d269c469fc7b65212", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "7b97bcf6fbeee53bb32441d6c495bf478d26f9575633cfef6831e421e86ada6d"},
"certifi": {:hex, :certifi, "2.8.0", "d4fb0a6bb20b7c9c3643e22507e42f356ac090a1dcea9ab99e27e0376d695eba", [:rebar3], [], "hexpm", "6ac7efc1c6f8600b08d625292d4bbf584e14847ce1b6b5c44d983d273e1097ea"},
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
"crontab": {:hex, :crontab, "1.1.10", "dc9bb1f4299138d47bce38341f5dcbee0aa6c205e864fba7bc847f3b5cb48241", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "1347d889d1a0eda997990876b4894359e34bfbbd688acbb0ba28a2795ca40685"},
"distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"},
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
"gen_stage": {:hex, :gen_stage, "1.1.2", "b1656cd4ba431ed02c5656fe10cb5423820847113a07218da68eae5d6a260c23", [:mix], [], "hexpm", "9e39af23140f704e2b07a3e29d8f05fd21c2aaf4088ff43cb82be4b9e3148d02"},
"hackney": {:hex, :hackney, "1.18.0", "c4443d960bb9fba6d01161d01cd81173089686717d9490e5d3606644c48d121f", [:rebar3], [{:certifi, "~>2.8.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "9afcda620704d720db8c6a3123e9848d09c87586dc1c10479c42627b905b5c5e"},
"httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"},

5
rel/env.bat.eex Normal file
View File

@ -0,0 +1,5 @@
@echo off
rem Set the release to work across nodes.
rem RELEASE_DISTRIBUTION must be "sname" (local), "name" (distributed) or "none".
rem set RELEASE_DISTRIBUTION=none
rem set RELEASE_NODE=<%= @release.name %>

17
rel/env.sh.eex Normal file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# Sets and enables heart (recommended only in daemon mode)
# case $RELEASE_COMMAND in
# daemon*)
# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND"
# export HEART_COMMAND
# export ELIXIR_ERL_OPTIONS="-heart"
# ;;
# *)
# ;;
# esac
# Set the release to work across nodes.
# RELEASE_DISTRIBUTION must be "sname" (local), "name" (distributed) or "none".
export RELEASE_DISTRIBUTION=none
# export RELEASE_NODE=<%= @release.name %>