Socket-activate the agent with a systemd user unit #18
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The agent is started on demand by a window and outlives it
(
crates/terminalko-agent/src/client.rs,start_agent): a singlesetsid, neverwaited on, so it is reparented rather than killed when the window exits. It takes
an exclusive
flockso a second one steps aside, unlinks a stale socket, andexits by itself once it has no windows and no sessions
(
docs/spec/session-agent.md).The plan called socket activation an optional improvement, "not v1".
What it would add
A
terminalko-agent.socketuser unit, with the agent as its service:race between two windows starting an agent — the flock and the unlink logic
become belt-and-braces rather than load-bearing;
so
systemctl --user status terminalko-agentsays something useful, and itslog goes to the journal instead of a window's stderr;
loginctl enable-linger, which is the documented way to makesessions survive logout — today that only half works, because nothing restarts
the agent after the session scope is torn down.
What to be careful about
(
$XDG_RUNTIME_DIR/terminalko/agent.sock, overridable withTK_RUNTIME_DIR),or every window and
terminalkoctlinvocation has to learn a second path;on a system without systemd, and both paths have to end with exactly one agent
serving. Keep the flock;
Restart=set wrongly, an agentthat exits because it has nothing to do gets restarted immediately;
Accept=no(one agent, many connections), notAccept=yes;with
gio::SocketService::add_address. With socket activation it must insteadadopt the descriptor systemd passes (
$LISTEN_FDS, fd 3) —gio::Socket::from_fdplus
SocketListener::add_socket— and fall back to creating its own whennothing was passed. That fallback is what keeps the non-systemd path working.
Acceptance criteria
never spawns one directly.
it does today, including the tests, which start the agent as a plain process.
systemctl --user stop terminalko-agentstops sessions cleanly and a windowreconnecting starts a fresh agent.
docs/spec/session-agent.mddocuments both paths, and the unit is installed bymeson and listed in the rpm spec.
Notes
sd_listen_fdssemantics matter (LISTEN_PIDmust match); thelibsystemdcrate exists, but reading two environment variables directly avoids a
dependency.