![将 init 脚本转换为 systemd - 可执行路径不是绝对的](https://linux22.com/image/1489888/%E5%B0%86%20init%20%E8%84%9A%E6%9C%AC%E8%BD%AC%E6%8D%A2%E4%B8%BA%20systemd%20-%20%E5%8F%AF%E6%89%A7%E8%A1%8C%E8%B7%AF%E5%BE%84%E4%B8%8D%E6%98%AF%E7%BB%9D%E5%AF%B9%E7%9A%84.png)
我正在尝试将我的一个初始化脚本转换为 systemd,但无济于事。
[Unit]
Description=My Service
After=network.target
Wants=mysql.service
[Service]
Type=oneshot
PIDFile=/var/run/MyService.pid
ExecStart=nohup /usr/local/bin/php -f /home/user/www/myservice.php > /dev/null 2>&1
[Install]
WantedBy=multi-user.target
输出:
root@localserver [/etc/systemd/system]# service myservice restart
Redirecting to /bin/systemctl restart myservice.service
Failed to restart myservice.service: Unit myservice.service failed to load: Invalid argument. See system logs and 'systemctl status myservice.service' for details.
root@localserver [/etc/systemd/system]# service myservice status
Redirecting to /bin/systemctl status myservice.service
â myservice.service - My Service
Loaded: error (Reason: Invalid argument)
Active: activating (start) since Tue 2016-04-12 12:48:18 BST; 1min 9s ago
Main PID: 22892 (php)
CGroup: /system.slice/myservice.service
ââ22892 /usr/local/bin/php -f /home/user/www/myservice.php
Apr 12 12:48:18 localserver systemd[1]: Starting My Service...
Apr 12 12:48:27 localserver systemd[1]: [/etc/systemd/system/myservice.service:9] Executable path is not absolute, ignoring: nohup /usr/local/bin/php -f /home/user/www/myservice.php > /dev/null 2>&1
Apr 12 12:48:27 localserver systemd[1]: myservice.service lacks both ExecStart= and ExecStop= setting. Refusing.
root@localserver [/etc/systemd/system]#
知道为什么它不起作用吗?
答案1
systemd 需要绝对路径:
ExecStart=/usr/bin/nohup /usr/local/bin/php -f /home/user/www/myservice.php > /dev/null 2>&1