|
One of the most asked questions about this new logging is:
How do I rewrite my init scripts to take advantage of this? The short answer is:
You don't. In general, most scripts written for earlier versions of Red
Hat Linux should work transparently with the new scripts.
For example, the following script should work fine:
Example 1. ypserv
#!/bin/sh
#
# ypserv: Starts the yp-server
#
# Version: @(#) /etc/rc.d/init.d/ypserv.init 1.0
#
# Author: Joerg Mertin <smurphy@stargate.bln.sub.org>
#
# chkconfig: - 12 88
# description: ypserv is an implementation of the standard NIS/YP networking \
# protocol. It allows network-wide distribution of hostname, \
# username, and other information databases. This is the NIS \
# server, and is not needed on NIS clients.
# processname: ypserv
# config: /etc/ypserv.conf
# Source function library.
. /etc/rc.d/init.d/functions
# getting the YP-Domainname
. /etc/sysconfig/network
# See how we were called.
case "$1" in
start)
echo -n "Starting YP server services: "
daemon ypserv
echo
touch /var/lock/subsys/ypserv
;;
stop)
echo -n "Stopping YP server services: "
killproc ypserv
rm -f /var/lock/subsys/ypserv
echo
;;
status)
status ypserv
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit 0
|
What we've done is modify the
daemon and killproc functions (used by
most scripts) to take advantage of the new logging and display functions,
so that most script writers don't have to change their scripts.
- daemon
-
The daemon function is used to start services. Its syntax is:
daemon [+/-nicelevel] [--check program] command
|
nicelevel is the nice level to run the command at - see
man 1 nice for details.
program is the name of the service you are
running if it's not the first argument of the command
parameter. The
canonical example is using su to run a service as a different
user:
daemon --check xfs su xfs -c "xfs"
|
- killproc
-
The killproc function is used to stop services. Its syntax is:
where signal is the optional signal to send to the process.
If your init script uses these functions, it will automatically
take advantage of the new logging and display functionality.
If it doesn't, it will still be logged and displayed similarily
at boot and shutdown, as scripts of this sort are run
through initlog. However, this does mean that starting and
stopping a service of this sort from the command line will
not be logged.
We do not recommend init script authors writing scripts that
specifically call logging and display functions, simply because
it ties these scripts to specific versions of Red Hat Linux.
However, if you feel that it is necessary to call some of these functions directly,
the following are available:
- success, failure
-
success/failure description
|
Logs that the action described by description succeeded/failed, and
prints an appropriate marker.
- action
-
action "some action" command
|
Runs command, logs whether the specified action succeeded or
failed, and prints an appropriate display. For example:
action "Mounting NFS filesystems" mount -a -t nfs
|
|