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.


You can copy one of the existing files under /etc/init.d/ folder and customize it to start your script instead. These files usually do the following:

1- Check the existence of some config files and binaries.

2- Include some init functions.

3- Check the "action" parameter: start, stop, restart and execute the appropriate action using a case structure.

4- The comments at the beginning of these startup files are important as they describe how they are started and the needed run levels.

To make it run at system startup, you can use update-rc.d utility.

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.