重启后未找到 systemd 用户服务

重启后未找到 systemd 用户服务

将 syncthing 设置为 systemd 用户服务在 16.04 电脑上。运行良好。自从我升级到 18.04 后,服务在重启时消失。

重新启动后,我看到:

$ systemctl --user status syncthing.service 
Unit syncthing.service could not be found.

而且syncthing确实没有运行。

以下是~/.config/systemd/user/syncthing.service例子,但请注意二进制文件位于我的主目录下):

[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

然后我运行这个:

$ systemctl --user enable syncthing.service
$ systemctl --user start syncthing.service

按照我最初安装用户服务时使用的安装说明。

运行上述两个命令后,我看到:

$ 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

正如预期的那样。然后 syncthing 就可以正常工作,正如预期的那样,直到下次重新启动为止。

请注意,我有一个加密的主目录。当我使用 16.04 时也是如此。

答案1

归功于https://unix.stackexchange.com/questions/417162/use-systemd-user-services-with-ecryptfs/545704#545704


这是 ecryptfs 软件包配置中的一个错误。您可以使用快速修复:打开 /etc/pam.d/common-session 并切换行

session optional        pam_systemd.so
session optional        pam_ecryptfs.so unwrap

session optional        pam_ecryptfs.so unwrap
session optional        pam_systemd.so

因此 pam_systemd.so 在 pam_ecryptfs.so 之后加载

答案2

你有同样的问题https://unix.stackexchange.com/q/417162/116970

我建议您在该部分中添加After=一行,以便在挂载主文件夹后运行 syncthing。Requires=syncthing.service[Unit]

更具体地说,您可以尝试:

[Unit]
Description=Syncthing - Open Source Continuous File Synchronization
Documentation=man:syncthing(1)
After=home-yourusername.mount
Requires=home-yourusername.mount

...

并替换您的用户名使用您的用户名

相关内容