How to write Linux init scripts based on LSB init standard?

How to write Linux init scripts based on LSB init standard?

LSB-compliant init scripts need to: Optionally, they can use init.d functions like “log_success_msg”, “log_failure_msg” etc.. to log the messages. LSB provides default set of functions which is in /lib/lsb/init-functions. We can make use of those functions in our Init scripts.

How to write init scripts to automatically start any?

Anatomy of an init script. The init scripts reside in the /etc/init.d directory which in fact is a soft link to the /etc/rc.d/init.d directory. An init script is a shell script that has some metadata information which is meant to be used by sysvinit followed by the code to manage a service/task/process. As you will see in the sample init script

Where does the init script log the PID?

All the Init process by default will log the pid of the process in a file under /var/run/ directory. This is useful for the Init scripts to find the status of the process. Now let’s start writing a Init script.

Where do I find the init script in sysvinit?

The init scripts reside in the /etc/init.d directory which in fact is a soft link to the /etc/rc.d/init.d directory. An init script is a shell script that has some metadata information which is meant to be used by sysvinit followed by the code to manage a service/task/process.

Where does insserv enable an installed system init.d?

This defaults to /etc/init.d/ in compliance with the LSB specification. In this case insserv does not add or remove a script to the runlevels declared in the script headers, but may re-order the runlevels if the order of the currently enabled scripts has changed (see option -d ).

How to recognize upstart jobs in insserv script?

To allow upstart jobs to work as init.d scripts, insserv will recognize a symlink from path/to/init.d/script to /lib/init/upstart-job as upstart jobs, and instead of reading the header from the file will run the script with the argument lsb-header to get the script header.