aboutsummaryrefslogtreecommitdiff
path: root/utils/init_mauve.sh
blob: 309562cddf48b6a5eb50213e85651aa7c102c4de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
### BEGIN INIT INFO
# Provides:          mauveserver
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the mauve alerting daemon at boot time
# Description:       Start the mauve alerting daemon at boot time
### END INIT INFO

PATH=/bin:/sbin:/usr/bin:/usr/local/bin
DAEMON=/usr/bin/mauveserver
DAEMON_OPTS=/etc/mauvealert/mauveserver.conf
DESC="mauvealert server"
PIDFILE=/var/run/mauveserver.pid
LOG=/var/log/mauve

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
  start)
    log_begin_msg "Starting $DESC:" "$NAME"
    if [ ! -d $LOG ]; then mkdir $LOG; fi
    chown mauveserver $LOG /var/lib/mauveserver
    $DAEMON $DAEMON_OPTS &
    echo $! > $PIDFILE
    #start-stop-daemon --background --make-pidfile --pidfile $PIDFILE \
    #  --start --quiet --chuid mauveserver \
    #  --exec "$DAEMON" --oknodo -- $DAEMON_OPTS
    sleep 3
    #kill -0 $(cat $PIDFILE)
    #if [ $? != 0 ] ; then echo -n "failed"; else echo -n "success"; fi

    # Email on start.
    address="yann@bytemark.co.uk"
    lastLog=`/bin/ls -tr $LOG/*.log | tail -1`
    logLastLines=`tail -101 $lastLog`
    echo $logLastLines | mail -s "Mauve was started at `date`" $address

    log_end_msg $?
    ;;
  stop)
    log_begin_msg "Stopping $DESC:" "$NAME"
    if [ -f $PIDFILE ] ; then
      kill `cat $PIDFILE`
      rm $PIDFILE

      # Email on stop.
      address="yann@bytemark.co.uk"
      lastLog=`/bin/ls -tr $LOG/*.log | tail -1`
      logLastLines=`tail -101 $lastLog`
      echo $logLastLines | mail -s "Mauve was stopped at `date`" $address

    else
      echo Not running to stop
      exit 1
    fi
    log_end_msg $?
    ;;
  reload)
    if [ -f $PIDFILE ] ; then
      echo Sending restart signal to mauveserver
      kill -HUP `cat $PIDFILE`
    else
      echo Not running to reload
    fi
    ;;
  restart|reload|force-reload)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart}" >&2
    exit 1
    ;;
esac

exit 0