Skip to content
Snippets Groups Projects
Commit 29e56226 authored by Adam Wujek's avatar Adam Wujek :speech_balloon:
Browse files

Merge branch 'adam-monit'

--Improve some init scripts
--Split start-daemons.sh.in
--Add monit conf files for HAL, RTUd and PPSi
parents 1cfa8ba3 641b76db
Branches
Tags
No related merge requests found
Showing
with 336 additions and 27 deletions
...@@ -1814,6 +1814,47 @@ gentle restarts before. ...@@ -1814,6 +1814,47 @@ gentle restarts before.
Date set from file @t{/update/saved_date} is never correct, but is based on Date set from file @t{/update/saved_date} is never correct, but is based on
best effort principle. best effort principle.
@c ==========================================================================
@node Supervision of running processes
@section Supervision of running processes
During normal operation @t{monit} supervises several processes running on a wrs
switch. Check is done every 10 seconds. As for now supervised processes are:
@t{wrsw_rtud},
@t{wrsw_hal},
@t{ppsi},
@t{lighttpd},
@t{dropbear},
@t{snmpd}.
In case any of the supervised processes does not run anymore (because of a crash,
exit etc.), @t{monit} restarts missing process. If 5 restarts of a process
occur during 10 cycles (10*10 seconds), the entire switch is restarted.
Since @t{monit} is started from the inittab, even if @t{monit} crashes for some
reason it will be re-spawned by the @t{init}.
@c ==========================================================================
@node Disabling monit
@subsection Disabling monit
In some cases, especially during development it is convenient to disable
@t{monit} to avoid annoying re-spawns of the processes and restarts of the entire
switch.
@t{monit} can be disabled with command:
@example
/etc/init.d/monit.sh stop
@end example
which will send STOP signal to @t{monit} or by adding @t{CONFIG_MONIT_DISABLE=y} to dot-config.
To re-enable @t{monit} first make sure there is no @t{CONFIG_MONIT_DISABLE=y} in dot-config, then execute command:
@example
/etc/init.d/monit.sh start
@end example
NOTE: Even when @t{monit} is disabled there is a process @t{/usr/bin/monit} in
a process list, but its state is "stopped" (T).
@c ========================================================================== @c ==========================================================================
@node SDB and Hardware Information @node SDB and Hardware Information
@section SDB and Hardware Information @section SDB and Hardware Information
......
...@@ -554,7 +554,7 @@ value is changed by the web interface, proper action is taken. ...@@ -554,7 +554,7 @@ value is changed by the web interface, proper action is taken.
@item CONFIG_MONIT_DISABLE @item CONFIG_MONIT_DISABLE
Disable monitoring of running processes by monit. Monit by default Disable monitoring of running processes by monit. Monit by default
re spawns processes that have died. This option is useful mostly during re-spawns processes that have died. This option is useful mostly during
development. development.
@end table @end table
......
...@@ -40,14 +40,27 @@ start() { ...@@ -40,14 +40,27 @@ start() {
fi fi
umask 077 umask 077
start-stop-daemon -S -q -p /var/run/dropbear.pid --exec /usr/sbin/dropbear start-stop-daemon -S -q -p /var/run/dropbear.pid --exec /usr/sbin/dropbear
start_counter ret=$?
echo "OK" if [ $ret -eq 0 ]; then
start_counter
echo "OK"
elif [ $ret -eq 1 ]; then
echo "Failed (already running?)"
else
echo "Failed"
fi
} }
stop() { stop() {
echo -n "Stopping dropbear sshd: " echo -n "Stopping dropbear sshd: "
start-stop-daemon -K -q -p /var/run/dropbear.pid start-stop-daemon -K -q -p /var/run/dropbear.pid
echo "OK" if [ $? -eq 0 ]; then
echo "OK"
else
echo "Failed"
fi
} }
restart() { restart() {
stop stop
start start
......
#!/bin/sh
dotconfig=/wr/etc/dot-config
start() {
echo -n "Starting HAL daemon: "
if [ -f $dotconfig ]; then
. $dotconfig
else
echo "$0 unable to source dot-config ($dotconfig)!"
fi
WRS_LOG=$CONFIG_WRS_LOG_HAL
# if empty turn it to /dev/null
if [ -z $WRS_LOG ]; then
WRS_LOG="/dev/null";
fi
# if a pathname, use it
if echo "$WRS_LOG" | grep / > /dev/null; then
eval LOGPIPE=\" \> $WRS_LOG 2\>\&1 \";
else
# not a pathname: use verbatim
eval LOGPIPE=\" 2\>\&1 \| logger -t wr-switch -p $WRS_LOG\"
fi
# be carefull with pidof, no running script should have the same name as process
if pidof wrsw_hal > /dev/null; then
# wrsw_hal already running
echo "Failed (already running?)"
else
eval /wr/bin/wrsw_hal $LOGPIPE \&
echo "OK"
fi
}
stop() {
echo -n "Stopping HAL "
start-stop-daemon -K -q --exec /wr/bin/wrsw_hal
if [ $? -eq 0 ]; then
echo "OK"
else
echo "Failed"
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
...@@ -21,23 +21,27 @@ start() { ...@@ -21,23 +21,27 @@ start() {
# running # running
start-stop-daemon -q -p /var/run/lighttpd.pid -S \ start-stop-daemon -q -p /var/run/lighttpd.pid -S \
--exec /usr/sbin/lighttpd -- -f /var/www/lighttpd.config --exec /usr/sbin/lighttpd -- -f /var/www/lighttpd.config
if [ $? -eq 0 ]; then ret=$?
if [ $ret -eq 0 ]; then
start_counter start_counter
echo "OK" echo "OK"
else elif [ $ret -eq 1 ]; then
echo "Failed (already running?)" echo "Failed (already running?)"
else
echo "Failed"
fi fi
} }
stop() { stop() {
echo -n "Stopping lighttpd daemon: " echo -n "Stopping lighttpd daemon: "
start-stop-daemon -K -q -p /var/run/lighttpd.pid start-stop-daemon -K -q -p /var/run/lighttpd.pid
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
start_counter
echo "OK" echo "OK"
else else
echo "Failed" echo "Failed"
fi fi
} }
restart() { restart() {
stop stop
start start
......
#!/bin/sh
dotconfig=/wr/etc/dot-config
start() {
echo -n "Starting PTP daemon: "
if [ -f $dotconfig ]; then
. $dotconfig
else
echo "$0 unable to source dot-config ($dotconfig)!"
fi
WRS_LOG=$CONFIG_WRS_LOG_PTP
# if empty turn it to /dev/null
if [ -z $WRS_LOG ]; then
WRS_LOG="/dev/null";
fi
# if a pathname, use it
if echo "$WRS_LOG" | grep / > /dev/null; then
eval LOGPIPE=\" \> $WRS_LOG 2\>\&1 \";
else
# not a pathname: use verbatim
eval LOGPIPE=\" 2\>\&1 \| logger -t wr-switch -p $WRS_LOG\"
fi
# be carefull with pidof, no running script should have the same name as process
if pidof ppsi > /dev/null; then
# ppsi already running
echo "Failed (already running?)"
else
eval /wr/bin/ppsi $LOGPIPE \&
echo "OK"
fi
}
stop() {
echo -n "Stopping PTP: "
start-stop-daemon -K -q --exec /wr/bin/ppsi
if [ $? -eq 0 ]; then
echo "OK"
else
echo "Failed"
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
#!/bin/sh
# simple wrapper for monit to announce reboot to console
echo "Monit triggered reboot due to $1" > /dev/console
/sbin/reboot
#!/bin/sh
dotconfig=/wr/etc/dot-config
start() {
echo -n "Starting RTUd daemon: "
if [ -f $dotconfig ]; then
. $dotconfig
else
echo "$0 unable to source dot-config ($dotconfig)!"
fi
WRS_LOG=$CONFIG_WRS_LOG_RTU
# if empty turn it to /dev/null
if [ -z $WRS_LOG ]; then
WRS_LOG="/dev/null";
fi
# if a pathname, use it
if echo "$WRS_LOG" | grep / > /dev/null; then
eval LOGPIPE=\" \> $WRS_LOG 2\>\&1 \";
else
# not a pathname: use verbatim
eval LOGPIPE=\" 2\>\&1 \| logger -t wr-switch -p $WRS_LOG\"
fi
# be carefull with pidof, no running script should have the same name as process
if pidof rtud > /dev/null; then
# rtud already running
echo "Failed (already running?)"
else
eval /wr/bin/wrsw_rtud $LOGPIPE \&
# ensure we receive UDP PTP frames, since ppsi supports UDP too.
/wr/bin/rtu_stat add 01:00:5e:00:01:81 18 0 &
echo "OK"
fi
}
stop() {
echo -n "Stopping RTUd "
start-stop-daemon -K -q --exec /wr/bin/wrsw_rtud
if [ $? -eq 0 ]; then
echo "OK"
else
echo "Failed"
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
...@@ -16,18 +16,31 @@ start_counter() { ...@@ -16,18 +16,31 @@ start_counter() {
} }
start() { start() {
echo -n "Starting snmpd daemon: "
# Log to syslog at daemon level. And log source address (-a) # Log to syslog at daemon level. And log source address (-a)
snmpd -Lsd -p $SNMP_PID -a -c $SNMP_CONF start-stop-daemon -q -p $SNMP_PID -S \
start_counter --exec /usr/sbin/snmpd -- -Lsd -p $SNMP_PID -a -c $SNMP_CONF
ret=$?
if [ $ret -eq 0 ]; then
start_counter
echo "OK"
elif [ $ret -eq 1 ]; then
echo "Failed (already running?)"
else
echo "Failed"
fi
} }
stop() { stop() {
if pidof snmpd > /dev/null; then echo -n "Stopping snmpd: "
echo -n "Stopping snmpd: " start-stop-daemon -K -q -p $SNMP_PID
start-stop-daemon -K -q -p $SNMP_PID if [ $? -eq 0 ]; then
echo "OK" echo "OK"
else
echo "Failed"
fi fi
} }
restart() { restart() {
stop stop
start start
......
...@@ -17,9 +17,17 @@ start() { ...@@ -17,9 +17,17 @@ start() {
# Check the configuration file: if there's no target, don't run the thing. # Check the configuration file: if there's no target, don't run the thing.
if ! grep -q '^##.*remote-host' /etc/rsyslog.conf; then if ! grep -q '^##.*remote-host' /etc/rsyslog.conf; then
echo -n "Starting rsyslog: " echo -n "Starting rsyslog: "
/usr/sbin/rsyslogd start-stop-daemon -q -p /var/run/rsyslogd.pid -S \
start_counter --exec /usr/sbin/rsyslogd
echo "OK" ret=$?
if [ $ret -eq 0 ]; then
start_counter
echo "OK"
elif [ $ret -eq 1 ]; then
echo "Failed (already running?)"
else
echo "Failed"
fi
else else
echo "Not starting rsyslog: no target host selected" echo "Not starting rsyslog: no target host selected"
# avoid SNMPd complaints about lack of start counter file # avoid SNMPd complaints about lack of start counter file
...@@ -28,12 +36,15 @@ start() { ...@@ -28,12 +36,15 @@ start() {
} }
stop() { stop() {
if pidof rsyslogd > /dev/null; then echo -n "Stopping rsyslog: "
echo -n "Stopping rsyslog: " start-stop-daemon -K -q -p /var/run/rsyslogd.pid
start-stop-daemon -K -q -p /var/log/rsyslog.pid if [ $? -eq 0 ]; then
echo "OK" echo "OK"
else
echo "Failed"
fi fi
} }
restart() { restart() {
stop stop
start start
......
...@@ -34,10 +34,10 @@ if [ ! -z "$CONFIG_WRSAUXCLK_PPSHIFT" ]; then ...@@ -34,10 +34,10 @@ if [ ! -z "$CONFIG_WRSAUXCLK_PPSHIFT" ]; then
fi fi
# execute wrs_auxclk # execute wrs_auxclk
echo "Configuring external clock clk2" echo -n "Configuring external clock clk2: "
/wr/bin/wrs_auxclk $p_freq $p_duty $p_cshift $p_sigdel $p_ppshift > /dev/null 2>&1 /wr/bin/wrs_auxclk $p_freq $p_duty $p_cshift $p_sigdel $p_ppshift > /dev/null 2>&1
if [ $? == 0 ]; then if [ $? == 0 ]; then
echo "External clock clk2 OK" echo "OK"
else else
echo "Failed to configure external clock clk2!!!" echo "Failed"
fi fi
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
start program = "/etc/init.d/dropbear start" start program = "/etc/init.d/dropbear start"
stop program = "/etc/init.d/dropbear stop" stop program = "/etc/init.d/dropbear stop"
if failed host localhost port 22 type tcp then restart if failed host localhost port 22 type tcp then restart
if 5 restarts within 10 cycles then exec "/sbin/reboot" if 5 restarts within 10 cycles then exec "/etc/init.d/reboot.sh dropbear"
check process wrsw_hal matching /wr/bin/wrsw_hal
start program = "/etc/init.d/hald.sh start"
stop program = "/etc/init.d/hald.sh stop"
if 5 restarts within 10 cycles then exec "/etc/init.d/reboot.sh hald"
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
start program = "/etc/init.d/lighttpd.sh start" start program = "/etc/init.d/lighttpd.sh start"
stop program = "/etc/init.d/lighttpd.sh stop" stop program = "/etc/init.d/lighttpd.sh stop"
if failed host localhost port 80 type tcp then restart if failed host localhost port 80 type tcp then restart
if 5 restarts within 10 cycles then exec "/sbin/reboot" if 5 restarts within 10 cycles then exec "/etc/init.d/reboot.sh lighttpd"
check process ppsi matching /wr/bin/ppsi
start program = "/etc/init.d/ppsi.sh start"
stop program = "/etc/init.d/ppsi.sh stop"
if 5 restarts within 10 cycles then exec "/etc/init.d/reboot.sh ppsi"
depends on wrsw_hal
check process wrsw_rtud matching /wr/bin/wrsw_rtud
start program = "/etc/init.d/rtud.sh start"
stop program = "/etc/init.d/rtud.sh stop"
if 5 restarts within 10 cycles then exec "/etc/init.d/reboot.sh rtud"
depends on wrsw_hal
check process snmpd with pidfile /var/run/snmpd.pid
start program = "/etc/init.d/snmp start"
stop program = "/etc/init.d/snmp stop"
if 5 restart within 10 cycles then exec "/sbin/reboot"
check process snmpd with pidfile /var/run/snmpd.pid
start program = "/etc/init.d/snmpd start"
stop program = "/etc/init.d/snmpd stop"
if 5 restart within 10 cycles then exec "/etc/init.d/reboot.sh snmpd"
../init.d/hald.sh
\ No newline at end of file
../init.d/ppsi.sh
\ No newline at end of file
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