1

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.

2 Answers 2

1

( Sorry @Gogeta70 )

I did actually end up using systemd. Here's an example of a dropbox service I got working that depends on two things:

[Unit]

Description=Dropbox as a system service
After=local-fs.target network.target

[Service]
User=me
Restart=always
ExecStart=/opt/dropbox/dropboxd
Restart=on-failure
RestartSec=1

[Install]
WantedBy=default.target

I named the file dropbox.service and put it in /etc/systemd/system/

-1

Use systemd for service management.

2
  • Okay, you didn't really answer my question but after a lot of reading I eventually accomplished what I wanted. One thing I was completely unable to do was make a service unit dependent on two path units. Can you point me to any doc that deals specifically with path units and/or unit dependencies?
    – cgm123
    Commented Aug 14, 2016 at 16:37
  • @cgm123 I know it has been two years, but it would be nice for you to post the solution you found as an answer to your own question. I'm now running into the same problems you were...
    – Gogeta70
    Commented Sep 12, 2018 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .