Monday, December 23, 2013

Adding new service to chkconfig

Adding new script to managed by chkconfig

We had a request to put a job to start at run level 3 but when we copied the script to the /etc/init.d directory ( which is a link from /etc/rc.d/init.d/ ) but chkconfig did not recognize.
# chkconfig --add  mlabpadm  # returned
Service does not support chkconfig
The script looks,
[root@hostlnx init.d]# more mlabpadm
#!/bin/sh
case $1 in
   "start") /opt/matlab/etc/lmstart 2>/dev/null;;
   "stop") /opt/matlab/etc/lmdown 2>/dev/null;;
esac

To add this script to run automatically to run level 3, I can create S script on rc3.d but it should be managed by chkconfig.
To make it work, we have to supply the chkconfig values, like what run level you want to display and what priority you want to start/shutdown.

[root@hostlnx init.d]# more mlabpadm
#!/bin/sh
# chkconfig: 345 98 15
# description: This script will stop and starts the metlab
# processname: It starts the lm process
case $1 in
   "start") /opt/matlab/etc/lmstart 2>/dev/null;;
   "stop") /opt/matlab/etc/lmdown 2>/dev/null;;
esac



# chkconfig --list | grep mlabpadm
mlabpadm 0:off 1:off 2:off 3:off 4:off 5:off 6:off

# chkconfig --list mlabpadm
mlabpadm        0:off   1:off   2:off   3:on    4:on    5:on    6:off


To remove a service from chkconfig management
# chkconfig --del servicename


Source: http://linux.about.com/library/cmd/blcmdl8_chkconfig.htm
RUNLEVEL FILES
 Each service which should be manageable by chkconfig needs two or more commented lines added to its init.d script. The first line tells chkconfig what runlevels the service should be started in by default, as well as the start and stop priority levels. If the service should not, by default, be started in any runlevels, a - should be used in place of the runlevels list. The second line contains a description for the service, and may be extended across multiple lines with backslash continuation.

For example, random.init has these three lines:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
#              higher quality random number generation.
 This says that the random script should be started in levels 2, 3, 4, and 5, that its start priority should be 20, and that its stop priority should be 80. You should be able to figure out what the description says; the \ causes the line to be continued. The extra space in front of the line is ignored.

http://serverfault.com/questions/384556/whats-the-difference-between-chkconfig-on-vs-chkconfig-add

No comments:

Post a Comment