【问题标题】:How to run an app as a daemon with systemd?如何使用 systemd 将应用程序作为守护进程运行?
【发布时间】:2017-03-19 06:48:23
【问题描述】:

我想将 syncthing 作为守护进程运行,尝试遵循 syncthing 手册中的 this hint here

我在 Fedora 25 和 syncthing 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

【问题讨论】:

    标签: linux daemon systemd fedora-25 syncthing


    【解决方案1】:

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

    Arch wiki 有一篇不错的文章:

    系统服务

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

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

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

    【讨论】:

    • 抱歉,上面代码中的“myuser”应该是我实际用户名的占位符。将编辑问题。感谢您的链接,将看看。
    • 好吧酷我只是想我会检查。尝试复制 ExecStart 行,看看它是否单独工作?
    • 抱歉,我不确定我能帮上忙……可以试试:SYSTEMD_LOG_LEVEL=debug sudo journalctl -u syncthing?祝你好运!
    • 您好,当我查看Fedora wiki 中的文档时,这被描述为我可以设置为引导参数的内容。我可以以某种方式在正在运行的电脑上设置它吗?干杯!
    最近更新 更多