summaryrefslogtreecommitdiff
path: root/templates/irc_bot/Debian/nagios-nsa.sh.erb
blob: 6e608db942aabddfe5b78285788c8537e2bb49b1 (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
#! /bin/sh

### BEGIN INIT INFO
# Provides:		nagios-nsa
# Required-Start:	$remote_fs $syslog $nagios
# Required-Stop:	$remote_fs $syslog $nagios
# Default-Start:	2 3 4 5
# Default-Stop:		1 6 0
# Short-Description:	Nagios Simple IRC Agent
### END INIT INFO

PIDFILE=<%= nagios_nsa_pidfile %>
SOCKFILE=<%= nagios_nsa_socket %>

. /lib/lsb/init-functions

start() {
	log_daemon_msg "Starting nagios IRC bot" "nagios-nsa"
        if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --user nagios --chuid nagios --exec /usr/local/bin/riseup-nagios-server.pl; then
            log_end_msg 0
        else
            log_end_msg 1
        fi
}

stop () {
	log_daemon_msg "Stopping nagios IRC bot" "nagios-nsa"
        if start-stop-daemon --stop --quiet --pidfile $PIDFILE; then
            log_end_msg 0
        else
            log_end_msg 1
        fi
}

remove_socket() {
	[ -e $SOCKFILE ] && rm $SOCKFILE
}

cleanup() {
        if [ -r $PIDFILE ]; then
                ps -p `cat $PIDFILE` | grep -v 'PID' || {
			echo "not running"
			remove_socket
		}
        else
                echo "no pid file"
		remove_socket
        fi
}

case $1
in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
		cleanup
                start
                ;;
        status)
                status_of_proc -p $PIDFILE /usr/local/bin/riseup-nagios-server.pl && exit 0 || exit $?
                ;;
        *)
                log_action_msg "Usage: /etc/init.d/nagios-nsa {start|stop|restart|status}"
                exit 1
esac