Markino
Posts: 40
Joined: Fri Oct 03, 2014 11:53 am

/etc/rc.local not running at boot?

Mon Dec 29, 2014 10:11 am

/etc/rc.local is not run at startup...
Hi all,
I've just upgraded my Raspy to the last Raspbmc release (Kodi) but it seems that /etc/rc.local won't run at boot!
I've added some lines in order to export a gpio and it doesn't work:

echo 22 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio22/direction
chown root:gpio /sys/class/gpio/gpio22/value
chmod g+w /sys/class/gpio/gpio22/value


I've checked the execution bit and it's ok:

-rwxr-xr-x 1 root root 996 Dec 29 09:49 /etc/rc.local


Any idea?

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: /etc/rc.local not running at boot?

Mon Dec 29, 2014 10:40 am

Add a simple echo to /etc/rc.local to verify if it runs or not:
echo "running rc.local" > /tmp/rc_test.txt

Markino
Posts: 40
Joined: Fri Oct 03, 2014 11:53 am

Re: /etc/rc.local not running at boot?

Mon Dec 29, 2014 12:48 pm

Just tried and nothing has been written on /tmp...

Mark_T
Posts: 149
Joined: Sat Dec 27, 2014 10:54 am

Re: /etc/rc.local not running at boot?

Mon Dec 29, 2014 4:26 pm

You put these at the top of the file yes?

Markino
Posts: 40
Joined: Fri Oct 03, 2014 11:53 am

Re: /etc/rc.local not running at boot?

Tue Dec 30, 2014 5:01 pm

yes, just before "exit 0"

User avatar
B.Goode
Posts: 8536
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: /etc/rc.local not running at boot?

Tue Dec 30, 2014 6:43 pm

Markino wrote:yes, just before "exit 0"
That looks like the bottom, not the top...

Markino
Posts: 40
Joined: Fri Oct 03, 2014 11:53 am

Re: /etc/rc.local not running at boot?

Tue Dec 30, 2014 6:55 pm

Ok but on the default rc.local of the Raspbmc there's nothing:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

User avatar
ilguargua
Posts: 73
Joined: Thu Jun 19, 2014 8:14 pm
Location: Livorno - Italy

Re: /etc/rc.local not running at boot?

Tue Dec 30, 2014 7:52 pm

I don't have raspbmc so I can't check it, but rc.local should be linked as service to start in /etc/rc.d[2 3 4 5] dirs. Does your system has this links?


Cheers, Ale.

Markino
Posts: 40
Joined: Fri Oct 03, 2014 11:53 am

Re: /etc/rc.local not running at boot?

Tue Dec 30, 2014 8:02 pm

ilguargua wrote:I don't have raspbmc so I can't check it, but rc.local should be linked as service to start in /etc/rc.d[2 3 4 5] dirs. Does your system has this links?


Cheers, Ale.

Sorry but... how can I check it? :)

User avatar
ilguargua
Posts: 73
Joined: Thu Jun 19, 2014 8:14 pm
Location: Livorno - Italy

Re: /etc/rc.local not running at boot?

Wed Dec 31, 2014 11:17 am

I don't know how raspbmc works , but if you have access to a console type the follow :

Code: Select all

[email protected]guargua-desktop:~$ for i in 2 3 4 5; do ls -l /etc/rc$i.d/ | grep local; done
lrwxrwxrwx 1 root root  18 dic 23 20:27 S99rc.local -> ../init.d/rc.local
lrwxrwxrwx 1 root root  18 dic 23 20:27 S99rc.local -> ../init.d/rc.local
lrwxrwxrwx 1 root root  18 dic 23 20:27 S99rc.local -> ../init.d/rc.local
lrwxrwxrwx 1 root root  18 dic 23 20:27 S99rc.local -> ../init.d/rc.local

Cheers, Ale.

Markino
Posts: 40
Joined: Fri Oct 03, 2014 11:53 am

Re: /etc/rc.local not running at boot?

Wed Dec 31, 2014 12:57 pm

Thanks Ale for your help! I really appreciate!

Here there is my output:

[email protected]:~$ for i in 2 3 4 5; do ls -l /etc/rc$i.d/ | grep local; done
lrwxrwxrwx 1 root root 18 Dec 23 2013 S20rc.local -> ../init.d/rc.local
lrwxrwxrwx 1 root root 18 Dec 23 2013 S20rc.local -> ../init.d/rc.local
lrwxrwxrwx 1 root root 18 Dec 23 2013 S20rc.local -> ../init.d/rc.local
lrwxrwxrwx 1 root root 18 Dec 23 2013 S20rc.local -> ../init.d/rc.local


Can you explain me what that output means?

User avatar
ilguargua
Posts: 73
Joined: Thu Jun 19, 2014 8:14 pm
Location: Livorno - Italy

Re: /etc/rc.local not running at boot?

Thu Jan 01, 2015 11:33 am

Your system seems OK, so rc.local should be executed at boot. I'm sorry but I'm afraid I don't have a clue for you, do you already tried a sudo apt-get update && sudo apt-get upgrade ? Don't know what ever else suggest...


Cheers, Ale.

temp
Posts: 1
Joined: Wed Feb 25, 2015 6:24 am

Re: /etc/rc.local not running at boot?

Wed Feb 25, 2015 6:36 am

Perhaps those involved in this have already passed by the solution so this might be for anyone else who comes upon this, but according to what I'm seeing the file linked to the boot process is /etc/init.d/rc.local, not the original question with /etc/rc.local.

I have tried the "echo "running rc.local" > /tmp/rc_test.txt" command in the /etc/init.d/rc.local file and it did create the /tmp/rc_test.txt file.

--
Temp

User avatar
ilguargua
Posts: 73
Joined: Thu Jun 19, 2014 8:14 pm
Location: Livorno - Italy

Re: /etc/rc.local not running at boot?

Wed Feb 25, 2015 9:55 pm

If you check the content of /etc/init.d/rc.local you should see something like this :

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          rc.local
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Run /etc/rc.local if it exist
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
        if [ -x /etc/rc.local ]; then
                [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
                /etc/rc.local
                ES=$?
                [ "$VERBOSE" != no ] && log_end_msg $ES
                return $ES
        fi
}

case "$1" in
    start)
        do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac

As stated in the very first lines, the scope of this script is to run the /etc/rc.local file , so if the file exist and is executable should be launched at boot.

Cheers, Ale

arre
Posts: 3
Joined: Fri May 27, 2016 2:28 pm

Re: /etc/rc.local not running at boot?

Thu Oct 20, 2016 7:38 pm

I'm actually experiencing the same problem.
This is very bizar. Other services do run (I have for example smokeping running in runlevel 2), but rc.local refuses

A few tests I did:
- Manually running the service by either running the script; or service rc.local start works fine
- But at boot; the script is simply not executed. I checked this by adding a simple "echo test > /test.txt" line in /etc/init.d/rc.local
(A similar line in /etc/init.d/smokeping clearly shows that it is called)
- Changing order of execution seems to make no difference
- Removing and reinstalling with rc-updateconfig has no effect
- Using the same parameters as smokeping in the header has no effect
- ..

The most interesting stuff I found so far, was checking which application fails to call the script.
In the end, the chain is pretty long. Init (upstart) calls the legacy sysV script , which again call scripts etc

This command however brings the last steps to life:

Code: Select all

[email protected]:~$ ps aufww
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
pi        1256  2.0  0.4   3296  1832 pts/0    Ss   21:33   0:00 -bash
pi        1266  0.0  0.2   2892   964 pts/0    R+   21:33   0:00  \_ ps aufww
root      1153  0.0  0.2   2212   792 tty3     Ss+  21:32   0:00 /sbin/getty -8 38400 tty3
root      1152  0.0  0.2   2212   792 tty2     Ss+  21:32   0:00 /sbin/getty -8 38400 tty2
root      1018  0.0  0.1   2032   728 ?        Ss+  21:32   0:00 /sbin/getty -L ttyAMA0 115200 vt100
root       625  0.0  0.1   1724   572 tty1     Ss+  21:32   0:00 /bin/sh /etc/init.d/rc 2
root       648  0.5  0.4   1980  1852 tty1     SL+  21:32   0:00  \_ startpar -p 4 -t 20 -T 3 -M start -P N -R 2
And a bit later (after it has fully booted)

Code: Select all

[email protected]:~$ ps aufww
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
pi        1256  0.0  0.4   3296  1832 pts/0    Ss   21:33   0:00 -bash
pi        1646  0.0  0.2   2892   964 pts/0    R+   21:34   0:00  \_ ps aufww
root      1153  0.0  0.2   2212   792 tty3     Ss+  21:32   0:00 /sbin/getty -8 38400 tty3
root      1152  0.0  0.2   2212   792 tty2     Ss+  21:32   0:00 /sbin/getty -8 38400 tty2
root      1018  0.0  0.1   2032   728 ?        Ss+  21:32   0:00 /sbin/getty -L ttyAMA0 115200 vt100
root       625  0.0  0.1   1724   572 tty1     Ss+  21:32   0:00 /bin/sh /etc/init.d/rc 2
root       648  0.5  0.4   1980  1852 tty1     SL+  21:32   0:00  \_ startpar -p 4 -t 20 -T 3 -M start -P N -R 2
root      1605  0.0  0.1   1724   580 tty1     S    21:33   0:00      \_ /bin/sh /etc/init.d/smokeping start
root      1616  0.0  0.3   3024  1300 tty1     S    21:33   0:00          \_ /bin/bash /usr/sbin/smokeping --config=/etc/smokeping/config
root      1617  0.0  0.1   1816   476 tty1     S    21:33   0:00          \_ logger -p daemon.notice -t smokeping

As you can see, it is startpar (sys v thingie to parallize startup scripts) which I think is supposed to call the /etc/init.d/rc.local script; but for some reason does not do it.

I gave up at this point, and hacked smokeping to be a shellscript that first calls /etc/rc.local, and then starts smokeping. The output looks like this:

Code: Select all

[email protected]:~$ ps aufww
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
pi        1256  0.0  0.4   3296  1832 pts/0    Ss   21:33   0:00 -bash
pi        1646  0.0  0.2   2892   964 pts/0    R+   21:34   0:00  \_ ps aufww
root      1153  0.0  0.2   2212   792 tty3     Ss+  21:32   0:00 /sbin/getty -8 38400 tty3
root      1152  0.0  0.2   2212   792 tty2     Ss+  21:32   0:00 /sbin/getty -8 38400 tty2
root      1018  0.0  0.1   2032   728 ?        Ss+  21:32   0:00 /sbin/getty -L ttyAMA0 115200 vt100
root       625  0.0  0.1   1724   572 tty1     Ss+  21:32   0:00 /bin/sh /etc/init.d/rc 2
root       648  0.5  0.4   1980  1852 tty1     SL+  21:32   0:00  \_ startpar -p 4 -t 20 -T 3 -M start -P N -R 2
root      1605  0.0  0.1   1724   580 tty1     S    21:33   0:00      \_ /bin/sh /etc/init.d/smokeping start
root      1616  0.0  0.3   3024  1300 tty1     S    21:33   0:00          \_ /bin/bash /usr/sbin/smokeping --config=/etc/smokeping/config
root      1619  0.0  0.1   1724   512 tty1     S    21:33   0:00          |   \_ /bin/sh -e /etc/rc.local
root      1617  0.0  0.1   1816   476 tty1     S    21:33   0:00          \_ logger -p daemon.notice -t smokeping
This is an absurd workaround.. but I got tired and this is a toy device I wanted to do something with.

If anybody knows the missing link why startpar behaves the way it does, feel free to comment. But for now, I'll use my strange workaround:)

senten
Posts: 6
Joined: Thu Oct 13, 2016 8:40 pm

Re: /etc/rc.local not running at boot?

Tue Nov 08, 2016 6:42 pm

Also trying to solve this problem.... (thanks for the investigation @arre !)

/etc/rc.local is not running at boot. I included an echo to file line which doesn't get run.

kryptomatrix
Posts: 4
Joined: Sun Jul 17, 2016 12:12 pm

Re: /etc/rc.local not running at boot?

Thu Jan 05, 2017 1:06 am

For everyone who has a similar problem and found this post:

Code: Select all

chmod +x /etc/rc.local
might solve your Problem

NOOB7771
Posts: 1
Joined: Sun Jan 08, 2017 9:35 pm

Re: /etc/rc.local not running at boot?

Sun Jan 08, 2017 9:37 pm

Yes! this worked for me:
chmod +x /etc/rc.local

fdr4prez
Posts: 17
Joined: Fri May 13, 2016 8:06 pm

Re: /etc/rc.local not running at boot?

Wed Jan 18, 2017 1:57 am

On a side note, a colleague had a similar issue with rc.local during boot and found odd permission value for the file. He changed it to 755 and it starting working.

not that other settings wouldn't work, but that is the setting he used.

John Mc
Posts: 47
Joined: Wed Feb 22, 2017 1:22 am

Re: /etc/rc.local not running at boot?

Mon Mar 13, 2017 5:50 am

I added a line to rc.local which is executed properly if I type: /etc/rc.local (It emails the Pi's current IP address to an address I set up for this purpose).

However, it does not execute when I reboot the Pi.
I tried chmod +x /etc/rc.local but got the following:
chmod: changing permissions of ‘/etc/rc.local’: Operation not permitted

NOTE: the rc.local file does already show up in green when I list what's in the etc directory.

It seems to me that rc.local is not being run at all when rebooting.

Is it related to these comments in the top of the rc.local file:
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
I'm a Noob at this. How do I now make rc.local run at startup/reboot?

User avatar
CarlRJ
Posts: 599
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: /etc/rc.local not running at boot?

Mon Mar 13, 2017 10:18 am

John Mc wrote:I added a line to rc.local which is executed properly if I type: /etc/rc.local (It emails the Pi's current IP address to an address I set up for this purpose).

However, it does not execute when I reboot the Pi.
I tried chmod +x /etc/rc.local but got the following:
...
How do I now make rc.local run at startup/reboot?
9 times out of 10 in this situation, /etc/rc.local is, in fact, being run at startup, but your script or command is not accounting for differentces in the environment that is present at startup, compared to the environment when you run the script by hand (this often trips up people trying to run cron jobs as well). Things like PATH being set to a different value, or assumptions about what the current directory is, or what user is executing the command. You mention trying to send email. It's entirely possible that the network connection is not fully up yet at the point when your command or script is run by /etc/rc.local. You can verify that rc.local is getting run by adding a line like date >> /tmp/rc_local_did_run to it, and then rebooting and looking to see if that file got created and contains a reasonable value. To check the network state present at boot time, try adding /sbin/ifconfig > /tmp/network_at_boot to /etc/rc.local, and compare that output against what you see by running ifconfig from a command prompt. If the problem is, indeed, that the network is not yet available when your script runs, you'll need to take steps to pause your script until the network connection is established.

Someone may be along shortly to explain that the proper way to start things at boot time is by using systemd. That's probably the right course to follow, but I haven't done it yet.

John Mc
Posts: 47
Joined: Wed Feb 22, 2017 1:22 am

Re: /etc/rc.local not running at boot?

Mon Mar 13, 2017 9:42 pm

Here is the unedited rc.local script as it appears in a freshly installed version of Jessie:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

exit 0
If I type /etc/rc.local from the command line, the following is returned:
My IP address is 192.168.1.13

I never see that message at boot up. I assumed that it was because as the comments state: "In order to enable or disable this script just change the execution bits. By default this script does nothing."

I added the line you suggested /sbin/ifconfig > /tmp/network_at_boot to rc.local (I put it just above the comment line "# Print the IP address"). Saved it and rebooted. The wlan0 part of that file looked like this:
wlan0 Link encap:Ethernet HWaddr b8:27:eb:08:21:b7
inet6 addr: fe80::1c9d:cc9e:d15a:7ce/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
So it looks as though the Pi has not connected to the WiFi network at the time rc.local is run.

If there is a better way to do this (i.e. by using systemd), I'd love to learn about it. I have an application that does exactly what I want, and it runs fine if I type sudo python /home/pi/Startup_maily.py & I need to find a way to run it on bootup AFTER the Pi connects to the Wifi access point. Hopefully someone can help with an explanation or pointing me to a link. I'm way too new at this to do it myself

nimzoking
Posts: 1
Joined: Mon Mar 13, 2017 10:42 pm

Re: /etc/rc.local not running at boot?

Mon Mar 13, 2017 11:07 pm

I have an application that does exactly what I want, and it runs fine if I type sudo python /home/pi/Startup_maily.py & I need to find a way to run it on bootup AFTER the Pi connects to the Wifi access point
Have you tried putting a sleep command in place?

I have tried this on my setup with a 15 second delay, and the IP address is assigned to the WiFi within that time. You could play with the delay time, if you need a quicker reboot.

Code: Select all

# Print the IP address
# Sleep introduced to see if Wifi acquired and IP assigned
date >> /tmp/rc_local_b4_sleep
sleep 15
date >> /tmp/rc_local_after_sleep

_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

/sbin/ifconfig > /tmp/network_at_boot
After a reboot I have 3 files in /tmp - all with the data I expected.

John Mc
Posts: 47
Joined: Wed Feb 22, 2017 1:22 am

Re: /etc/rc.local not running at boot?

Tue Mar 14, 2017 3:25 am

BINGO! "sleep 15" fixed the problem. Thank you SO much.

User avatar
CarlRJ
Posts: 599
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: /etc/rc.local not running at boot?

Tue Mar 14, 2017 5:02 am

If you wanted to be a bit more robust (I'm always leery of solutions based on waiting a fixed number of seconds), short of going to systemd, you could put something like this ahead of your code in /etc/rc.local:

Code: Select all

while ! /sbin/ifconfig wlan0 | grep -q 'inet addr:[0-9]'; do
    sleep 3
done
Basically, look at ifconfig for the desired interface for "inet addr:" followed by a digit, if not found, sleep a very short time and try again. Of course, if you ever bring up the system necessarily without network access, it'll keep (rc.local stuff at least) from ever completing. The next step would be to add a counter as a sort of escape valve (check for IP and sleep 3 seconds, but if this fails 20 times, give up)... but that's getting dangerously close to the point where it's better to invest the time in learning systemd.

Return to “General discussion”