Issue 548 - SYSV initscript for slapd
Summary: SYSV initscript for slapd
Status: VERIFIED FIXED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: contrib (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2000-05-28 01:13 UTC by tengel@fluid.com
Modified: 2000-09-09 19:49 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description tengel@fluid.com 2000-05-28 01:13:23 UTC
Full_Name: Troy Engel
Version: any
OS: any SYSV R4
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (209.204.160.45)


Below is a SYSV initscript for the /etc/init.d tree of most OSes; it's been
tested on Solaris 2.x and Linux, so it should work anywhere a basic Bourne shell
is in place.  You can stop, start, and restart the slapd daemon.

== begin slapd.sysv ==
#!/bin/sh
# tengel@fluid.com
# stop/start slapd in a nice manner
 
SLAPD_BIN=/usr/local/libexec/slapd
SLAPD_PID=/usr/local/var/slapd.pid

case "$1" in
 
'start')
    if test -r $SLAPD_PID && kill -0 `cat $SLAPD_PID`; then
      echo "Already running according to $SLAPD_PID. Not started."
    else
      $SLAPD_BIN
    fi
    ;;
'stop')
    [ -f $SLAPD_PID ] || exit 0
    kill -TERM `cat $SLAPD_PID`
    rm -f $SLAPD_PID
    ;;
'restart')
    $0 stop
    $0 start
    ;;
*)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
  
esac
 
exit 0
== end slapd.sysv ==

-te

Comment 1 Ben Collins 2000-05-28 02:04:04 UTC
You might want to try this one, which is a modified version of the Debian
GNU/Linux script. Note, "killall" is not very portable outside of the
Linux expected usage, so change that for outside of this. The special
thing about this version is that it will start slurpd if there are any
replicas defined.

Ben

#! /bin/sh
#
# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Debian by Christoph Lameter <clameter@debian.org>
# Modified for OpenLDAP by Ben Collins <bcollins@debian.org>

PATH=/bin:/usr/bin:/sbin:/usr/sbin
SLAPD=/usr/sbin/slapd
SLURPD=/usr/sbin/slurpd

pidfile=`grep ^pidfile /etc/openldap/slapd.conf | awk '{print $2}'`
if [ -z "$pidfile" ]; then
    pidfile="/var/run/slapd.pid"
fi

test -x $DAEMON || exit 0

case "$1" in
  start)
    echo -n "Starting ldap server(s):"
    echo -n " slapd"
    $SLAPD
    replicas=`grep ^replica /etc/openldap/slapd.conf`
    test -z "$replicas" || (echo -n " slurpd" && $SLURPD)
    echo "."
    ;;
  stop)
    echo -n "Stopping ldap server(s):"
    echo -n " slapd"
    if [ -f "$pidfile" ]; then
        kill `cat /var/run/slapd.pid` > /dev/null 2>&1
    fi
    replicas=`grep ^replica /etc/openldap/slapd.conf`
    test -z "$replicas" || (echo -n " slurpd" && killall slurpd > /dev/null 2>&1)
    echo "."
    ;;
  restart|force-reload)
    echo "Restarting ldap server(s):"
    echo -n "  "
    $0 stop
    sleep 2 # give it some time to die
    echo -n "  "
    $0 start
    ;;
  force-stop)
    echo -n "Stopping ldap servers (force): "
    killall slapd slurpd > /dev/null 2>&1
    echo "done."
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|force-stop}"
    exit 1
    ;;
esac

exit 0

-- 
 -----------=======-=-======-=========-----------=====------------=-=------
/  Ben Collins  --  ...on that fantastic voyage...  --  Debian GNU/Linux   \
`  bcollins@debian.org  --  bcollins@openldap.org  --  bcollins@linux.com  '
 `---=========------=======-------------=-=-----=-===-======-------=--=---'
Comment 2 tengel@fluid.com 2000-05-28 19:20:57 UTC
Thanks!  I didn't see this anywhere in the tarball, hence my basic
submission.  I am developing my slapd database initially on Solaris, so
you're right - killall is bad (killall - kill all active processes) in
this world.

Below is some hackery I just did, based on the Portable Shell
Programming book -- it's about as portable I can get it, but I don't
have access to all platforms.  I've been able to test in on Linux,
Solaris, BSD (3), and SGI.  Help with AIX, HP, Ultrix, and DECOSF
appreciated.

== begin systype() and kprocs() functions, for portable "killall" ==

# systype and kprocs hacked from original functions in Portable
# Shell Programming:
# "The code in this file is from the book "Shell Programming
# Examples" by Bruce Blinn, published by Prentice Hall.
# This file may be copied free of charge for personal,
# non-commercial use provided that this notice appears in
# all copies of the file.  There is no warranty, either
# expressed or implied, supplied with this code."

# Determine an OS type
systype() {
 _HOSTNAME=`hostname | sed 's/\..*//'`
  case `uname -s` in
    AIX )          echo AIX              ;;
    BSD/OS )       echo BSD              ;;
    HP-UX )        echo HP               ;;
    IRIX )         echo SGI              ;;
    Linux )        echo LINUX            ;;
    OSF1 )         echo DECOSF           ;;
    ULTRIX )       echo ULTRIX           ;;
    SunOS )        case `uname -r` in
                     4*)  echo SUNBSD    ;;
                     5*)  echo SOLARIS   ;;
                   esac
                   ;;
    $_HOSTNAME )   case `uname -m` in
                     IP*)      echo SGI  ;;
                     i386)     echo SCO  ;;
                   esac
                   ;;
  esac
}

# Kill all named processes
kprocs() {
  OLD_IFS=$IFS              # Original value of IFS variable
  PROCESS_LIST=/tmp/list.$$ # Output of ps command
  SYSTEM=`systype`          # System type
  trap 'rm -f /tmp/*.$$; exit 1' 1 2 3 15
  # Get and check the command line parameters.
  SIGNAL=                   # Optional signal; see kill(1)
  case $1 in
    --)  shift
         ;;
    -*)  SIGNAL=$1          # Leave the hyphen
         shift
         ;;
  esac
  if [ $# -ne 1 ]; then
    echo "$USAGE" 1>&2
    exit 1
  fi
  NAME=$1        # Get the name of the process to kill.
  # Determine which options to use with the ps command.
  PS_OPTS=                  # Options for ps command
  case $SYSTEM in
    SUNBSD | ULTRIX ) PS_OPTS="-auxw"  ;;
    BSD )             PS_OPTS="-auw"   ;;
    * )               PS_OPTS="-ef"    ;;
  esac
  # Get a list of the current processes and filter out the
  # lines that do not contain the process we are looking for.
  ps $PS_OPTS             |
    sed '1d'              |  # Remove the title line
    grep -- "$NAME"       |  # Eliminate the chaff
    grep -v "$0"          |  # Eliminate this process
    grep -v "ps $PS_OPTS" >$PROCESS_LIST
  # Check each process.
  exec <$PROCESS_LIST
  IFS=
  while read LINE
  do
    IFS=$OLD_IFS
    # Get the owner, PID, and name of the process.
    set $LINE
    OWNER=$1
    PID=$2
    # Determine the column where the process name begins.
    COL=                      # Column where process name begins
    case $SYSTEM in
      AIX | HP | LINUX | SGI | SOLARIS )  COL=48 ;;
      SUNBSD | DECOSF )                   COL=57 ;;
      ULTRIX )                            COL=51 ;;
      BSD )                               COL=65 ;;
      * ) echo "Unexpected system type." 1>&2
          exit 1
          ;;
    esac
    LINE=`echo "$LINE" | cut -c$COL-`
    set dummy $LINE
    shift
    PROCNAME=$1
    if [ "$PROCNAME" = "$NAME" -o \
	    "`basename -- $PROCNAME`" = "$NAME" ]; then
      kill $SIGNAL $PID
    fi
    IFS=
  done
  rm -f /tmp/*.$$
}

== end systype() and kprocs() funtions ==


Ben Collins wrote:
> 
> You might want to try this one, which is a modified version of the Debian
> GNU/Linux script. Note, "killall" is not very portable outside of the
> Linux expected usage, so change that for outside of this. The special
> thing about this version is that it will start slurpd if there are any
> replicas defined.

-- 
Troy Engel, Systems Engineer
F L U I D - [http://www.fluid.com]
Comment 3 Kurt Zeilenga 2000-05-29 04:11:59 UTC
I think, in the end, such scripts will be quite specific
to the operating system and/or packaging.  Ben's example
is good case in point.  It has a killall option presumely
because they build with LinuxThreads (because you don't
need or want killall otherwise).

I like the idea of providing an example(s) of startup scripts.
However, they should be simple and platform neutral (or, well,
let's say implementation of the SYSV platform neutral :-).

Your original suggestion is seems appropriate (with a few
minor tweaks for greater portability).

Kurt

Comment 4 Kurt Zeilenga 2000-06-10 11:41:08 UTC
moved from Incoming to Contrib
Comment 5 Kurt Zeilenga 2000-09-09 19:49:20 UTC
changed state Open to Closed