I bought a Raspberry Pi 3 a couple of weeks ago and have been playing with it for a long while. I'm running Raspbian Lite headless and one thing I want to do is run some stuff on boot. Nothing exciting, just a few commands, but I am finding that very difficult to do. I will be using a simplified example of my script, but this is what I've worked it down to and this is what I can't make work. Here's what I've done so far:
Created a file, /etc/init.d/sanity
#!/bin/sh
# /etc/init.d/sanity
# If you want a command to always run, put it here
echo "sanity script is running"
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "START START START"
echo "START START START" > /root/START.txt
;;
stop)
echo "STOP STOP STOP"
echo "STOP STOP STOP" > /root/STOP.txt
;;
*)
echo "Usage: /etc/init.d/sanity {start|stop}"
echo "FAIL FAIL FAIL" > /root/FAIL.txt
exit 1
;;
esac
exit 0
Then modified the permissions with:
chmod 755 /etc/init.d/sanity
Which seems to work:
root@raspberrypi:/etc/init.d|⇒ ll
total 304
...blah blah blah...
-rwxr-xr-x 1 root root 493 Aug 13 23:09 sanity
...blah blah blah...
And, manually run, that seems to work:
root@raspberrypi:/etc/init.d|⇒ sh sanity start
sanity script is running
START START START
root@raspberrypi:/etc/init.d|⇒ sh sanity stop
sanity script is running
STOP STOP STOP
root@raspberrypi:/etc/init.d|⇒ sh sanity
sanity script is running
Usage: /etc/init.d/sanity {start|stop}
root@raspberrypi:/etc/init.d|⇒ cat /root/STOP.txt
STOP STOP STOP
root@raspberrypi:/etc/init.d|⇒ cat /root/START.txt
START START START
root@raspberrypi:/etc/init.d|⇒ cat /root/FAIL.txt
FAIL FAIL FAIL
Looks good. Now, I set it to run on boot, then try to start it like a service... but nothing happens.
root@raspberrypi:/etc/init.d|⇒ update-rc.d sanity defaults
insserv: warning: script 'K01sanity' missing LSB tags and overrides
insserv: warning: script 'sanity' missing LSB tags and overrides
root@raspberrypi:/etc/init.d|⇒ service sanity start
root@raspberrypi:/etc/init.d|⇒ ls /root
configurations
root@raspberrypi:/etc/init.d|⇒
So, what am I doing wrong here? Is there something special about Raspberry Pis that I'm missing? I know for sure that I've done this before with Ubuntu and Debian and I've never had this much trouble. It's driving me nuts.