Search code examples
bashservicedaemoninit.dupstart

Considerations for building SysV or Upstart compatible Bash scripts


I've just knocked out a quick script for keeping a slave web server in sync with a master using rsync. (https://github.com/simonjgreen/liveFolderSync/blob/master/liveFolderSync.sh)

I'd like to make this run on boot and be controllable via the usual /etc/init.d/... or service commands, however this is an area I've always fallen down in. I find both init.d scripts and upstart scripts horrendously confusing, and can't find a guide anywhere for starting from scratch.

The only control I'd like to have over it is start/stop/restart. Obviously later I will move the config into a separate file in /etc but that's already on the cards so outside the scope of this question.

Any pointers/advise and best practices would be helpful. I should add that I'm doing this on Ubuntu.


Solution

  • To get started with Sys V init scripts, I suggest the following links:

    1. Linux: How to write a System V init script to start, stop, and restart my own application or service
    2. Writing System V init scripts for Red Hat Linux
    3. Ubuntu Bootup Howto

    For instructions specific to Upstart, I would recommend starting with:

    At present, there are also 129 questions on AskUbuntu, several of which will point you in the right direction: