Commit a26170b2 authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch 'adam-monit' into master

Make monit to start from inittab instead of rcS script.
Add config files for:
--dropbear
--lighttpd
parents 18ea681a 053cd837
......@@ -471,3 +471,13 @@ config WRSAUXCLK_PPSHIFT
endmenu
menu "Developer options"
config MONIT_DISABLE
bool "Disable monit"
default n
help
Disable monit to prevent processes' restarts. It may be useful for
development.
endmenu
......@@ -551,6 +551,12 @@ value is changed by the web interface, proper action is taken.
the chosen name is expected to be installed in the @sc{wrs}
filesystem.
@item CONFIG_MONIT_DISABLE
Disable monitoring of running processes by monit. Monit by default
re spawns processes that have died. This option is useful mostly during
development.
@end table
@c ==========================================================================
......
......@@ -16,15 +16,27 @@ start_counter() {
}
start() {
echo -n "Starting lighttpd daemon: "
/usr/sbin/lighttpd -f /var/www/lighttpd.config
start_counter
echo "OK"
echo -n "Starting lighttpd daemon: "
# note start-stop-daemon does not create pidfile, only check if pid is
# running
start-stop-daemon -q -p /var/run/lighttpd.pid -S \
--exec /usr/sbin/lighttpd -- -f /var/www/lighttpd.config
if [ $? -eq 0 ]; then
start_counter
echo "OK"
else
echo "Failed (already running?)"
fi
}
stop() {
echo -n "Stopping lighttpd daemon: "
killall lighttpd
echo "OK"
start-stop-daemon -K -q -p /var/run/lighttpd.pid
if [ $? -eq 0 ]; then
start_counter
echo "OK"
else
echo "Failed"
fi
}
restart() {
stop
......
#!/bin/sh
# start monit
/usr/bin/monit
# script to be run directly from init
dotconfig=/wr/etc/dot-config
monit_pid=/var/run/monit.pid
start() {
# to start monit, first kill monit running/stopped previously, init will
# take care of starting it again
if [ -f $monit_pid ]; then
kill -9 `cat $monit_pid`
else
echo "Unable to find monit's pid"
exit 1
fi
}
stop() {
echo "Stopping monit"
# Stop monit by sending STOP singal to it. Killing monit will make init
# to start another instance of monit.
if [ -f $monit_pid ]; then
kill -STOP `cat $monit_pid`
else
echo "Unable to find monit's pid"
exit 1
fi
}
restart() {
echo "Restarting monit"
# invoke start
start
}
loop_forever() {
# Save pid of current script as monit's (used by start function).
echo $$ > $monit_pid
# sleep forever
while true; do sleep 10000; done
}
init() {
# First, read dot-config to know if we shall start monit
if [ -f $dotconfig ]; then
. $dotconfig
else
echo "dot-config not found! Don't start monit"
loop_forever
fi
if [ -z "$CONFIG_MONIT_DISABLE" ]; then
echo "Start monit"
# start monit
/usr/bin/monit
else
echo "Monit disabled in dot-config"
loop_forever
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
init)
init
;;
*)
echo $"Usage: $0 {start|stop|restart|init}"
exit 1
;;
esac
......@@ -23,6 +23,7 @@
# now run any rc scripts
::sysinit:/etc/init.d/rcS
::respawn:/etc/init.d/monit.sh init
# Put a getty on the serial port
ttyGS0::respawn:/bin/ash --login
......
check process dropbear with pidfile /var/run/dropbear.pid
start program = "/etc/init.d/dropbear start"
stop program = "/etc/init.d/dropbear stop"
if failed host localhost port 22 type tcp then restart
if 5 restarts within 10 cycles then exec "/sbin/reboot"
check process lighttpd with pidfile /var/run/lighttpd.pid
start program = "/etc/init.d/lighttpd.sh start"
stop program = "/etc/init.d/lighttpd.sh stop"
if failed host localhost port 80 type tcp then restart
if 5 restarts within 10 cycles then exec "/sbin/reboot"
check process snmpd with pidfile /var/run/snmpd.pid
start program = "/etc/init.d/snmp start"
stop program = "/etc/init.d/snmp stop"
# if failed host localhost port 161 type udp then restart
# if 5 restarts within 10 then exec "/sbin/reboot"
if 5 restart within 10 cycles then exec "/sbin/reboot"
......@@ -14,9 +14,11 @@
## Global section
###############################################################################
##
## Start Monit in the background (run as a daemon):
#
set daemon 10 # check services at 10 seconds intervals
# run from init
set init
#if "set init" don't run as daemon. "set daemon" only specify interval
set daemon 10 # check services at 10 seconds intervals,
# with start delay 240 # optional: delay the first check by 4-minutes (by
# # default Monit check immediately after Monit start)
#
......@@ -45,7 +47,15 @@ set idfile /var/monit/monit.id
## the monitoring state across reboots. If it is on temporary filesystem, the
## state will be lost on reboot which may be convenient in some situations.
#
set statefile /var/monit/monit.state
# We don't want to propagate monit's state over restarts. Otherwise following
# scenario is possible:
# --exceeded number of application restarts/crashes within given time
# --system restart due to above
# --application restart/crash again
# --monit will include application restart/crash after system restart in
# previous countings, so will trigger another restart
# We don't want to save monit's state over reboots, keep state file it in tmp
set statefile /tmp/monit.state
###############################################################################
## Includes
......@@ -54,5 +64,5 @@ set statefile /var/monit/monit.state
## It is possible to include additional configuration parts from other files or
## directories.
#
include /etc/monit.d/*
include /etc/monit.d/*.conf
#
......@@ -126,4 +126,5 @@ fastcgi.server = ( ".php" => ((
## where to upload files to, purged daily.
server.upload-dirs = ( "/tmp" )
server.pid-file = "/var/run/lighttpd.pid"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment