Add runtime support: don't only listen on /tmp/frajtano1, script to add peer
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -28,3 +28,4 @@ frajtano-*.tar
|
|||||||
|
|
||||||
/.nix-hex
|
/.nix-hex
|
||||||
/.nix-mix
|
/.nix-mix
|
||||||
|
/result
|
||||||
|
|||||||
2
config/runtime.exs
Normal file
2
config/runtime.exs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import Config
|
||||||
|
config :frajtano, listen_path: Path.expand(System.get_env("FRAJTANO_DIR")) |> Path.join("agent.sock")
|
||||||
36
default.nix
36
default.nix
@@ -1,10 +1,12 @@
|
|||||||
{
|
{
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
mixRelease,
|
mixRelease,
|
||||||
fetchMixDeps,
|
|
||||||
elixir,
|
elixir,
|
||||||
}:
|
}: let
|
||||||
mixRelease rec {
|
|
||||||
pname = "frajtano";
|
pname = "frajtano";
|
||||||
|
pkg = mixRelease {
|
||||||
|
inherit pname;
|
||||||
version = "0.0.1";
|
version = "0.0.1";
|
||||||
|
|
||||||
inherit elixir;
|
inherit elixir;
|
||||||
@@ -13,12 +15,26 @@ mixRelease rec {
|
|||||||
name = "${pname}-source";
|
name = "${pname}-source";
|
||||||
filter = path: _type: baseNameOf path != "flake.nix" && baseNameOf path != "flake.lock";
|
filter = path: _type: baseNameOf path != "flake.nix" && baseNameOf path != "flake.lock";
|
||||||
};
|
};
|
||||||
mixFodDeps = fetchMixDeps {
|
|
||||||
pname = "mix-deps-${pname}";
|
|
||||||
inherit version src;
|
|
||||||
sha256 = "sha256-lknkq6b1yDOLgTpR/tPEk9UKqpqQT6H1N5g15M60nCA=";
|
|
||||||
};
|
|
||||||
|
|
||||||
ELIXIR_MAKE_CACHE_DIR = "/tmp/.elixir-make-cache";
|
ELIXIR_MAKE_CACHE_DIR = "/tmp/.elixir-make-cache";
|
||||||
meta.mainProgram = "${pname}";
|
meta.mainProgram = pname;
|
||||||
}
|
};
|
||||||
|
script = pkgs.writeShellScriptBin pname ''
|
||||||
|
set -eu
|
||||||
|
file="$FRAJTANO_DIR/cookie"
|
||||||
|
(umask 077; [ -f "$file" ] || ${pkgs.coreutils}/bin/head -c 128 /dev/urandom | ${pkgs.coreutils}/bin/base64 -w0 > "$file")
|
||||||
|
export RELEASE_COOKIE=$(${pkgs.coreutils}/bin/cat "$file")
|
||||||
|
run() {
|
||||||
|
exec ${lib.getExe pkg} "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
assimilate)
|
||||||
|
run rpc ":ok = \"$(echo -n "$2" | ${pkgs.coreutils}/bin/base64)\" |> Base.decode64!() |> Frajtano.Agent.add_peer()"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
run "$@"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
'';
|
||||||
|
in pkgs.symlinkJoin { name = pname; paths = [ script pkg ]; meta.mainProgram = pname; }
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ defmodule Frajtano.Agent do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_call({:add_peer, path}, _from, state) do
|
def handle_call({:add_peer, path}, _from, state) do
|
||||||
|
# TODO: deduplicate peers by socket path
|
||||||
case Peer.start(path) do
|
case Peer.start(path) do
|
||||||
{:ok, _} -> {:reply, :ok, state}
|
{:ok, _} -> {:reply, :ok, state}
|
||||||
{:error, error} -> {:reply, {:error, error}, state}
|
{:error, error} -> {:reply, {:error, error}, state}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ defmodule Frajtano.Supervisor do
|
|||||||
def init(:ok) do
|
def init(:ok) do
|
||||||
children = [
|
children = [
|
||||||
Frajtano.Agent,
|
Frajtano.Agent,
|
||||||
{Frajtano.Listener, ["/tmp/frajtano1"]},
|
{Frajtano.Listener, [Application.fetch_env!(:frajtano, :listen_path)]},
|
||||||
{Task.Supervisor, name: Frajtano.ClientSupervisor},
|
{Task.Supervisor, name: Frajtano.ClientSupervisor},
|
||||||
{DynamicSupervisor, name: Frajtano.Peer}
|
{DynamicSupervisor, name: Frajtano.Peer}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user