[Fedora-directory-commits] ldapserver/wrappers initscript.in, NONE, 1.1
Richard Allen Megginson (rmeggins)
fedora-directory-commits at redhat.com
Fri Feb 9 22:34:01 UTC 2007
Author: rmeggins
Update of /cvs/dirsec/ldapserver/wrappers
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv5558/ldapserver/wrappers
Added Files:
initscript.in
Log Message:
Resolves: bug 160235
Bug Description: Add support for /etc/init scripts
Reviewed by: nkinder (Thanks!)
Fix Description: Add the new initscript. The initscript is called $PACKAGE_NAME which by
default is fedora-ds. This script is created from wrappers/initscript.in,
sed'd by the fixupcmd in Makefile.am during make install. The way it works is
this: service fedora-ds cmd will execute the cmd on all instances (found in
/etc/fedora-ds by default). service fedora-ds cmd instance will execute cmd on
only that instance. So if you have
/etc/fedora-ds/slapd-foo
/etc/fedora-ds/slapd-bar
and you do
service start fedora-ds
it will start up both slapd-foo and slapd-bar. If you do
service start fedora-ds bar
it will start up only slapd-bar. If you do
service start fedora-ds biff
you will get an error message. The initdir is platform specific (e.g.
/etc/rc.d/init.d on linux, /etc/init.d on Solaris) so the
definition was added to the platform dependent section of configure.ac.
The init script is explicitly branded, including the filename. I needed to add
support to the autotool files so that we could change the name of the file.
Since package_name is defined when you use the AC_INIT macro in configure.ac,
we don't need to define it elsewhere (e.g. #define BRAND_DS). So I added the
branding and other information to the autotool files, and changed
create_instance to use package_name instead of brand_ds to be consistent.
Having the package_name defined in much fewer places should make it much easier
to change in the future if necessary.
I also fixed a compiler warning in ldaprot.h.
Platforms tested: RHEL4, FC6
Flag Day: no
Doc impact: Yes. We need to document how to use the initscript, and how to enable startup on boot - chkconfig fedora-ds on
--- NEW FILE initscript.in ---
#!/bin/bash
#
# @package_name@ This starts and stops @package_name@
#
# chkconfig: - 21 79
# description: @package_name@ Directory Server
# processname: @sbindir@/ns-slapd
# configdir: @sysconfdir@/@package_name@/
# piddir: @localstatedir@/run/@package_name@
# datadir: @localstatedir@/lib/@package_name@/slapd-<instance name>
#
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
echo "Networking is down"
exit 0
fi
exec="@sbindir@/ns-slapd"
prog="@package_name@"
# Lockfile
lockfile="@localstatedir@/lock/subsys/@package_name@"
# PID directory
piddir="@localstatedir@/run/@package_name@"
# Instance basedir
instbase="@sysconfdir@/@package_name@"
[ -f $exec ] || exit 0
umask 077
pids=$(pidof $exec)
INSTANCES=""
for FILE in `/bin/ls -d $instbase/slapd-* 2>/dev/null`; do
INSTANCES+=$(echo "$FILE" | sed -e "s|$instbase/slapd-||")
INSTANCES+=" "
done
if [ -n "$2" ]; then
for I in $INSTANCES; do
if [ "$2" == "$I" ]; then
INSTANCES="$2"
fi
done
if [ "$2" != "$INSTANCES" ]; then
echo -n "$2 is an invalid @package_name@ instance"
failure; echo
exit 1
fi
fi
start() {
if [ -n "$INSTANCES" ]; then
export LD_LIBRARY_PATH=@libdir@/@package_name@:@nss_libdir@
echo "Starting $prog: "
# Start every slapd instance that isn't already running
errors=0
successes=0
for instance in $INSTANCES; do
echo -n " $instance..."
# the server creates pidfile and writes the pid to it when it is fully
# started and available to serve clients
pidfile=$piddir/slapd-$instance.pid
# the server creates startpidfile and writes the pid to just after
# the process begins i.e. it received the startup request and didn't
# die a horrible death (e.g. shared lib problem, oom, etc.)
startpidfile=$piddir/slapd-$instance.startpid
server_running=0
if [ -e $pidfile ]; then
pid=$(cat $pidfile)
if [ $(echo "$pids" | grep -c $pid) -ge 1 ]; then
echo -n " already running"
success; echo
let successes=successes+1
server_running=1
else
echo -n " not running, but pid file exists - attempt to start anyway..."
rm -f $pidfile
fi
fi
server_started=0
if [ $server_running -eq 0 ] ; then
rm -f $pidfile
rm -f $startpidfile
$exec -D $instbase/slapd-$instance -i $pidfile -w $startpidfile
if [ $? -eq 0 ]; then
server_started=1 # well, perhaps not running, but started ok
else
failure; echo
let errors=errors+1
fi
fi
# ok, if we started the server successfully, let's see if it is really
# running and ready to serve requests
if [ $server_started -eq 1 ] ; then
loop_counter=1
# wait for 10 seconds for the start pid file to appear
max_count=10
while test $loop_counter -le $max_count; do
loop_counter=`expr $loop_counter + 1`
if test ! -f $startpidfile ; then
sleep 1
else
pid=`cat $startpidfile`
fi
done
if test ! -f $startpidfile ; then
failure; echo
let errors=errors+1
server_started=0
fi
fi
# ok, server wrote the startpid file - let's see if it comes up
# ready to service requests
if [ $server_started -eq 1 ] ; then
loop_counter=1
# wait for 10 minutes (600 times 1 seconds)
max_count=600
while test $loop_counter -le $max_count ; do
loop_counter=`expr $loop_counter + 1`
if test ! -f $pidfile ; then
if kill -0 $pid > /dev/null 2>&1 ; then
sleep 1
else
break
fi
else
pid=`cat $pidfile`
break
fi
done
if kill -0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
success; echo
let successes=successes+1
else
failure; echo
let errors=errors+1
fi
fi
rm -f $startpidfile
done
if [ $successes -ge 1 ]; then
touch $lockfile
fi
if [ $errors -ge 1 ]; then
echo "*** Warning: $errors instance(s) failed to start"
fi
else
echo "*** Error: no $prog instances configured"
fi
}
stop() {
echo "Shutting down $prog: "
errors=0
for instance in $INSTANCES; do
pidfile=$piddir/slapd-$instance.pid
if [ -e $pidfile ]; then
pid=$(cat $pidfile)
echo -n " $instance..."
server_stopped=0
if [ $(echo "$pids" | grep -c $pid) -ge 1 ]; then
kill $pid
if [ $? -eq 0 ]; then
server_stopped=1
else
failure; echo
let errors=errors+1
fi
fi
if [ $server_stopped -eq 1 ] ; then
loop_counter=1
# wait for 10 minutes (600 times 1 second)
max_count=600
while test $loop_counter -le $max_count; do
loop_counter=`expr $loop_counter + 1`
if kill -0 $pid > /dev/null 2>&1 ; then
sleep 1
else
if test -f $pidfile ; then
rm -f $pidfile
fi
break
fi
done
if test -f $pidfile ; then
failure; echo
let errors=errors+1
else
success; echo
rm -f $pidfile
fi
fi
fi
done
if [ $errors -ge 1 ]; then
echo -n "*** Error: $errors instance(s) unsuccessfully stopped"
failure; echo
else
rm -f $lockfile
fi
}
restart() {
stop
start
}
status() {
for instance in $INSTANCES; do
if [ -e $piddir/slapd-$instance.pid ]; then
pid=$(cat $piddir/slapd-$instance.pid)
if [ $(echo "$pids" | grep -c $pid) -ge 1 ]; then
echo "$prog $instance (pid $pid) is running..."
else
echo "$prog $instance dead but pid file exists"
fi
else
echo "$prog $instance is stopped"
fi
done
}
case "$1" in
start|stop|restart|reload|status)
$1
;;
condrestart)
[ ! -f $lockfile ] || restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart} [instance-name]"
exit 2
esac
More information about the Fedora-directory-commits
mailing list