Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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