[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: SYSV initscript for slapd (ITS#548)

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

== 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   ;;
    $_HOSTNAME )   case `uname -m` in
                     IP*)      echo SGI  ;;
                     i386)     echo SCO  ;;

# 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
  if [ $# -ne 1 ]; then
    echo "$USAGE" 1>&2
    exit 1
  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"    ;;
  # 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.
  while read LINE
    # Get the owner, PID, and name of the process.
    set $LINE
    # 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
    LINE=`echo "$LINE" | cut -c$COL-`
    set dummy $LINE
    if [ "$PROCNAME" = "$NAME" -o \
	    "`basename -- $PROCNAME`" = "$NAME" ]; then
      kill $SIGNAL $PID
  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]