Writing a custom init script
It's been a long time since I did a source tar-ball install. But the production servers at work require that applications that are not part of the standard install base (from Kickstart/Jumpstart and VMWare images) should be compiled from source. It was a very refreshing experience. :)
So after going through the usual
In a nutshell, the steps are:
Below is a script I wrote for Apache:
References:
So after going through the usual
configure; make; make install invocation, it was time to make sure that the app is persistent at boot. I would have copied an init script from my *nix desktop, but good thing SLES had a baseline script in /etc/init.d/skeleton. In a nutshell, the steps are:
- Define the
INIT INFOsection, as per the LSB specs. - Fill in the variables.
- Use /etc/rc.status and rc_* functions for sanity checks.
- Create the basic
start,stopandstatusfunctions. - Use YAST (System > System Services (Runlevel)) -- or, if available,
innserv-- to enable the startup script.
Below is a script I wrote for Apache:
#!/bin/sh
#
# Author: Ian Dexter R. Marquez
#
# /etc/init.d/httpd
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start the Apache httpd daemon
### END INIT INFO
HTTPD=/path/to/apache/2.2.4/bin/httpd
APACHECTL=/path/to/apache/2.2.4/bin/apachectl
PROG=httpd
test -x $HTTPD || exit 5
test -s /etc/rc.status && . /etc/rc.status && rc_reset
start() {
echo -n "Starting $PROG: "
$HTTPD -k start
rc_status -v
}
stop() {
echo -n "Stopping $PROG: "
/sbin/killproc $HTTPD
rc_status -v
}
status() {
echo -n "Checking $PROG: pid "
/sbin/pidofproc $HTTPD
rc_status -v
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
rc_status
;;
status)
status
;;
try-restart|condrestart)
if test "$1" = "condrestart"; then
echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
fi
$0 status
if test $? = 0; then
$0 restart
else
rc_reset # Not running is not a failure.
fi
# Remember status and be quiet
rc_status
;;
graceful|help|configtest|fullstatus)
$APACHECTL $@
rc_status
;;
*)
echo "Usage: $PROG {start|stop|restart|status|graceful|help|configtest|fullstatus}"
exit 1
esac
rc_exit
References:
- Writing Init Scripts, Novell Developer Net.
- Creating Custom Init Scripts, Novell Cool Solutions.
Hi, can you help me creating my own script?
ReplyDeleteContcact me by MSN, pĺease, i need to explain my needs:
Live ID: [email protected]