[Fedora-directory-commits] adminserver/wrappers initscript.in, NONE, 1.1

Noriko Hosoi (nhosoi) fedora-directory-commits at redhat.com
Fri Jun 15 17:13:04 UTC 2007


Author: nhosoi

Update of /cvs/dirsec/adminserver/wrappers
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv4913/wrappers

Added Files:
	initscript.in 
Log Message:
Resolves: #244325
Summary: init script for the Admin Server



--- NEW FILE initscript.in ---
#!/bin/sh
#
# @package_name@    This starts and stops @package_name@
#
# chkconfig:   - 21 79
# description: @package_name@ Admin Server
# processname: @sbindir@/httpd
# piddir:      @localstatedir@/run/@PACKAGE_BASE_NAME@
#

# Source function library.
if [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
fi
# Source networking configuration.
if [ -f /etc/sysconfig/network ] ; then
. /etc/sysconfig/network
fi

# Check that networking is up.
if [ "${NETWORKING}" = "no" ]
then
    echo "Networking is down"
    exit 0
fi

# Solaris echo cannot use -n - linux echo by default cannot use \c
echo_n()
{
    echo @ECHO_N@ "$*@ECHO_C@"
}

# failure and success are not defined on some platforms
type failure > /dev/null 2>&1 || {
failure()
{
    echo_n " FAILED"
}
}

type success > /dev/null 2>&1 || {
success()
{
    echo_n " SUCCESS"
}
}

# On Solaris /var/run is in tmpfs and gets wiped out upon reboot
# we have to recreate the /var/run/@package_name@ directory
# We also have to make sure that the directory is writable
# by the directory server process
# the argument to this function is the server instance directory,
# which must have a dse.ldif file in it
fix_pid_dir_ownership()
{
    if [ -d $piddir ] ; then
        owner=`grep \^sysuser @instconfigdir@/admin-serv/adm.conf | awk '{print $2}'`
        dirowner=`ls -ld $piddir | awk '{print $3}'`
        dirgrp=`ls -ld $piddir | awk '{print $4}'`
        if [ "$owner" != "$dirowner" ]; then
            groups $owner | grep $dirgrp > /dev/null 2>&1
            rc=$?
            if [ $rc -eq 0 ]; then
                chmod 770 $piddir
            else
                echo_n "$piddir is not writable for $owner"
                failure; echo
                exit 1
            fi
        fi
    else
        mkdir -p $piddir
        owner=`grep \^nsslapd-localuser $1/dse.ldif | awk '{print $2}'`
        if [ -n "$owner" ] ; then
            chown $owner $piddir
            chmod 700 $piddir
        fi
    fi
}

start_script=@sbindir@/start-ds-admin
restart_script=@sbindir@/restart-ds-admin
stop_script=@sbindir@/stop-ds-admin
exec=`grep "^HTTPD=" $start_script | awk -F= '{print $2}'`
prog="@package_name@"
# PID directory
piddir="@localstatedir@/run/@PACKAGE_BASE_NAME@"
# PID file
pidfile=$piddir/admin-serv.pid

[ -f $exec ] || exit 0

umask 077

start() {
    if [ ! -f $start_script ]; then
        echo_n "*** Error: $start_script does not exist"
        failure; echo
        exit 1
    fi
    echo  "Starting $prog: "
    # Start every slapd instance that isn't already running

    # the server creates pidfile and writes the pid to it when it is fully
    # started and available to serve clients
    server_running=0
    if [ -f $pidfile ]; then
        pid=`cat $pidfile`
        if kill -0 $pid > /dev/null 2>&1 ; then
            echo_n " already running"
            success; echo
            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
        fix_pid_dir_ownership 
        $start_script
        if [ $? -eq 0 ]; then
            server_started=1 # well, perhaps not running, but started ok
        else
            failure; echo
        fi
    fi
    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
                sleep 1
            else
                pid=`cat $pidfile`
                break
            fi
        done
        if kill -0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
            success; echo
        else
            echo_n "*** Error: $prog failed to start"
            failure; echo
        fi
    fi
}

stop() {
    if [ ! -f $stop_script ]; then
       echo_n "$stop_script does not exist"
       failure; echo
       exit 1
    fi
    echo "Shutting down $prog: "
    if [ -f $pidfile ]; then
        pid=`cat $pidfile`
        server_stopped=0
        if kill -0 $pid > /dev/null 2>&1 ; then
            kill $pid
            if [ $? -eq 0 ]; then
                server_stopped=1
            else
                failure; echo
            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
                echo_n "*** Error: $prog failed to stop"
                failure; echo
            else
                success; echo
                rm -f $pidfile
            fi
        fi
    fi
}

restart() {
    stop
    start
}


status() {
    if [ -f $pidfile ]; then
        pid=`cat $pidfile`
        if kill -0 $pid > /dev/null 2>&1 ; then
            echo "$prog (pid $pid) is running..."
        else
            echo "$prog dead but pid file exists"
        fi
    else
        echo "$prog is stopped"
    fi
}


case "$1" in
    start|stop|restart|reload|status)
        $1
        ;;
    condrestart)
        [ ! -f $lockfile ] || restart
        ;;
    *)
        echo Unknown command $1
        echo "Usage: $0 {start|stop|status|restart|condrestart}"
        exit 2
esac




More information about the Fedora-directory-commits mailing list