简单 systemd 服务中的错误

简单 systemd 服务中的错误

我有这个系统服务:

$ sudo cat /etc/systemd/system/my_service123.service

    [Unit]
    Description=my_service123
    After=syslog.target

    [Service]
    ExecStart=./my_app --config main_cfg.conf
    Restart=on-abort
    WorkingDirectory=/home/user1/my_service_workspace
    SyslogIdentifier=my_service123
    User=user1

    [Install]
    WantedBy=multi-user.target

当我运行它时:

Failed to start my_service123.service: Unit my_service123.service has a bad unit file setting.
See system logs and 'systemctl status my_service123.service' for details.

$ sudo journalctl -u my_service123
No journal files were found.
-- No entries --

它出什么问题了?

$ sudo systemctl status my_service123
● my_service123.service - ton-node_01
     Loaded: bad-setting (Reason: Unit my_service123.service has a bad unit file setting.)
     Active: inactive (dead)

答案1

看一眼systemctl status my_service123.service。输出将显示类似的内容

Mar 04 14:39:02 hostname systemd[1]: /etc/systemd/system/my_service123.service:5: Neither a valid executable name nor an absolute path: <path>

尝试使用绝对路径,然后它应该可以工作。

答案2

您的设备包含这一行:

ExecStart=./my_app --config main_cfg.conf

从 systemd.service 手册页:

ExecStart=
对于每个指定的命令,第一个参数必须是绝对路径到可执行文件或没有斜杠的简单文件名

相关内容