4

I'm trying to run a simple C code when the pi boots, so I followed the steps on the documentation (https://www.raspberrypi.org/documentation/linux/usage/rc-local.md), but when I start it, it shows this error:

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

I do as it says and I receive this:

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)

My rc.local file looks like this:

./home/pi/server-starter &

exit 0

Can anyone show me what I'm doing wrong?

Lucas Barbosa
  • 41
  • 1
  • 1
  • 3
  • 1
    Did you `systemctl enable rc-local.service`? What happens when you `systemctl start rc-local.service` when it's already running? (Does that change the output of `systemctl status rc-local.service`?) – Two-Bit Alchemist Dec 10 '15 at 21:01
  • Yes, and when I do it, it shows the message I've put here, after the 'I do as it says...' – Lucas Barbosa Dec 10 '15 at 22:56

2 Answers2

1

You have to refer to your script using an absolute path.

/home/pi/server-starter &

Notice the absence of the . in comparison to your solution.

Also, you may have to add a reference to the shell right at the beginning of your rc.local.

#!/bin/sh -e
/home/pi/server-starter &
exit 0
flo
  • 9,713
  • 6
  • 25
  • 41
  • I followed your suggestion, but it keeps showing the same error on Pi's startup. – Lucas Barbosa Dec 14 '15 at 21:26
  • Does executing `sh /home/pi/server-starter` work correctly? – flo Dec 15 '15 at 05:35
  • I executed it here and it showed the error `/home/pi/server-starter: 1: /home/pi/server-starter: Syntax error: word unexpected (expecting ")")` Here's my full code: `#include #include 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; }` – Lucas Barbosa Dec 15 '15 at 13:25
  • This is not a script that can be started using the shell (sh) but looks like a C(++).program which has to be compiled first. – flo Dec 15 '15 at 19:24
  • I know it's not a script, that's why I was trying to put the command inside the rc.local file with the "." . It's already compiled, and when I run `./home/pi/server-starter` on the command line, it works as it is supposed to. – Lucas Barbosa Dec 17 '15 at 17:29
  • `./home/pi/server-starter` should only work if you are in the root folder `/` with your shell. If you are somewhere else (probably your home directory `/home/pi`), you may have another/different `server-starter` file somewhere (e.g. `/home/pi/home/pi/server-starter`). – flo Dec 18 '15 at 09:38
1

to run a script shell "in a script shell" use this :

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

to run this script in background use this :

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

Don't forget exit 0 at the end of the file

youyoup
  • 559
  • 1
  • 6
  • 9