#!/bin/sh
#
# Restart the daemons which might have changed the configuration
# during install

set -e 

echo "info: Stopping services in sequence."
for ALL in /etc/rc1.d/K* ; do 
  if [ -h $ALL ] ; then 
    SERVICE=$(basename $(readlink $ALL))
  else
    SERVICE=$(basename $ALL)
  fi
  echo "info: Stopping $SERVICE"
  $ALL stop || /bin/true
done

for service in \
    slapd \
    rpcbind \
    apache \
    ;
    do
  if [ "$(pidof $service)" ] ; then
      echo "info: '$service' still running, sending HUP."
      pkill $service || /bin/true
  fi
done

echo "info: Checking what's still running"
ps aux | while read LINE ; do 
  echo "info: $LINE"
done

for service in \
    slapd \
    rpcbind \
    apache \
    ;
    do
  if [ "$(pidof $service)" ] ; then
      echo "info: '$service' still running, sending KILL."
      pkill -9 $service || /bin/true
  fi
done

echo "info: Checking what's still running"
ps aux | while read LINE ; do 
  echo "info: $LINE"
done

echo "Info: Restarting networking"
/etc/init.d/networking restart || /bin/true

echo "info: Starting services in sequence."
for ALL in /etc/rc2.d/S* ; do 
  if [ -h $ALL ] ; then 
    SERVICE=$(basename $(readlink $ALL))
  else
    SERVICE=$(basename $ALL)
  fi
  echo "info: Starting $SERVICE"
  $ALL start || /bin/true
done

exit 0
