From 0b89b6eb8a0d8d7d69d00ce66a87c9e1de66915a Mon Sep 17 00:00:00 2001 From: "Christopher R. Nelson" Date: Sun, 1 Nov 2026 01:17:43 -0400 Subject: Build a relx release for running as a systemd service Running the daemon via `rebar3 shell` under systemd exits immediately: stdin is /dev/null, so the interactive shell reads EOF and terminates the VM. Add a relx release (with a prod profile that bundles ERTS) and document running it with `bin/xdg_pipe_menu foreground` instead. Ship a custom vm.args rather than relx's default, which sets a fixed, publicly-known cookie while distribution listens on all interfaces. The node now uses ~/.erlang.cookie, binds distribution to 127.0.0.1, and is named xdg_pipe_menu@localhost so the release script's ping / remote_console / stop can reach it even where the hostname resolves to 127.0.1.1. Co-Authored-By: Claude Opus 5.5 --- README.md | 22 ++++++++++++++++++---- config/vm.args | 10 ++++++++++ rebar.config | 12 ++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 config/vm.args diff --git a/README.md b/README.md index c39385d..933c988 100644 --- a/README.md +++ b/README.md @@ -28,15 +28,21 @@ For a quick manual run (e.g. while developing): $ rebar3 shell --eval "application:ensure_all_started(xdg_pipe_menu)." -To have it start automatically with your session, add a systemd -user unit, e.g. `~/.config/systemd/user/xdg-pipe-menu.service`: +To run it as a service, build a production release (a self-contained +directory with its own copy of the Erlang runtime): + + $ rebar3 as prod release + +This produces `_build/prod/rel/xdg_pipe_menu`. Re-run the command +after pulling changes, then restart the service. To start it with +your session, add a systemd user unit, e.g. +`~/.config/systemd/user/xdg-pipe-menu.service`: [Unit] Description=XDG pipe menu daemon [Service] - WorkingDirectory=/path/to/xdg-pipe-menu - ExecStart=/usr/bin/rebar3 shell --eval "application:ensure_all_started(xdg_pipe_menu)." + ExecStart=/path/to/xdg-pipe-menu/_build/prod/rel/xdg_pipe_menu/bin/xdg_pipe_menu foreground Restart=on-failure [Install] @@ -44,6 +50,14 @@ user unit, e.g. `~/.config/systemd/user/xdg-pipe-menu.service`: then enable it with `systemctl --user enable --now xdg-pipe-menu`. +The running node is named `xdg_pipe_menu@localhost` and only accepts +Erlang distribution connections from localhost, using the cookie in +`~/.erlang.cookie` (see `config/vm.args`). That lets you manage it with +the release script: + + $ _build/prod/rel/xdg_pipe_menu/bin/xdg_pipe_menu ping + $ _build/prod/rel/xdg_pipe_menu/bin/xdg_pipe_menu remote_console + Openbox itself doesn't talk to the socket directly -- it invokes `bin/xdg_pipe_menu_menu` as the pipe menu command, which connects to the daemon's socket and prints whatever comes back (or, if the diff --git a/config/vm.args b/config/vm.args new file mode 100644 index 0000000..24183d6 --- /dev/null +++ b/config/vm.args @@ -0,0 +1,10 @@ +## Short node name, so `bin/xdg_pipe_menu remote_console` / `stop` work. +-sname xdg_pipe_menu@localhost + +## No -setcookie: fall back to the per-user random ~/.erlang.cookie +## rather than a fixed, publicly-known cookie. + +## Only accept distribution connections from this machine. +-kernel inet_dist_use_interface {127,0,0,1} + ++C multi_time_warp diff --git a/rebar.config b/rebar.config index 9071343..fa60f19 100644 --- a/rebar.config +++ b/rebar.config @@ -1,6 +1,18 @@ {erl_opts, [debug_info]}. {deps, [{fs, "11.4.1"}]}. +{relx, [ + {release, {xdg_pipe_menu, "0.1.0"}, [xdg_pipe_menu, sasl]}, + {vm_args, "config/vm.args"}, + {mode, dev} +]}. + +{profiles, [ + {prod, [ + {relx, [{mode, prod}]} + ]} +]}. + {shell, [ %% {config, "config/sys.config"}, {apps, [xdg_pipe_menu]} -- cgit v1.2.3