#!/bin/bash

if [ -x /usr/bin/logger ]; then
	LOGGER="/usr/bin/logger -s -p user.notice -t NetworkManagerDispatcher"
else
	LOGGER=echo
fi

if [ ! -x /etc/init.d/sendmail ]; then
  $LOGGER "init script /etc/init.d/sendmail missing or not executible"
  return
fi
  
if [ -n $1 ] && [ $2 == "up" ]; then

  if [ -f /var/run/sendmail.pid ]; then
    $LOGGER "sendmail is running, restart"
    /sbin/service sendmail restart
  else
    $LOGGER "sendmail is not running, start"
    /sbin/service sendmail start
  fi

fi

if [ -n $1 ] && [ $2 == "down" ] && [ -f /var/run/sendmail.pid ]; then
  $LOGGER "sendmail is running, stop"
  /sbin/service sendmail stop
fi

