Thursday, October 22, 2009

Running your script at system startup on linux

Hi,

If you want to run your script at system startup e.g if you want to start jboss on system startup and stop on system shut down then create script and put it in "/etc/init.d" directory.

If you are using Debian then use 'update-rc.d' utility to install and remove System-V style init script links. Other distributions (such as Red Hat) use 'chkconfig'. You can see these utilities the you can locate files and check them.

If name of the script is say jboss then use following command

update-rc.d jboss defaults

If defaults is used, update-rc.d will make links to start the service in runlevels 2345, and stop the service in runlevels 016.

To start the script jboss in runlevels 0123 and stop in 456, run (as root):

update-rc.d jboss start 0123 stop 456

Read more: http://wiki.linuxquestions.org/wiki/Update-rc.d#ixzz0UjiBfsGM


For other distribution like red hat you can use chkconfig

Following tag needs to be added to your script so that it can be added to chkconfig
#!/bin/sh
#
# chkconfig: 2345 90 60

then you can add script by using command

chkconfig --add jboss

you can see all scripts configured by command

chkconfig --list

Regards,
Anand

No comments: