4 # Required-Start: $remote_fs $syslog
5 # Required-Stop: $remote_fs $syslog
6 # Default-Start: 2 3 4 5
8 # Short-Description: icinga2 host/service/network monitoring and management system
9 # Description: icinga2 is a monitoring and management system for hosts, services and networks.
12 # Author: Alexander Wirt <formorer@debian.org>
13 # Markus Frosch <markus@lazyfrosch.de>
15 # PATH should only include /usr/* if it runs after the mountnfs.sh script
16 PATH=/sbin:/usr/sbin:/bin:/usr/bin
17 DESC="icinga2 monitoring daemon"
19 DAEMON=/usr/sbin/icinga2
20 DAEMON_CONFIG="/etc/icinga2/icinga2.conf"
23 DAEMON_CMDGROUP=www-data
24 DAEMON_ARGS="-e /var/log/icinga2/icinga2.err"
25 PIDFILE=/var/run/icinga2/$NAME.pid
26 SCRIPTNAME=/etc/init.d/$NAME
28 # Exit if the package is not installed
29 [ -x "$DAEMON" ] || exit 0
31 # Read configuration variable file if it is present
32 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
34 # Load the VERBOSE setting and other rcS variables
37 # Define LSB log_* functions.
38 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
39 # and status_of_proc is working.
40 . /lib/lsb/init-functions
44 test -d '/var/run/icinga2' || mkdir /var/run/icinga2
45 test -d '/var/run/icinga2/cmd' || mkdir /var/run/icinga2/cmd
47 chown "$DAEMON_USER":"$DAEMON_GROUP" /var/run/icinga2
48 chmod 0755 /var/run/icinga2
50 chown "$DAEMON_USER":"$DAEMON_CMDGROUP" /var/run/icinga2/cmd
51 chmod 2710 /var/run/icinga2/cmd
55 $DAEMON --validate -u "$DAEMON_USER" -g "$DAEMON_GROUP" -c "$DAEMON_CONFIG"
59 # Function that starts the daemon/service
64 # 0 if daemon has been started
65 # 1 if daemon was already running
66 # 2 if daemon could not be started
67 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
69 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
70 -c "$DAEMON_CONFIG" -u "$DAEMON_USER" -g "$DAEMON_GROUP" -d $DAEMON_ARGS \
72 # Add code here, if necessary, that waits for the process to be ready
73 # to handle requests from services started subsequently which depend
74 # on this one. As a last resort, sleep for some time.
78 # Function that starts the daemon/service in foreground for debugging
82 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test \
84 start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- \
85 -c "$DAEMON_CONFIG" -u "$DAEMON_USER" -g "$DAEMON_GROUP" $DAEMON_ARGS \
90 # Function that stops the daemon/service
95 # 0 if daemon has been stopped
96 # 1 if daemon was already stopped
97 # 2 if daemon could not be stopped
98 # other if a failure occurred
99 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
101 [ "$RETVAL" = 2 ] && return 2
102 # Wait for children to finish too if this is a daemon that forks
103 # and if the daemon is only ever run from this initscript.
104 # If the above conditions are not satisfied then add some other code
105 # that waits for the process to drop all resources that could be
106 # needed by services started subsequently. A last resort is to
107 # sleep for some time.
108 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
109 [ "$?" = 2 ] && return 2
110 # Many daemons don't delete their pidfiles when they exit.
116 # Function that sends a SIGHUP to the daemon/service
120 # If the daemon can reload its configuration without
121 # restarting (for example, when it is sent a SIGHUP),
122 # then implement that here.
124 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
130 log_begin_msg "checking Icinga2 configuration"
131 if ! check_config >/dev/null 2>&1; then
134 log_failure_msg "checking Icinga2 configuration"
138 [ -n "$DOEXITONOK" ] && exit 0
147 log_daemon_msg "Starting $DESC" "$NAME"
150 0|1) log_end_msg 0 ;;
156 log_action_msg "Starting $DESC in foreground"
158 trap 'status=2;' INT # handle intr here
160 do_foreground || status="$?"
163 log_success_msg "$NAME ended graceful"
167 if [ "$i" -eq 1 ]; then
168 log_warning_msg "$NAME already running!"
169 log_begin_msg "Do you want to stop $NAME before going foreground? [y/N] "
171 if [ "$question" = "y" ] || [ "$question" = "yes" ]; then
176 log_failure_msg "$NAME already running! Please stop before starting in foreground!"
180 log_failure_msg "$NAME ended"
188 log_daemon_msg "Stopping $DESC" "$NAME"
191 0|1) log_end_msg 0 ;;
196 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
200 log_daemon_msg "Reloading $DESC" "$NAME"
206 log_daemon_msg "Restarting $DESC" "$NAME"
213 1) log_end_msg 1 ;; # Old process is still running
214 *) log_end_msg 1 ;; # Failed to start
227 echo "Usage: $SCRIPTNAME {start|stop|status|reload|force-reload|restart|checkconfig|foreground}" >&2
232 # vi: ts=2 sw=2 expandtab :