2

I have a service I start/stop on boot/shutdown which I'm using to help me keep track of what I'm doing while experimenting with distributions on my RPi and swapping SD cards all the time.

The problem is that I put this on my new xbian image and I only get shutdown notifications.

Everything works fine on my main Raspbian which I've customized a lot. What I'm thinking is that the base xbian doesn't do very much yet, and my Raspbian has a lot of things running now after customization like samba, so the service starts much later on my fully developed raspbian than on xbian.

So what is the correct way to ensure this script runs only once the network connection is fully up?

Here is my script:

#! /bin/sh
# /etc/init.d/boot-notify
#

### BEGIN INIT INFO
# Provides:          boot-notify
# Required-Start:    $remote_fs $syslog $network $all
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

# Some things that run always
OS=$(uname -nr)

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script boot-notify "
    curl -s -k \
      -F "token=token" \
      -F "user=token" \
      -F "message=Raspberry Pi ($OS) boot-notify starting" \
      https://api.pushover.net/1/messages
    ;;
  stop)
    echo "Stopping script boot-notify "
    curl -s -k \
      -F "token=token" \
      -F "user=token" \
      -F "message=Raspberry Pi ($OS) boot-notify stopping" \
      https://api.pushover.net/1/messages
    ;;
  *)
    echo "Usage: /etc/init.d/boot-notify {start|stop}"
    exit 1
    ;;
esac

exit 0

I seemed to be unable to capture the curl errors (removing -s and adding -v and >> to a log file and trying the -o option), but I added the following arguments to the startup and I'm getting boot notifications now:

  --retry 10 \
  --retry-delay 5 \
  --retry-max-time 60 \
  • Required-start: network? – Alex Chamberlain Aug 19 '12 at 17:28
  • @AlexChamberlain Didn't help. – Cade Roux Aug 19 '12 at 17:43
  • Have you installed the script using update-rc.d or insserv? – Alex Chamberlain Aug 22 '12 at 7:22
  • @AlexChamberlain I used update-rc.d and it's sending on shutdown, just not startup. I think it's probably because curl can't find the http endpoint because the network is not fully up, but I have to put some logging in to see. – Cade Roux Aug 22 '12 at 14:39
  • @AlexChamberlain I had trouble capturing curl's behavior during startup, but I added some retries and delays and I'm getting the boot notifications now. I didn't think it needed much, after all it worked on Raspbian and even on my Tomato router, I do a similar thing on network up and it never seemed that sensitive. – Cade Roux Aug 23 '12 at 3:54
2

If you symlink your script into the runlevel directories then you can control the order. I'm not sure what kernel xbian runs on but the runlevel directory is usually something like:

/etc/rc[1-9].d/

In this case I'll assume you're using runlevel 5, so you want to symlink your script to:

/etc/rc5.d/

The naming convention in this folder controls the order in which scripts will run and what they do.

The first character tells you if the script kills or starts a process (K or S). I'm pretty sure the order of execution is determined alphabetically, so you can control it easily for using the next two characters.

For example:

S01syslog 

Would start before:

S05network

I hope that helps somewhat. If I find anything else out about xbian I'll let you know.

  • I may have misunderstood runlevels, but they don't run one after another. The system runs one runlevel. – Alex Chamberlain Aug 22 '12 at 7:13
  • @AlexChamberlain Yes, I knew it was something to do with the rc folders but I didn't remember correctly. I have looked it up and will edit my answer. – Jivings Aug 22 '12 at 16:56
  • @Jivings This is what update-rc does. My script is symlinked to S18 in runlevels 2, 3, 4, 5 (which is actually higher than it is in plain Raspbian - it's just at S05), but I believe those SNN orders are just calculated dynamically to take account of the dependency tree. – Cade Roux Aug 23 '12 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.