Compare commits

...

3 Commits

Author SHA1 Message Date
bluepython508
66cb85ec1d Add systemd notification on listener available 2024-09-26 08:47:51 +01:00
bluepython508
4958944cb8 Log spawn info 2024-09-25 07:57:56 +01:00
bluepython508
dd60e5459b Don't crash on unbound variables 2024-09-24 23:22:47 +01:00
6 changed files with 14 additions and 6 deletions

View File

@@ -23,7 +23,7 @@
deps = fetchMixDeps { deps = fetchMixDeps {
pname = "mix-deps-${pname}"; pname = "mix-deps-${pname}";
inherit version src; inherit version src;
sha256 = "sha256-4g5lUlr5+l+mNVp0InZkx6X31g2cckI8NNQp37QgBis="; sha256 = "sha256-/9Ushiv0z1wJL9FwebUF4gem8IOwlUPnQuDBiXV0Ib8=";
}; };
hash = builtins.substring 11 32 "${./mix.lock}"; hash = builtins.substring 11 32 "${./mix.lock}";
in in
@@ -33,12 +33,12 @@
meta.mainProgram = pname; meta.mainProgram = pname;
}; };
script = pkgs.writeShellScriptBin pname '' script = pkgs.writeShellScriptBin pname ''
set -eu set -e
${pkgs.coreutils}/bin/mkdir -p $FRAJTANO_DIR ${pkgs.coreutils}/bin/mkdir -p $FRAJTANO_DIR
file="$FRAJTANO_DIR/cookie" file="$FRAJTANO_DIR/cookie"
(umask 077; [ -f "$file" ] || ${pkgs.coreutils}/bin/head -c 128 /dev/urandom | ${pkgs.coreutils}/bin/base64 -w0 > "$file") (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") export RELEASE_COOKIE=$(${pkgs.coreutils}/bin/cat "$file")
[ -n $RELEASE_NODE ] || export RELEASE_NODE="frajtano-$(${pkgs.coreutils}/bin/whoami)@$(${pkgs.coreutils}/bin/cat /etc/hostname)" [ -z $RELEASE_NODE ] && export RELEASE_NODE="frajtano-$(${pkgs.coreutils}/bin/whoami)@$(${pkgs.coreutils}/bin/cat /etc/hostname)"
run() { run() {
exec ${lib.getExe pkg} "$@" exec ${lib.getExe pkg} "$@"
} }

View File

@@ -50,8 +50,10 @@
systemd.user.services.frajtano = { systemd.user.services.frajtano = {
Unit.Description = "frajtano"; Unit.Description = "frajtano";
Unit.After = ["default.target"]; Unit.After = ["default.target"];
Service.Type = "notify";
Service.Environment = ["'FRAJTANO_DIR=${cfg.dir}'"]; Service.Environment = ["'FRAJTANO_DIR=${cfg.dir}'"];
Service.ExecStart = "${self.packages.${pkgs.system}.default}/bin/frajtano start"; Service.ExecSearchPath = ["${self.packages.${pkgs.system}.default}/bin"];
Service.ExecStart = "frajtano start";
Install.WantedBy = ["default.target"]; Install.WantedBy = ["default.target"];
}; };

View File

@@ -22,6 +22,7 @@ defmodule Frajtano.Supervisor do
Frajtano.Agent, Frajtano.Agent,
{Task.Supervisor, name: Frajtano.ClientSupervisor}, {Task.Supervisor, name: Frajtano.ClientSupervisor},
{Frajtano.Listener, [Application.fetch_env!(:frajtano, :listen_path)]}, {Frajtano.Listener, [Application.fetch_env!(:frajtano, :listen_path)]},
:systemd.ready(),
] ]
Supervisor.init(children, strategy: :one_for_one) Supervisor.init(children, strategy: :one_for_one)

View File

@@ -29,6 +29,7 @@ defmodule Frajtano.Peer do
end end
def start({:spawn, spec}) do def start({:spawn, spec}) do
Logger.info("Spawning #{inspect spec}")
DynamicSupervisor.start_child(Frajtano.PeerSupervisor, {Spawner, spec}) DynamicSupervisor.start_child(Frajtano.PeerSupervisor, {Spawner, spec})
end end
@@ -46,13 +47,14 @@ defmodule Frajtano.Peer do
end end
@impl true @impl true
def init({path, :spawned, _}) do def init({path, :spawned, spec}) do
if File.exists?(path) do if File.exists?(path) do
{:ok, conn} = :gen_tcp.connect({:local, path}, 0, [:binary, active: :once]) {:ok, conn} = :gen_tcp.connect({:local, path}, 0, [:binary, active: :once])
Logger.info("Connected to #{inspect spec}")
{:ok, %{conn: conn, clients: :queue.new(), buffer: <<>>}} {:ok, %{conn: conn, clients: :queue.new(), buffer: <<>>}}
else else
Process.sleep(100) Process.sleep(100)
init({path, :spawned, nil}) init({path, :spawned, spec})
end end
end end

View File

@@ -22,6 +22,7 @@ defmodule Frajtano.MixProject do
[ [
{:muontrap, "~> 1.0"}, {:muontrap, "~> 1.0"},
{:temp, "~> 0.4"}, {:temp, "~> 0.4"},
{:systemd, "~> 0.6"},
] ]
end end
end end

View File

@@ -1,5 +1,7 @@
%{ %{
"elixir_make": {:hex, :elixir_make, "0.8.4", "4960a03ce79081dee8fe119d80ad372c4e7badb84c493cc75983f9d3bc8bde0f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "6e7f1d619b5f61dfabd0a20aa268e575572b542ac31723293a4c1a567d5ef040"}, "elixir_make": {:hex, :elixir_make, "0.8.4", "4960a03ce79081dee8fe119d80ad372c4e7badb84c493cc75983f9d3bc8bde0f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "6e7f1d619b5f61dfabd0a20aa268e575572b542ac31723293a4c1a567d5ef040"},
"enough": {:hex, :enough, "0.1.0", "0254710c52d324e2dadde54cb56fbb80a792c2eb285669b8379efd0752bf89f0", [:rebar3], [], "hexpm", "0460c7abda5f5e0ea592b12bc6976b8a5c4b96e42f332059cd396525374bf9a1"},
"muontrap": {:hex, :muontrap, "1.5.0", "bf5c273872379968615a39974458328209ac97fa1f588396192131ff973d1ca2", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "daf605e877f60b5be9215e3420d7971fc468677b29921e40915b15fd928273d4"}, "muontrap": {:hex, :muontrap, "1.5.0", "bf5c273872379968615a39974458328209ac97fa1f588396192131ff973d1ca2", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "daf605e877f60b5be9215e3420d7971fc468677b29921e40915b15fd928273d4"},
"systemd": {:hex, :systemd, "0.6.2", "aaa24f1e3e6cb978c45369768b1abd766a0dbff637ed61254ca64797bcec9963", [:rebar3], [{:enough, "~> 0.1.0", [hex: :enough, repo: "hexpm", optional: false]}], "hexpm", "5062b911800c1ab05157c7bf9a9fbe23dd24c58891c87fd12d2e3ed8fc1708b8"},
"temp": {:hex, :temp, "0.4.9", "eb6355bfa7925a568b3d9eb3bb57e89aa6d2b78bfe8dfb6b698e090631b7f41f", [:mix], [], "hexpm", "bc8bf7b27d9105bef933ef4bf4ba37ac6b899dbeba329deaa88c60b62d6b4b6d"}, "temp": {:hex, :temp, "0.4.9", "eb6355bfa7925a568b3d9eb3bb57e89aa6d2b78bfe8dfb6b698e090631b7f41f", [:mix], [], "hexpm", "bc8bf7b27d9105bef933ef4bf4ba37ac6b899dbeba329deaa88c60b62d6b4b6d"},
} }