如何使用systemd作为守护程序运行应用程序?

时间:2017-03-19 06:48:24

标签: linux daemon systemd fedora-25 syncthing

我想将syncthing作为守护程序运行,尝试从syncthing手册中关注this hint here

我在Fedora 25上运行并同步0.14.24。

可执行文件通过/usr/bin/syncthing中的符号链接指向,可由任何用户执行(已成功测试)。

要启用该服务,我正在键入(myuser将替换为我在下面所有的实际用户名):

sudo systemctl enable sycnthing@myuser.service

返回:

Failed to lookup unit file state: Invalid argument

我不明白错误信息的含义。我怎样才能将syncthing作为守护进程运行?

syncthing@myuser.service:

[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=man:syncthing(1)
After=network.target
Wants=syncthing-inotify@myuser.service  # I also commented this line out; didn't have an effect

[Service]
User=%i
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4

[Install]
WantedBy=multi-user.target

1 个答案:

答案 0 :(得分:0)

我认为myuser应该替代您的实际用户名。

Arch wiki有一篇非常好的文章:

  

系统服务

     

将Syncthing作为系统服务运行可确保它在启动时运行,即使用户没有活动会话,也可以在服务器上使用它。

     

启用并启动syncthing@myuser.service,其中myuser是您用户的实际名称。

信用:https://wiki.archlinux.org/index.php/Syncthing