#!/bin/sh # # sympa Mailing Lists Management System # # Written by Michel Bouissou 20/07/2000 # # Modified by Olivier Salaun 27/07/2000 # - translations # - lang parameter deleted (defined in sympa.conf) # - introduced --VARS-- parsed by Makefile # - no more sympauser since sympa sets its UID # Modified by Michel Bouissou 27/07/2000 # # chkconfig: 345 95 05 # description: Sympa is a powerful mailing list management system. if [ -f --initdir--/functions ]; then # Source function library. . --initdir--/functions ## Set a flag use_functions=1 fi # Sympa parameters # Sympa binaries directory sympadir="--sbindir--" # Sympa config files directory sympaconf="--CONFIG--" sympapiddir="--piddir--" sympalockdir="--lockdir--" RETVAL=1 if [ -f /etc/sysconfig/network ]; then # Get config. . /etc/sysconfig/network fi # OSTYPE is not defined on Solaris if [ ! "${OSTYPE}" ]; then OSTYPE=`uname -s` fi # OSTYPE *is* defined on Solaris 10! (bug #3149) case "$OSTYPE" in *solaris*) OSTYPE=SunOS ;; Linux) if [ -f /etc/SuSE-release ] ; then OSDIST='Suse' fi if [ -f /etc/debian_version ] ; then OSDIST='Debian' fi if [ -f /etc/slackware-version ] ; then OSDIST='Slack' fi ;; *BSD) OSDIST=$OSTYPE OSTYPE=BSD ;; esac ##'echo -n' not supported with SH on Solaris if [ ${OSTYPE} = "SunOS" ]; then echo_opt="" else echo_opt="-n" fi # End of parameters # Current state of the module sympa_status() { # Test syntax. if [ $# = 0 ] ; then echo "Usage: sympa_status {program}" return 1 fi if [ ${use_functions} ]; then status $1.pl else comm=`echo $1.pl | cut -c-8` if [ -f ${sympapiddir}/$1.pid ] ; then pids=`head -1 ${sympapiddir}/$1.pid` runningpids="" if [ "$pids" != "" ] ; then for pid in $pids; do if [ "$OSTYPE" = "BSD" ]; then running=`ps -axw | grep "^[[:space:]]*$pid[[:space:]]"` else running=`ps -A | grep "$pid ..* $comm"` fi if [ "$running" != "" ]; then runningpids="$runningpids $pid" fi done if [ "$runningpids" != "" ]; then echo "$1 (pid(s)$runningpids) is active..." return 0 else echo "$1 died, pid file remains." return 1 fi fi fi echo "$1 is stopped." return 3 fi } # Health check sympa_check() { echo $echo_opt "Checking environment: " if [ ${use_functions} ]; then $sympadir/sympa.pl --health_check && success || failure return $? else if $sympadir/sympa.pl --health_check; then echo "success" return 0 else echo "failure" return 1 fi fi echo } # Start a module sympa_module_start() { if [ $# = 0 ] ; then echo "Usage: sympa_module_start {program}" return 1 fi # if [ $1 = "sympa" -a $lang != "" ]; then # startparam="-l $lang" # else # startparam="" # fi if [ ${use_functions} ]; then $sympadir/$1.pl $startparam && success || failure else $sympadir/$1.pl $startparam && echo "success" || echo "failure" fi echo } # Test state of module before startup sympa_start() { if [ $# = 0 ] ; then echo "Usage: sympa_start {program}" return 1 fi sympa_status $1 > /dev/null case "$?" in 3) echo $echo_opt "Starting module $1.pl: " sympa_module_start $1 ;; 1) echo $echo_opt "Starting $1, overwriting old pid file." sympa_module_start $1 ;; 0) echo "$1 seems active. No action will be taken." echo "Try \"sympa status\" or \"sympa restart"\". ;; esac } # Stop a module sympa_stop() { if [ $# = 0 ] ; then echo "Usage: sympa_stop {program}" return 1 fi if [ $1 = 'sympa-creation' ]; then process_name='sympa'; else process_name=$1; fi comm=`echo $process_name.pl | cut -c-8` if [ -f ${sympapiddir}/$1.pid ]; then echo $echo_opt "Stopping module $process_name.pl: " pids=`head -1 ${sympapiddir}/$1.pid` runcount=0 if [ "$pids" != "" ]; then for pid in $pids; do killcount=0 if [ "$OSTYPE" = "BSD" ]; then running=`ps -axw | grep "^[[:space:]]*$pid[[:space:]]"` else running=`ps -A | grep "$pid ..* $comm"` fi while [ "$running" != "" ]; do if [ $killcount -gt 10 ]; then if [ ${use_functions} ]; then failure else echo 'failure' fi return 3 fi kill -TERM $pid >/dev/null 2>&1 if [ "$OSTYPE" = "BSD" ]; then running=`ps -axw | grep "^[[:space:]]*$pid[[:space:]]"` else running=`ps -A | grep "$pid ..* $comm"` fi if [ "$running" = "" ]; then runcount=`expr $runcount + 1` break fi sleep 2 if [ "$OSTYPE" = "BSD" ]; then running=`ps -axw | grep "^[[:space:]]*$pid[[:space:]]"` else running=`ps -A | grep "$pid ..* $comm"` fi if [ "$running" = "" ]; then runcount=`expr $runcount + 1` break fi killcount=`expr $killcount + 1` done done fi if [ $runcount -gt 0 ]; then if [ ${use_functions} ]; then success else echo 'success' fi else echo 'died' fi echo else echo "Module $process_name.pl not running" fi return 0 } # Check that networking is up. if [ ${OSTYPE} != "Linux" -a ${OSTYPE} != "BSD" -a ${OSTYPE} != "SunOS" -a ${OSTYPE} != "Darwin" ]; then if [ "${NETWORKING}" = "no" ] then exit 0 fi fi # Check config files [ -d $sympadir ] || exit 0 [ -f $sympaconf ] || exit 0 # See how we were called. case "$1" in start) if [ ! -f ${sympalockdir}/sympa ]; then echo "Starting Sympa subsystem: " sympa_check || exit 1 sympa_start sympa_msg sympa_start bulk sympa_start archived sympa_start bounced sympa_start task_manager touch ${sympalockdir}/sympa echo else echo "Sympa seems active. No action will be taken." echo "Try \"sympa status\" or \"sympa restart"\". fi RETVAL=$? ;; stop) echo "Stopping Sympa subsystem: " sympa_stop bounced sympa_stop archived sympa_stop bulk sympa_stop sympa_msg if [ -f ${sympapiddir}/sympa.pid ]; then # For Sympa earlier than 6.2b.4 sympa_stop sympa fi if [ -f ${sympapiddir}/sympa-distribute.pid ]; then # For Sympa earlier than 6.2b.1 sympa_stop sympa-distribute fi if [ -f ${sympapiddir}/sympa-creation.pid ]; then # For Sympa earlier than 6.2b.4 sympa_stop sympa-creation fi if [ -f ${sympapiddir}/sympa_automatic.pid ]; then sympa_stop sympa_automatic fi sympa_stop task_manager if [ -f ${sympalockdir}/sympa ]; then rm -f ${sympalockdir}/sympa fi RETVAL=$? ;; status) echo "Status of Sympa subsystem: " if [ -f ${sympalockdir}/sympa ]; then echo "Status file for subsystem found." else echo "Status file for subsystem NOT found." fi sympa_status sympa_msg sympa_status bulk sympa_status archived sympa_status bounced sympa_status task_manager RETVAL=$? ;; restart) echo "Restarting Sympa subsystem: " $0 stop && $0 start echo ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac exit $RETVAL