Understanding Solaris runtime control scripts

Contributor Icon Contributed by qmchenry Date Icon October 3, 2003  
Tag Icon Tagged: Solaris system administration

Runtime control scripts are responsible for starting and stopping services when the system changes run levels such as during boot and shutdown. These scripts reside in the rc#.d directories where the # sign is replaced by the run level, such as rc2.d, rc3.d, and rc0.d.


Well written runtime control scripts should accept at least start and stop as runtime parameters and may optionally accept additional parameters such as restart and status. When a runtime control script runs with a start parameter, it starts the processes for which it is responsible. Likewise, the stop parameter causes the script to terminate those processes.

Inside the runtime control directories are a numer of runtime control scripts starting with uppercase K or S followed by two numbers. As the system changes its run level, scripts in the corresponding directory are run in sorted order so a script starting with K00 will run before K99 which will run before S00. A script starting with the letter K is a kill script and will be run with a stop parameter and S scripts will be run with a start parameter. In this manner, the same script can be used to start and stop processes.

It is common to place a generic script, newservice for example, in /etc/init.d and then create logical links to that script in the appropriate rc#.d directory preceeded with a suitable combination of K or S and number. For example, to create an early kill script in rc0.d for an rc script newservice located in /etc/init.d, run as superuser:

cd /etc/rc0.d
ln -s ../init.d/newservice K05newservice

When you shutdown or restart the system you change its run level to 6 or 5, respectively. There are no /etc/rc5.d or /etc/rc6.d directories. Since changing to run level 0 (openboot prompt) involves the same procedure as shutting down or restarting, run levels 5 and 6 share the /etc/rc0.d directory. It is important to include kill scripts for services such as databases that could be corrupted if they were not properly shut down .

For an example of a runtime control script, see the recipe Create a basic Solaris runtime control script

Previous recipe | Next recipe |
 
  • Anonymous
    "to create an early kill script in rc0.d"
    "cd /etc/rc2.d"
    can it be that those statements do not go together ???
  • qmchenry
    You are exactly right. Great catch. Thanks for pointing out the error. I've fixed it in the recipe.
blog comments powered by Disqus