Making your scrips chkconfig aware

If you want to have your scripts run at startup and shutdown, there is a specific way of doing it using chkconfig (or /sbin/chkconfig).

The first thing to do is to get to know about runlevels. Run levels informally define the state to which your system is booting up to. Runlevel 5 in Fedora/RedHat/CentOS is the default and means Multi-user with X. Runlevel 1 typically means single user mode, Runlevel 3 is Multi-user mode without X. There are 7 runlevels, 0 through 6. The file /etc/inittab tells you the run level that your system boots up to by default.

Firstly you need to know the runlevels in which you need to run your startup scripts. Typically you’d be running your scripts in runlevel 3,4,5.

The first thing you need to add to your script is the comment

#chkconfig 345 98 02
#description: This is what my script does.

–The first set of numbers after chkconfig are the runlevels you want your script to run at startup.
–The second number is the priority of the script at start time i.e. 98 in this case. It means that your script will run after all scripts with priority less than 98 have already run.
–The third number is the priority of the script at shutdown i.e. 02 in this case.

When you add your script using the command chkconfig –add , 7 symlinks are created. Firstly the symlinks prefixed with S are placed in /etc/rc.d where runlevel are the levels you specified that your script should run at startup. Then in the remaining /etc/rc.d, symlinks prefixed with K are created.

Leave a comment