I have a few services (such as syncthing) set up as user-level systemd services on my Arch machine. They work great when I ssh
in, but when I connect using mosh
, they seem to start and then immediately stop again. For instance, I can connect with mosh, and do systemctl --user status syncthing
and get back that it's running or shutting down; then, repeating the command, I get
Failed to connect to bus: No such file or directory
Based on other similar questions, I've checked that $XDG_RUNTIME_DIR
is set within the mosh session:
$ echo $XDG_RUNTIME_DIR
/run/user/1000
Indeed, it seems the user manager shuts down cleanly, even though I'm still connected to the session:
$ systemctl status [email protected]
● [email protected] - User Manager for UID 1000
Loaded: loaded (/usr/lib/systemd/system/[email protected]; static; vendor preset: disabled)
Active: inactive (dead)
[...]
Aug 16 18:36:56 ip-172-70-3-138 systemd[7804]: Closed GnuPG cryptographic agent and passphrase cache (restricted).
Aug 16 18:36:56 ip-172-70-3-138 systemd[7804]: Reached target Shutdown.
Aug 16 18:36:56 ip-172-70-3-138 systemd[7804]: Starting Exit the Session...
Aug 16 18:36:56 ip-172-70-3-138 systemd[7804]: Received SIGRTMIN+24 from PID 7877 (kill).
Aug 16 18:36:56 ip-172-70-3-138 systemd[1]: Stopped User Manager for UID 1000.
How do I keep the services alive?
Update: Tmux sessions themselves don't start or keep systemd services alive, at least on my system. I haven't been able to find out whether that's correct behavior or not, but it seems to me a tmux session should keep systemd from closing things down. Consider the case where I'm editing a file using emacsclient
: I would expect that if my connection dropped for a minute, whether using mosh or tmux, the emacs daemon would stay alive.