rc.local 未在启动时启动

rc.local 未在启动时启动
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
             /etc/systemd/system/rc-local.service.d
             └─ttyoutput.conf
     Active: failed (Result: exit-code) since Thu 2023-02-09 22:15:36 PST; 13min ago
       Docs: man:systemd-rc-local-generator(8)
    Process: 513 ExecStart=/etc/rc.local start (code=exited, status=203/EXEC)
        CPU: 9ms

Feb 09 22:15:36 raspberrypi systemd[1]: Starting /etc/rc.local Compatibility...
Feb 09 22:15:36 raspberrypi systemd[513]: rc-local.service: Failed to execute /etc/rc.local: Exec format error
Feb 09 22:15:36 raspberrypi systemd[513]: rc-local.service: Failed at step EXEC spawning /etc/rc.local: Exec format>
Feb 09 22:15:36 raspberrypi systemd[1]: rc-local.service: Control process exited, code=exited, status=203/EXEC
Feb 09 22:15:36 raspberrypi systemd[1]: rc-local.service: Failed with result 'exit-code'.
Feb 09 22:15:36 raspberrypi systemd[1]: Failed to start /etc/rc.local Compatibility.

~~~~~~

这是 rc.local 文件

python3 /home/sheepify/Desktop/main.py &
exit 0

我在 pi 4 model b 8gb RAM 上使用树莓派操作系统

答案1

确保它位于 /etc/rc.local 的顶部

#!/bin/sh -e

确保 /etc/rc.local 末尾有此内容

exit 0

答案2

rc-local.service: Failed to execute /etc/rc.local: Exec format error

由于没有 shebang 行(#!在 的开头/etc/rc.local),看起来内核已尝试将其作为二进制可执行文件运行,但这显然效果不佳。

与 shell 不同,systemd它不会自动检测没有 shebang 行的脚本:它只是对服务定义行exec()上的任何内容运行系统调用。ExecStart=

如果您绝对想使用rc.local,请将其更改为:

#!/bin/sh -e
python3 /home/sheepify/Desktop/main.py &
exit 0

并确保它被标记为可执行文件 ( sudo chmod a+x /etc/rc.local)。

相关内容