2012-09-14

Ubuntu upstart and init.d - the pain

I've started using start/stop/restart from the new and improved upstart package on Ubuntu (as I got tired of the warnings when using the old /etc/init.d/ way).

I like it, but it is a major pain in the back to remember what service is converted to upstart and not, and this were starting to give me quite an irritation. During a coffee break, I uttered that these upstart commands should check if there were an init.d script if the service were missing from /etc/init, and that got me thinking. It would be trivial to write an patch, but I guess the reason this feature is missing, already is discussed in the upstart community, and probably never would be accepted.

My solution is to use functions in bash and wrap around these commands.

I made a master function _start()



function _start() {
  if [ -f /etc/init/$1.conf ]; then
    /sbin/$2 $1
  elif [ -x /etc/init.d/$1 ]; then
    /etc/init.d/$1 $2
  else
    echo "$2: Unkown job: $1"
    return 1
  fi;
}

This master is used by the three small wrapper functions start(), stop() and restart():



function start() {
  _start $1 start;
}

function stop() {
  _start $1 stop;
}

function restart() {
  _start $1 restart;
}

I've put all four functions into /etc/profile.d/upstart.sh and now I don't have to remember which service is using what. To reduce the need of cut and paste, you can download upstart.sh directly.

No comments:

Post a Comment