]> granicus.if.org Git - icinga2/blob - etc/init.d/icinga2.in
8491cff1e784c7c3f52a634fef107e38e0d67a66
[icinga2] / etc / init.d / icinga2.in
1 #!/bin/sh
2 #
3 # chkconfig: 35 90 12
4 # description: Icinga 2
5 #
6 ### BEGIN INIT INFO
7 # Provides:          icinga2
8 # Required-Start:    $remote_fs $syslog
9 # Required-Stop:     $remote_fs $syslog
10 # Default-Start:     2 3 4 5
11 # Default-Stop:      0 1 6
12 # Short-Description: Start Icinga 2 at boot time
13 # Description:       Icinga 2
14 ### END INIT INFO
15
16 prefix=@prefix@
17 exec_prefix=@exec_prefix@
18 sbindir=@sbindir@
19 bindir=@bindir@
20 sysconfdir=@sysconfdir@
21 localstatedir=@localstatedir@
22
23 DAEMON=$bindir/icinga2
24 ICINGA2_CONFIG_FILE=$sysconfdir/icinga2/icinga2.conf
25 ICINGA2_PID_FILE=$localstatedir/run/icinga2/icinga2.pid
26 ICINGA2_ERROR_LOG=$localstatedir/log/icinga2/error.log
27
28 test -x $DAEMON || exit 0
29
30 if [ ! -e $ICINGA2_CONFIG_FILE ]; then
31         echo "Config file '$ICINGA2_CONFIG_FILE' does not exist."
32         exit 1
33 fi
34
35 # Get function from functions library
36 if [ -e /etc/init.d/functions ]; then
37         . /etc/init.d/functions
38 fi
39
40 # Start Icinga 2
41 start() {
42         mkdir -p `dirname -- $ICINGA2_PID_FILE`
43         mkdir -p `dirname -- $ICINGA2_ERROR_LOG`
44
45         echo "Validating the configuration file:"
46         if ! $DAEMON -c $ICINGA2_CONFIG_FILE -v; then
47                 echo "Not starting Icinga 2 due to configuration errors."
48                 exit 1
49         fi
50
51         printf "Starting Icinga 2: "
52         $DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG
53
54         echo "Done"
55         echo
56 }
57
58 # Restart Icinga 2
59 stop() {
60         printf "Stopping Icinga 2: "
61         if [ ! -e $ICINGA2_PID_FILE ]; then
62                 echo "The PID file '$ICINGA2_PID_FILE' does not exist."
63                 exit 1
64         fi
65
66         pid=`cat $ICINGA2_PID_FILE`
67         
68         if kill -INT $pid >/dev/null 2>&1; then
69                 for i in 1 2 3 4 5 6 7 8 9 10; do
70                         if ! kill -CHLD $pid >/dev/null 2>&1; then
71                                 break
72                         fi
73                 
74                         printf '.'
75                         
76                         sleep 1
77                 done
78         fi
79
80         if kill -CHLD $pid >/dev/null 2>&1; then
81                 kill -KILL $pid
82         fi
83
84         echo "Done"
85 }
86
87 # Print status for Icinga 2
88 status() {
89         printf "Icinga 2 status: "
90
91         pid=`cat $ICINGA2_PID_FILE`
92         if kill -CHLD $pid >/dev/null 2>&1; then
93                 echo "Running"
94         else
95                 echo "Not running"
96         fi
97 }
98
99 ### main logic ###
100 case "$1" in
101   start)
102         start
103         ;;
104   stop)
105         stop
106         ;;
107   status)
108         status FOO
109         ;;
110   restart|condrestart)
111         stop
112         start
113         ;;
114   *)
115         echo $"Usage: $0 {start|stop|restart|status}"
116         exit 1
117 esac
118 exit 0