【问题标题】:systemctl enable works but systemctl --user enable does notsystemctl enable 有效,但 systemctl --user enable 无效
【发布时间】:2017-05-09 16:02:04
【问题描述】:

我有一个运行 Ubuntu 16.04.1x64 的 DO droplet,我正在尝试将 IPFS 作为 systemd 服务运行。我已经按照here 的说明创建了一个用户“connor”并安装了 IPFS。我将服务作为“ipfs.service”存储在 ~/.config/systemd/user/ipfs.service 中,如下所示:

[Unit]
Description=IPFS Daemon

[Service]
Type=simple
ExecStart=/usr/local/bin/ipfs daemon
ExecStop=/usr/bin/pkill ipfs
Restart=always
User=Connor

[Install]
WantedBy=default.target

奇怪的是,如果我运行 systemctl --user start ipfs 它启动得很好。但是,运行 systemctl --user daemon-reload 然后 systemctl --user enable ipfs 我得到错误:

执行操作失败:没有那个文件或目录

但是,如果我运行 systemctl enable /home/connor/.config/systemd/user/ipfs.service -f 它运行得很好。我可以重新启动并运行 IPFS 命令就好了。我想以用户身份运行它,也想了解我做错了什么。

【问题讨论】:

  • 您是否正在使用connor 用户执行命令?请注意,使用 sudo 执行命令可能会将用户更改为 root

标签: service systemd systemctl ipfs


【解决方案1】:

请检查您是否正在使用connor 用户执行命令,您可以运行whoami 来查看用户执行命令。 (使用 sudo 运行命令会将用户更改为 root

此外,我看到服务文件中的用户是大写的(Connor 而不是 connor),这可能会带来其他问题,并且不需要,因为像 one proposed by Arch Linux wiki 这样的简单配置适用于用户守护进程。

请在下面找到我用于 ipfs 守护程序的配置(没有 User= 和不同的 Restart=,因为 Restart=always 在启动守护程序时会给我带来问题):

[Unit]
Description=IPFS daemon
After=network.target

[Service]
ExecStart=/usr/local/bin/ipfs daemon
Restart=on-failure

[Install]
WantedBy=default.target

【讨论】:

    猜你喜欢
    • 2017-08-27
    • 1970-01-01
    • 2018-06-19
    • 2022-01-23
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    相关资源
    最近更新 更多