【问题标题】:rc.local is not running on raspberry pi's startuprc.local 未在树莓派启动时运行
【发布时间】:2016-03-16 15:13:06
【问题描述】:

我试图在 pi 启动时运行一个简单的 C 代码,所以我按照文档 (https://www.raspberrypi.org/documentation/linux/usage/rc-local.md) 上的步骤进行操作,但是当我启动它时,它显示此错误:

Failed to start etc/rc.local compatibility.
See 'systemctl status rc-local.service' for details.

我按照它说的去做,我收到了这个:

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 Tue 2015-12-08 10:44:23 UTC; 2min 18s ago
Process: 451 ExecStart=/etc/rc.local start (code=exit, status=203/EXEC)

我的 rc.local 文件如下所示:

./home/pi/server-starter &

exit 0

谁能告诉我我做错了什么?

【问题讨论】:

  • systemctl enable rc-local.service了吗?当你systemctl start rc-local.service 已经运行时会发生什么? (这会改变systemctl status rc-local.service 的输出吗?)
  • 是的,当我这样做时,它会显示我在这里输入的信息,在“我按照它说的做......”之后。

标签: c linux raspbian raspberry-pi2


【解决方案1】:

要“在脚本外壳”中运行脚本外壳,请使用:

sh -c /absolute/path/to/script;

要在后台运行此脚本,请使用:

sh -c /absolute/path/to/script &;

不要忘记文件末尾的exit 0

【讨论】:

    【解决方案2】:

    您必须使用绝对路径引用您的脚本。

    /home/pi/server-starter &
    

    请注意与您的解决方案相比,. 的缺失。

    此外,您可能必须在 rc.local 的开头添加对 shell 的引用。

    #!/bin/sh -e
    /home/pi/server-starter &
    exit 0
    

    【讨论】:

    • 我听从了你的建议,但它在 Pi 启动时一直显示相同的错误。
    • 执行sh /home/pi/server-starter 是否正常工作?
    • 我在这里执行它并显示错误/home/pi/server-starter: 1: /home/pi/server-starter: Syntax error: word unexpected (expecting ")")这是我的完整代码:#include <stdio.h> #include <unistd.h> int main(int argc, char **argv){ const char *fname = "farm-info"; if (access(fname, F_OK) != -1){ return 1; }else{ system("node /home/pi/app.js"); } return 0; }
    • 这不是一个可以使用 shell (sh) 启动的脚本,但看起来像一个必须先编译的 C(++).program。
    • 我知道它不是脚本,这就是为什么我试图将命令放在带有“。”的 rc.local 文件中。 .它已经编译好了,当我在命令行上运行./home/pi/server-starter 时,它可以正常工作。
    猜你喜欢
    • 2017-04-22
    • 1970-01-01
    • 2022-12-05
    • 1970-01-01
    • 2017-02-27
    • 2022-11-27
    • 1970-01-01
    • 2015-05-11
    • 2023-01-08
    相关资源
    最近更新 更多