我正在尝试使用rc.local文件在启动时在我的Raspberry Pi上执行python温度监控脚本,但是经过多次尝试后我无法让它工作。目前我的rc.local看起来像这样:
pi@raspberrypi:~ $ systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static)
Drop-In: /etc/systemd/system/rc-local.service.d
└─ttyoutput.conf
Active: failed (Result: exit-code) since Mon 2017-03-27 12:03:53 CEST; 44s ago
Process: 565 ExecStart=/etc/rc.local start (code=exited, status=203/EXEC)
Warning: Unit file changed on disk, 'systemctl daemon-reload' recommended.
正如您所看到的,我已将其设置为将python输出记录到文件中,但是在启动期间根本不会创建该文件。
检查rc本地服务的状态我得到了这个输出:
pi@raspberrypi:~ $ ls -l /etc/rc.local
-rwxr-xr-x 1 root root 549 Mar 27 12:03 /etc/rc.local
我已将rc.local文件设置为可执行文件,权限看起来不错:
pi@raspberrypi:~ $ sh /etc/rc.local
/etc/rc.local: 1: /etc/rc.local: #!/bin/sh: not found
My IP address is 192.168.5.36
/etc/rc.local: 21: /etc/rc.local: cannot create /var/log/rc.local.log: Permission denied
pi@raspberrypi:~ $ sudo /etc/rc.local
/etc/rc.local: 1: /etc/rc.local: #!/bin/sh: not found
My IP address is 192.168.5.36
当我尝试从终端以root身份运行rc.local时,它会正确执行并创建日志文件(即使它在打开时为空):
pi@raspberrypi:~ $ sudo /etc/init.d/rc.local start
[....] Starting rc.local (via systemctl): rc.local.serviceWarning: Unit file of rc.local.service changed on disk, 'systemctl daemon-reload' recommended.
Job for rc-local.service failed. See 'systemctl status rc-local.service' and 'journalctl -xn' for details.
failed!
此外,这是输出(我在研究问题时已经看过这个命令,但我不确定它是做什么的):
Mar 27 13:48:54 raspberrypi systemd[1]: Starting /etc/rc.local Compatibility...
Mar 27 13:48:54 raspberrypi systemd[1]: Starting Network is Online.
Mar 27 13:48:54 raspberrypi systemd[1]: Reached target Network is Online.
Mar 27 13:48:54 raspberrypi systemd[1]: Starting LSB: Start NTP daemon...
Mar 27 13:48:54 raspberrypi systemd[568]: Failed at step EXEC spawning /etc/rc.local: Exec format error
Mar 27 13:48:54 raspberrypi systemd[1]: Started System Logging Service.
Mar 27 13:48:54 raspberrypi systemd[1]: rc-local.service: control process exited, code=exited status=203
Mar 27 13:48:54 raspberrypi systemd[1]: Failed to start /etc/rc.local Compatibility.
Mar 27 13:48:54 raspberrypi systemd[1]: Unit rc-local.service entered failed state.
非常感谢任何帮助!
编辑:
这是来自syslog文件的启动序列中rc.local似乎失败的部分:
{{1}}