systemd user service not found after reboot
I set up syncthing as a systemd user service on a 16.04 computer. Worked fine. Since I upgraded to 18.04 the service disappears upon reboot.
After rebooting, I see:
$ systemctl --user status syncthing.service
Unit syncthing.service could not be found.
And syncthing
is indeed not running.
Here is ~/.config/systemd/user/syncthing.service
(following the example, but note the binary is under my home dir):
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization
Documentation=man:syncthing(1)
[Service]
ExecStart=/home/user/syncthing-prefix/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
[Install]
WantedBy=default.target
I then run this:
$ systemctl --user enable syncthing.service
$ systemctl --user start syncthing.service
Following the setup instructions I used to install the user service originally.
After running the above two commands, I see:
$ systemctl --user status syncthing.service
● syncthing.service - Syncthing - Open Source Continuous File Synchronization
Loaded: loaded (/home/user/.config/systemd/user/syncthing.service; enabled;
Active: active (running) since Tue 2018-11-06 15:28:16 PST; 4s ago
Docs: man:syncthing(1)
Main PID: 4221 (syncthing)
CGroup: /user.slice/user-1000.slice/[email protected]/syncthing.service
└─4221 /home/user/syncthing-prefix/syncthing -no-b
Nov 06 15:28:18 kind syncthing[4221]: [XXXXX] INFO: Device XXXXXXX-XXXXXXX-XXXXX
Nov 06 15:28:18 kind syncthing[4221]: [XXXXX] INFO: Device XXXXXXX-XXXXXXX-XXXXX
Nov 06 15:28:18 kind syncthing[4221]: [XXXXX] INFO: Device XXXXXXX-XXXXXXX-XXXXX
Nov 06 15:28:18 kind syncthing[4221]: [XXXXX] INFO: GUI and API listening on 127
Nov 06 15:28:18 kind syncthing[4221]: [XXXXX] INFO: Access the GUI via the follo
Nov 06 15:28:18 kind syncthing[4221]: [XXXXX] INFO: Completed initial scan of se
Nov 06 15:28:18 kind syncthing[4221]: [XXXXX] INFO: Completed initial scan of se
Nov 06 15:28:18 kind syncthing[4221]: [XXXXX] INFO: Completed initial scan of se
Nov 06 15:28:19 kind syncthing[4221]: [XXXXX] INFO: Completed initial scan of se
Nov 06 15:28:20 kind syncthing[4221]: [XXXXX] INFO: Completed initial scan of se
as expected. And syncthing then works, as expected, until the next reboot.
Note that I have an encrypted home dir. This was the case when I was using 16.04, too.
Credit to https://unix.stackexchange.com/questions/417162/use-systemd-user-services-with-ecryptfs/545704#545704
It's a bug in the ecryptfs package configuration. You can use a quick fix: Open /etc/pam.d/common-session and switch the lines
session optional pam_systemd.so
session optional pam_ecryptfs.so unwrap
to
session optional pam_ecryptfs.so unwrap
session optional pam_systemd.so
so that pam_systemd.so is loaded after pam_ecryptfs.so