Saturday, December 21, 2024
HomeSolarisSolaris system administrationUnderstanding Solaris Runtime Control Scripts

Understanding Solaris Runtime Control Scripts

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. Hence, 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. 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 tech-recipe Create a basic Solaris runtime control script

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!