#!/bin/sh # Script that stops the ns-slapd server. # Exit status can be: # 0: Server stopped successfully # 1: Server could not be stopped # 2: Server was not running source @datadir@/@package_name@/data/DSSharedLib stop_instance() { SERV_ID=$1 initfile=`get_init_file $initconfig_dir $SERV_ID` || { echo Instance $SERV_ID not found. ; return 1 ; } # source env. for this instance if [ -f $initfile ] ; then . $initfile else echo Instance $SERV_ID not found. return 1 fi PIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.pid if test ! -f $PIDFILE ; then echo No ns-slapd PID file found. Server is probably not running return 2 fi PID=`cat $PIDFILE` # see if the server is already stopped kill -0 $PID > /dev/null 2>&1 || { echo Server not running if test -f $PIDFILE ; then rm -f $PIDFILE fi return 2 } # # use systemctl if running as root # if [ -d "@systemdsystemunitdir@" ] && [ "$(id -u)" == "0" ];then # # Now, check if systemctl is aware of this running instance # @bindir@/systemctl is-active @package_name@@$SERV_ID.service > /dev/null 2>&1 if [ $? -eq 0 ]; then # # systemctl sees the running process, so stop it correctly # @bindir@/systemctl stop @package_name@@$SERV_ID.service else # # Have to kill it since systemctl doesn't think it's running # kill $PID fi else # server is running - kill it kill $PID fi # wait for 10 minutes (600 times 1 second) loop_counter=1 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 return 0 fi done if test -f $PIDFILE ; then echo Server still running!! Failed to stop the ns-slapd process: $PID. Please check the errors log for problems. fi return 1 } while getopts "d:" flag do case "$flag" in d) initconfig_dir="$OPTARG";; esac done shift $(($OPTIND-1)) if [ "$initconfig_dir" = "" ]; then initconfig_dir=@initconfigdir@ fi if [ "$#" -eq 0 ]; then # We're stopping all instances. ret=0 initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; } for i in $initfiles; do if [ ! -f "$i" ] ; then echo No instances found in $initconfig_dir exit 1 fi inst=`normalize_server_id $i` echo Stopping instance \"$inst\" stop_instance $inst rv=$? if [ "$rv" -ne 0 ]; then ret=$rv fi done exit $ret else # We're stopping a single instance. stop_instance $@ exit $? fi