Comment 2 for bug 562377

Revision history for this message
Mathias Gug (mathiaz) wrote : Re: Add status action to slapd init script

Here is the proposed patch:

(l)mathiaz@mathiaz-srv:~/src/openldap/pkg-branches/lucid.dev/debian$ bzr diff --old ../../lucid/ slapd.init
=== modified file 'debian/slapd.init'
--- debian/slapd.init 2009-08-11 14:48:56 +0000
+++ debian/slapd.init 2010-04-12 23:21:40 +0000
@@ -189,6 +189,27 @@
        echo .
 }

+# Check OpenLDAP status
+status_slapd() {
+ # No PID
+ if [ ! -f $SLAPD_PIDFILE ]; then
+ echo "OpenLDAP is NOT running"
+ exit 3
+ fi
+
+ # Bogus PID
+ for pid in $(cat $SLAPD_PIDFILE) ; do
+ if ! ps --noheaders p "$pid" | grep $SLAPD > /dev/null ; then
+ echo "OpenLDAP is NOT running, bogus pidfile found: '$SLAPD_PIDFILE'"
+ exit 1
+ fi
+ done
+
+ # Running PID
+ echo "OpenLDAP is running"
+ exit 0
+}
+
 case "$1" in
   start)
        check_for_no_start
@@ -200,8 +221,10 @@
        stop_ldap
        start_ldap
        ;;
+ status)
+ status_slapd ;;
   *)
- echo "Usage: $0 {start|stop|restart|force-reload}"
+ echo "Usage: $0 {start|stop|restart|force-reload|status}"
        exit 1
        ;;
 esac