Recipe 16-1: init Scripts

System startup scripts are often called init scripts because they are normally started up by the init daemon from the /etc/init.d directory. This recipe provides a basic structure for such an init script. The process is started in the background and runs forever as a daemon, and the same process is killed to stop the daemon. This is not applicable to all applications; for example, it may be that $INSTDIR/$APP starts up another three processes and exits immediately. The Apache web server’s apachectl command is a typical example of this. In that case, more detailed understanding of the application is required. How can those subprocesses be monitored, and stopped when required? For daemon type systems, however, this recipe should be a useful starting point.

note.ai

Background processes are often called demons or daemons.

Technologies Used

  • init
  • chkconfig
  • case

Concepts

Recently some operating systems, notably Ubuntu and Solaris, began doing away with traditional init scripts in favor of more easily parallelized systems, using Upstart and SMF, respectively. Another flavor of Unix, BSD, has also always used a slightly different variant on the init scripts, and Slackware, too, uses a more BSD-like style, although Slackware also now supports the SysV initscripts style favored by most current Linux distributions.

The init script is responsible for starting and stopping, ...

Get Shell Scripting: Expert Recipes for Linux, Bash, and More now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.