United States (change)
Shortcuts: Downloads Fedora Red Hat Network
Account Links: Cart Your Account Logout
All System V init scripts are named /etc/rc.d/init.d/servicename where servicename is the name of the service. Below is a sample init script.
Please note that one convention of init scripts for Red Hat Enterprise Linux, that may be different on other distributions, is the necessity of touching and removing the lock file, as highlighted in bold in the example below. If these two lines are not present, your script may not execute as expected in all run levels.
#!/bin/bash
#
# chkconfig: 35 90 12
# description: My server
#
#Source function library.
. /etc/init.d/functions
start() {
initlog -c "echo -n Starting my server: "
/path/to/servicename &
### touch the lock file ###
touch /var/lock/subsys/servicename
success $"My server startup"
echo
}
stop() {
initlog -c "echo -n Stopping my server: "
killproc servicename
### Remove the lock file ###
rm -f /var/lock/subsys/servicename
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status servicename
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
Line #3 above allows the service to be controlled by chkconfig, which controls starting and stopping the service when rebooting or switching runlevels. For more information on the syntax of this line, see man chkconfig.