Power & Source of Big Ideas

NanoPi NEO rc.local does not get executed

Moderators: chensy, FATechsupport

Dear Sirs,

I have a nanoPi NEO running with image: nanopi-neo_ubuntu-core-xenial_3.4.39_20170819.img.zip, however, I cannot get the /etc/rc.local executed. I have tried many suggestions from the Internet, but none of them works. The rc.local works when I type it manually in the terminal, but not executed when booting up.

I have an evaluation board from Microchip, it works. Is there any thing wrong with my nonoPi NEO?

Here is my /etc/rc.local, please help! Thanks.

#
# By default this script does nothing.

/usr/local/bin/gen-friendlyelec-release
. /etc/friendlyelec-release
if [ ! -f /etc/firstuse ]; then
/bin/echo ${BOARD} > /etc/hostname
/bin/sed -i "s/\(127.0.1.1\s*\).*/\1${BOARD}/g" /etc/hosts
/bin/hostname ${BOARD}
/bin/echo "0" > /etc/firstuse
fi

. /usr/bin/setqt5env
/usr/bin/lcd2usb_print "CPU: {{CPU}}" "Mem: {{MEM}}" "IP: {{IP}}" "LoadAvg: {{L$
#/opt/QtE-Demo/run.sh&

echo "Hello from rc.local !!!!"

exit 0
First I would make sure that you can execute it as a stand-alone Bash script. That will possibly point to a file permissions problem.

How does the /etc/rc.local file get executed in the first time? Have a look in /etc/init.d
Is there a rc.local file in there?
Thank you Dave!
Yes, It can be executed alone if I type it manually in command line. For your question about /etc/init.d, yes, I have checked it and find a rc.local file as well. I copied its contents and pasted as follows:

#! /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|status)
# No-op
exit 0
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
I am confused about "typing it in the command line". I meant put all the text into a file, call it my_test_script.sh and run it like so:

sudo ./my_test_script.sh

from the same directory that you created it in. sudo chmod 755

The next thing I would try is:
sudo service rc.local start

It ran on my Xubuntu netbook without errors but I don't know if it actually did anything. So, I am not certain if that is the correct method.

Maybe, that helps.

Dave
Hang on a minute ... if you have a /etc/rc.local and you try to run another /etc/rc.local (placed in /etc/init.d/) when you boot up how does it know which one to run?

Or, did you name it something different and place it in /etc/init.d/
2 ideas:
shouldnt the first line read as
#!/bin/sh

but you have there
#! /bin/sh
(with a space)

Does you /etc/rc.local execute rights - like from chmod 755 /etc/rc.local

Is /bin/sh the right shell for the commands do you use?
maybe you could try
#!/bin/bash
When I type the following commands in terminal, it works. When I reboot the system, however, I did not see the same result as I typed manually.

cd /etc
./rc.local
The next things I would try:

- move your existing /etc/rc.local to your /home directory for safe-keeping
- put your new rc.local in /etc/
- and re-boot

I didn't pick up on the sh versus bash issue. All my scripts use bash, Google for the differences.

As far as I am aware all scripts in /etc/init.d/ get processed during boot but maybe there is some way to stop them.

Another thing that puzzles me why any messages using echo in the script are not displayed. Maybe saying:

Code: Select all

echo "this is an error message" > /dev/tty1

might display something and help you to debug it.
Seems

Code: Select all

sudo chmod -x /etc/rc.local

is the way to stop it executing.

Are you sure your new rc.local is 755?
Also going back to your 2nd post on the 5th Mar similar code is found in /etc/init.d/ on my Xubuntu machine. Which then goes and looks at /etc/rc.local for further information.

Exactly where are you placing your "rc.local" file?
Thanks all you guys' the help!

I tried to look into the other rc.local file in /etc/init.d directory instead of the file in /etc. I tried to execute it by typing ./rc.local command, then I got an "Usage: ./rc.local start", then I type ./rc.local start, I got a Warning message, please see the following message. Is the NanoPi NEO disabled the rc.local by its factory default settings somewhere? If yes, why?

root@NanoPi-NEO:/etc/init.d# ./rc.local
Usage: ./rc.local start|stop
root@NanoPi-NEO:/etc/init.d# ./rc.local start
Starting rc.local (via systemctl): rc.local.serviceWarning: rc.local.service changed on disk. Run 'systemctl daemon-reload' to reload units.
The rc.local file in /etc/init.d/ on a Debian installation looks 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|status)
        # No-op
        exit 0
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac


My understanding is to leave this as is and then modify the rc.local in /etc/ for your purposes. That warning is common with systemd when you make any changes. Because I change the network parameters several times a day I do a:

Code: Select all

systemctl daemon-reload

to eliminate warning messages, which seems to help keeping my system working properly.
OK, I won't change this file. Then let's head back to the /etc/rc.local file, my original problem is that it won't be executed while booting up the system. Do you have any comments? Thanks.
In /etc/init.d/rc.local
place the following:

Code: Select all

echo "/init.d/rc.local runs" >&2
echo "/init.d/rc.local runs" >/dev/tty1


In /etc/rc.local
place the following:

Code: Select all

echo "rc.local runs" >&2
echo "rc.local runs" >/dev/tty1


and see if any messages are printed on your terminal screen.
A really good place to get help for general Debian operating systems is at http://www.raspberrypi.org/forums/

I recall some discussion about rc.local there:
https://www.raspberrypi.org/forums/viewtopic.php?t=95101
looks relevant.
I have added in both rc.local files, and it did NOT display when I reboot the system either. Here is the file contents in /etc/rc.local file which I added the 2 lines you suggested.

root@NanoPi-NEO:/etc# cat rc.local
#!/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.

/usr/local/bin/gen-friendlyelec-release
. /etc/friendlyelec-release

echo "rc.local runs" >&2
echo "rc.local runs" >/dev/tty1

if [ ! -f /etc/firstuse ]; then
/bin/echo ${BOARD} > /etc/hostname
/bin/sed -i "s/\(127.0.1.1\s*\).*/\1${BOARD}/g" /etc/hosts
/bin/hostname ${BOARD}
/bin/echo "0" > /etc/firstuse
fi

. /usr/bin/setqt5env
/usr/bin/lcd2usb_print "CPU: {{CPU}}" "Mem: {{MEM}}" "IP: {{IP}}" "LoadAvg: {{LOADAVG}}" 2>&1 > /dev/null&
#/opt/QtE-Demo/run.sh&

exit 0
root@NanoPi-NEO:/etc# ./rc.local
rc.local runs
ctp = 0
root@NanoPi-NEO:/etc#
Either trying to echo stuff in init.d files is not done as per my suggestions or I wonder if any of the init.d scripts are running.

Next thing I would try is ...

Code: Select all

#!/bin/bash

echo "abc runs" > &2
echo "abc runs" > /dev/tty1


and call it abc and place this in /etc/init.d and give it 755 permissions. Also, check the owner, it should probably be root root

Before doing this try on the command line:

Code: Select all

echo "it works" > /dev/tty1


give it 755 and play with owner permissions until you see something.

Also, I am not sure about the &2 statement, which I copied from somewhere. I think there is supposed to be another character in it.
Thank you Dave! Here is the result after I ran each rc.local individually. Please note that tty1 does not display anything for my system. I have changed it to ttyS0 instead, the following result is based on ttyS0 which I changed. When I reboot the system, it showed one "rc.local runs" message. I have copied the screenshot for you at the bottom of this reply.

root@NanoPi-NEO:/etc# ./rc.local
rc.local runs
rc.local runs
ctp = 0
root@NanoPi-NEO:/etc# cd init.d
root@NanoPi-NEO:/etc/init.d# ./rc.local
/init.d/rc.local runs
/init.d/rc.local runs
Usage: ./rc.local start|stop
root@NanoPi-NEO:/etc/init.d#


************ The following screen shot is displayed after reboot *****************

[ 8.582043] systemd[1]: Reached target Remote File Systems.
[ 8.763322] systemd[1]: Mounted Debug File System.
[ 8.781740] systemd[1]: Started Journal Service.
rc.local runs

Ubuntu 16.04.2 LTS NanoPi-NEO ttyS0

NanoPi-NEO login: pi (automatic login)

Last login: Fri Mar 9 00:02:04 UTC 2018 on tty1
_____ _ _ _ _____ _ _____ ____
| ___| __(_) ___ _ __ __| | |_ _| ____| | | ____/ ___|
| |_ | '__| |/ _ \ '_ \ / _` | | | | | _| | | | _|| |
| _|| | | | __/ | | | (_| | | |_| | |___| |___| |__| |___
|_| |_| |_|\___|_| |_|\__,_|_|\__, |_____|_____|_____\____|
|___/

Welcome to Ubuntu 16.04.2 LTS 3.4.39-h3
System load: 0.66 Up time: 19 sec
Memory usage: 7 % of 494Mb IP:
CPU temp: 65°C
Usage of /: 10% of 15G

* Documentation: http://wiki.friendlyarm.com/
* Forum: http://www.friendlyarm.com/Forum/

pi@NanoPi-NEO:~$
Dave, when both command lines in /etc/rc.local were changed to the following, then it displayed "rc.local runs 2" after rebooted.

echo "rc.local runs 1" >&2
echo "rc.local runs 2" >/dev/ttyS0
So, we can conclude that /etc/rc.local gets at least partially executed, correct?

Wikipedia says:
Bourne-style shells allow standard error to be redirected to the same destination that standard output is directed to using

2>&1


Thought that >&2 was not what I wanted to get you to try.

So, now try:

Code: Select all

echo "success" 2>&1

and see it that displays something.

Now you can use:

Code: Select all

echo "got this far" > /dev/ttyS0

to debug your script.

I suspect that if you do something wrong in /etc/rc.local that it has no way to tell you what or where the problem is.
Yes, thank you Dave! The problem is solved! Thanks so much for your your effort and time! Have a great weekend!
stevearm wrote:
Yes, thank you Dave! The problem is solved! Thanks so much for your your effort and time! Have a great weekend!

could you also tell us - for the next one who is having this problem - what problem was in your /etc/rc.local? :)

Who is online

In total there are 7 users online :: 0 registered, 0 hidden and 7 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 7 guests