#!/bin/sh
#
# /etc/rc.d/mailman: start/stop mailman daemon
#

SSD=/sbin/start-stop-daemon
PROG=/usr/bin/mailman
PID=/run/mailman/master.pid
USER=mailman
GROUP=mail

case $1 in
start)
  if [ ! -e /run/mailman ]; then
    install -d -o $USER -g $GROUP -m 755 /run/mailman
  fi
  $SSD --start -c $USER --pidfile $PID --exec $PROG -- start
  ;;
stop)
  $SSD --stop -c $USER --retry 10 --exec "/usr/bin/python3" --pidfile $PID
  ;;
restart)
  $0 stop
  $0 start
  ;;
reload)
  $SSD --start -c $USER --pidfile $PID --exec "/usr/bin/python3" --exec $PROG -- restart
  ;;
status)
  $SSD --status -u $USER -c $USER --exec "/usr/bin/python3" --pidfile $PID
  case $? in
  0) echo "$PROG is running with pid $(cat $PID)" ;;
  1) echo "$PROG is not running but the pid file $PID exists" ;;
  3) echo "$PROG is not running" ;;
  4) echo "Unable to determine the program status" ;;
  esac
  ;;
*)
  echo "usage: $0 [start|stop|restart|reload|status]"
  ;;
esac

# End of file
