aboutsummaryrefslogtreecommitdiff
path: root/network/nsca/rc.nsca
blob: caa5846b6a7a46ccd5864a7a624063cf6dad5e44 (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
#!/bin/sh
#
# nsca daemon control script.
#
# This is an init script for the nsca daemon.
# To use nsca, you must first set up the config file(s).
#
# Written for Slackware Linux by Cherife li <cherife@dotimes.com>
# Modified for SBo by Zordrak <slackbuilds@tpa.me.uk>
# Modified by Mario Preksavec <mario@slackware.hr>

BIN=/usr/sbin/nsca
CFGFILE=/etc/nagios/nsca.cfg
PIDFILE=/var/run/nsca.pid
LOCKFILE=/var/lock/nsca

printstatus()
{
  if [ -e $PIDFILE ]; then
    echo "nsca (pid $PID) is running..."
  else
    echo "nsca is not running"
  fi
}

killproc()
{
  kill $2 $PID
}

getpid()
{
  if test ! -f $PIDFILE; then
    echo "Pid file $PIDFILE not found."
    exit 1
  else
    PID=`head -n 1 $PIDFILE`
  fi
}

# Check whether nsca bin file exists.
if [ ! -f $BIN ]; then
    echo "Executable file $BIN not found.  Exiting."
    exit 1
fi

# Check whether nsca config exists.
if [ ! -f $CFGFILE ]; then
    echo "Configuration file $CFGFILE not found.  Exiting."
    exit 1
fi

# Controls
case "$1" in
  start)
    echo -n "Starting nsca:"
    $BIN -c $CFGFILE -d
    touch $LOCKFILE
    echo " done."
  ;;
  stop)
    echo -n "Stopping nsca:"
    getpid
    killproc nsca
    rm -f $LOCKFILE
    echo " done."
  ;;
  status)
    getpid
    printstatus nsca
  ;;
  restart)
    $0 stop
    $0 start
  ;;
  *)
    echo "Usage: nsca {start|stop|restart|status}"
    exit 1
  ;;
esac