#!/bin/sh # Startup script for Fedora Directory Server # # chkconfig: 345 86 14 # description: Run each LDAP slapd server in the Fedora Directory Server # Source function library. . /etc/rc.d/init.d/functions myName=`basename $0` fdsRoot="/opt/fedora-ds" # Get a list of all slapd server ID's # We will iterate over all server ID's when executing a command if [ -d ${fdsRoot}/slapd-* ]; then serverIDS=`ls -d $fdsRoot/slapd-* | sed -r 's!.*/slapd-([^/]+)/?!\1!'` else servierIDS="" fi start() { RETVAL=0 failed="" listSeparator="" failSeparator="" echo -n "Starting slapd trying: " for serverID in $serverIDS; do slapd="slapd-${serverID}" echo -n "${listSeparator}${serverID}" ${fdsRoot}/${slapd}/start-slapd > /dev/null 2>&1 slapdStatus=$? # 0: Server started successfully # 1: Server could not be started # 2: Server already running if [ $slapdStatus = 0 ]; then touch /var/lock/subsys/${slapd} else failed="${failed}${failSeparator}${serverID}(${slapdStatus})" failSeparator="," RETVAL=$slapdStatus fi listSeparator="," done if [ ! -z $failed ]; then echo -n " (FAIL ${failed})" fi if [ $RETVAL -eq 0 ]; then success else failure fi echo return $RETVAL } stop() { RETVAL=0 failed="" listSeparator="" failSeparator="" echo -n "Stopping slapd trying: " for serverID in $serverIDS; do slapd="slapd-${serverID}" echo -n "${listSeparator}${serverID}" ${fdsRoot}/${slapd}/stop-slapd > /dev/null 2>&1 slapdStatus=$? # 0: Server stopped successfully # 1: Server could not be stopped # 2: Server was not running if [ $slapdStatus = 0 ]; then rm -f /var/lock/subsys/${slapd} else if [ $slapdStatus != 1 ]; then rm -f /var/lock/subsys/${slapd} fi failed="${failed}${failSeparator}${serverID}(${slapdStatus})" failSeparator="," RETVAL=$slapdStatus fi listSeparator="," done if [ ! -z $failed ]; then echo -n " (FAIL ${failed})" fi if [ $RETVAL -eq 0 ]; then success else failure fi echo return $RETVAL } restart() { stop start } condrestart() { RETVAL=0 failed="" listSeparator="" failSeparator="" echo -n "Restarting slapd trying: " for serverID in $serverIDS; do slapd="slapd-${serverID}" if [ -f /var/lock/subsys/${slapd} ]; then echo -n "${listSeparator}${serverID}" ${fdsRoot}/${slapd}/restart-slapd > /dev/null 2>&1 slapdStatus=$? # 0: Server restarted successfully # 1: Server could not be started # 2: Server started successfully (was not running) # 3: Server could not be stopped if [ $slapdStatus = 0 ]; then touch /var/lock/subsys/${slapd} else failed="${failed}${failSeparator}${serverID}(${slapdStatus})" failSeparator="," RETVAL=$slapdStatus fi listSeparator="," fi done if [ ! -z $failed ]; then echo -n " (FAIL ${failed})" fi if [ $RETVAL -eq 0 ]; then success else failure fi echo return $RETVAL } status() { # Note: there are two pid files in the slapd-*/logs directory a # startpid file and a pid file. The startpid file is written when # the server is attempting to initialize, this may take a long # time. When the server is fully initialized and ready to receive # connections the pid file is written. Thus there is the question # of what constitutes running, initializing or ready? In this # instance we decide to report a running state when the server is # fully initalized and ready to serve clients. # init.d status should return: # 0 "$prog (pid $pid) is running..." # 1 "$prog dead but pid file exists" # 2 "$prog dead but subsys locked" # 3 "$prog is stopped" RETVAL=0 for serverID in $serverIDS; do slapd="slapd-${serverID}" pidFile=${fdsRoot}/${slapd}/logs/pid if test -f $pidFile ; then pid=`cat $pidFile` if kill -0 $pid > /dev/null 2>&1 ; then # slapd process $pid is running echo "$slapd (pid $pid) is running..." else echo "$slapd dead but pid file exists" if [ $RETVAL -eq 0 ]; then RETVAL=1 fi fi else if [ -f /var/lock/subsys/${slapd} ]; then echo "$slapd dead but subsys locked" if [ $RETVAL -eq 0 ]; then RETVAL=2 fi else echo "$slapd is stopped" if [ $RETVAL -eq 0 ]; then RETVAL=3 fi fi fi done return $RETVAL } case "$1" in start) start RETVAL=$? ;; stop) stop RETVAL=$? ;; reload|restart) restart RETVAL=$? ;; condrestart) condrestart RETVAL=$? ;; status) status RETVAL=$? ;; *) echo $"Usage: $myName {start|stop|restart|condrestart|status}" RETVAL=3 esac exit $RETVAL