
早安,
我們正在嘗試在 Raspberry PIZero Wireless 上啟動自訂服務。我們使用的程式適用於 Ubuntu 14.04 下的 PI3。 PiZero 運行 2017-04-10-raspbian-jessie。我將在下面使用名稱 CUSTOM_SERVICE。
我嘗試了不同的事情但沒有成功。查詢服務報告的狀態:
sudo systemctl status CUSTOM_SERVICE.service
● CUSTOM_SERVICE.service - Custom service
Loaded: loaded (/etc/systemd/system/CUSTOM_SERVICE.service; enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2017-04-26 14:44:40 UTC; 32s ago
Process: 1516 ExecStart=/usr/local/etc/startCustomService (code=exited, status=203/EXEC)
Main PID: 1516 (code=exited, status=203/EXEC)
Apr 26 14:44:40 raspberrypi systemd[1]: CUSTOM_SERVICE.service: main process exited, code=exited, status=203/EXEC
Apr 26 14:44:40 raspberrypi systemd[1]: Unit CUSTOM_SERVICE.service entered failed state.
使用命令:
sudo ls -l /etc/systemd/system/multi-user.target.wants/*.service
輸出:
...
lrwxrwxrwx 1 root root 40 Apr 10 09:24 /etc/systemd/system/multi-user.target.wants/avahi-daemon.service -> /lib/systemd/system/avahi-daemon.service
lrwxrwxrwx 1 root root 38 Apr 26 13:53 /etc/systemd/system/multi-user.target.wants/CUSTOM_SERVICE.service -> /etc/systemd/system/CUSTOM_SERVICE.service
...
服務單元檔案定義為:
more /etc/systemd/system/multi-user.target.wants/CUSTOM_SERVICE.service
[Unit]
Description=Custom service
After=network-online.target
[Service]
Type=simple
RestartSec=60
Restart=always
ExecStart=/usr/local/etc/startCustomService
[Install]
WantedBy=multi-user.target
在哪裡/usr/local/etc/startCustomService定義為
more /usr/local/etc/startCustomService
#!/bin/sh
/usr/local/sbin/customService
正如我所說,該服務在 Ubuntu 14.04 下啟動並正確運行。另請注意該文件/usr/local/etc/startCustomService可以在 PIZero 上手動啟動。
有什麼建議麼?
問候,丹尼爾
答案1
嘗試新增工作目錄。
WorkingDirectory=/usr/local/etc/