Search code examples
raspberry-piautostart

Raspberry Pi Script does not start after boot


I have problems starting my simple raspberry pi script automatically after reboot. I did the following steps:

cd /etc/init.d 

sudo nano myStartScript2.sh

sudo chmod +x /etc/init.d/myStartScript2.sh

sudo chmod 755 /etc/init.d/myStartScript2.sh

sudo update-rc.d myStartScript2.sh defaults

script looks like this:

#!/bin/sh
### BEGIN INIT INFO
# Provides:         myStartScreen2
# Required-Start:
# Required-Stop:
# Should-Start:      
# Default-Start:     S
# Default-Stop:
# Short-Description: Show custom splashscreen
# Description:       Show custom splashscreen
### END INIT INFO
echo "this is called at boot"
sleep 5
cd /home/pi/Desktop/mjpg-streamer-experimental
 export LD_LIBRARY_PATH=.
./mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so -x 1020 -y 550 -fps 20 -hf -vf -ex night"

If I look in the folder /etc/rcS.d , I can find myStartScript2.sh. But it is not getting executed after reboot. What am I missing?


Solution

  • As it stands, your script only runs in single-user mode, but I assume you want it to run in normal, i.e. multi-user mode? If so, first of all run:

    sudo update-rc.d myStartScript2.sh remove
    

    to get rid of the redundant link in /etc/rcS.d. Then change your line:

    # Default-Start:     S
    

    to

    # Default-Start:     5
    

    Run

    sudo update-rc.d myStartScript2.sh defaults
    

    It should have created a link in /etc/rc5.d. Try re-booting.