Commit 65970bde authored by Jean-Claude BAU's avatar Jean-Claude BAU

Bug fix: Monit errors appearing in syslog at startup

As monit process is started after other processes, it does not take into
account  the 'unmonitor' messages sent from start scripts (ldap.sh,
...). This generates error messages at startup.

To avoid that, the configuration of monit is set now dynamically in the
apply_dotconfig script. All disabled processes are then removed from the
configuration to avoid errors due to process start order.
Also the first monitoring cycle is postponed by 30s at startup.
parent 734deab9
...@@ -10,8 +10,7 @@ start_counter() { ...@@ -10,8 +10,7 @@ start_counter() {
# increase boot counter # increase boot counter
COUNTER_FILE="/tmp/start_cnt_httpd" COUNTER_FILE="/tmp/start_cnt_httpd"
START_COUNTER=1 START_COUNTER=1
if [ -f "$COUNTER_FILE" ]; if [ -f "$COUNTER_FILE" ] ; then
then
read -r START_COUNTER < $COUNTER_FILE read -r START_COUNTER < $COUNTER_FILE
START_COUNTER=$((START_COUNTER+1)) START_COUNTER=$((START_COUNTER+1))
fi fi
...@@ -30,10 +29,6 @@ start() { ...@@ -30,10 +29,6 @@ start() {
if [ "$CONFIG_HTTPD_DISABLE" = "y" ]; then if [ "$CONFIG_HTTPD_DISABLE" = "y" ]; then
echo "web interface disabled in dot-config!" echo "web interface disabled in dot-config!"
if [ "$1" != "force" ]; then if [ "$1" != "force" ]; then
# Unmonitor web server (lighttpd), ignore all printouts
# from monit.
# Run in background since monit may wait for a timeout.
$MONIT unmonitor lighttpd &>/dev/null &
exit 0 exit 0
fi fi
echo -n "Force start of lighttpd: " echo -n "Force start of lighttpd: "
...@@ -52,15 +47,6 @@ start() { ...@@ -52,15 +47,6 @@ start() {
else else
echo "Failed" echo "Failed"
fi fi
# check whether the process was monitored
$MONIT summary 2>&1 | grep lighttpd | grep "Not monitored" &> /dev/null
if [ $? -eq 0 ]; then
echo "web interface was not monitored, enabling monitoring"
# the process was not monitored, enable monitoring
# this will generate extra log entries from monit
$MONIT monitor lighttpd
fi
} }
stop() { stop() {
......
...@@ -17,34 +17,28 @@ start_counter() { ...@@ -17,34 +17,28 @@ start_counter() {
# increase start counter # increase start counter
COUNTER_FILE="/tmp/start_cnt_lldpd" COUNTER_FILE="/tmp/start_cnt_lldpd"
START_COUNTER=1 START_COUNTER=1
if [ -f "$COUNTER_FILE" ]; if [ -f "$COUNTER_FILE" ] ; then
then read -r START_COUNTER < $COUNTER_FILE
read -r START_COUNTER < $COUNTER_FILE START_COUNTER=$((START_COUNTER+1))
START_COUNTER=$((START_COUNTER+1))
fi fi
echo "$START_COUNTER" > $COUNTER_FILE echo "$START_COUNTER" > $COUNTER_FILE
} }
start() { start() {
echo -n "Starting lldpd: " echo -n "Starting lldpd: "
if [ -f $dotconfig ]; then if [ -f $dotconfig ]; then
. $dotconfig . $dotconfig
else else
echo "$0 unable to source dot-config ($dotconfig)!" echo "$0 unable to source dot-config ($dotconfig)!"
fi fi
if [ "$CONFIG_LLDPD_DISABLE" = "y" ]; then if [ "$CONFIG_LLDPD_DISABLE" = "y" ]; then
echo "lldpd disabled in dot-config!" echo "lldpd disabled in dot-config!"
if [ "$1" != "force" ]; then if [ "$1" != "force" ]; then
# Unmonitor lldpd, ignore all printouts from monit. exit 0
# Run in background since monit may wait for a timeout. fi
$MONIT unmonitor lldpd &>/dev/null & echo -n "Force start of lldpd: "
exit 0
fi
echo -n "Force start of lldpd: "
fi fi
# Creating lldpd config # Creating lldpd config
...@@ -54,57 +48,48 @@ start() { ...@@ -54,57 +48,48 @@ start() {
tx_interval=5 tx_interval=5
if [ ! -z "$CONFIG_LLDPD_TX_INTERVAL" ]; then if [ ! -z "$CONFIG_LLDPD_TX_INTERVAL" ]; then
tx_int=$CONFIG_LLDPD_TX_INTERVAL tx_int=$CONFIG_LLDPD_TX_INTERVAL
# check if given value is an int # check if given value is an int
case $tx_int in case $tx_int in
''|*[!0-9]*) echo -n "wrong CONFIG_LLDPD_TX_INTERVAL "$tx_int". Using 5 as the default interval. " ;; ''|*[!0-9]*) echo -n "wrong CONFIG_LLDPD_TX_INTERVAL "$tx_int". Using 5 as the default interval. " ;;
*) echo tx_interval=$tx_int ;; *) echo tx_interval=$tx_int ;;
esac esac
fi fi
echo "configure lldp tx-interval $tx_interval" >> $LLDPD_CONFIG echo "configure lldp tx-interval $tx_interval" >> $LLDPD_CONFIG
if [ "$CONFIG_LLDPD_MINIMUM_FRAME_SIZE" = "y" ]; then if [ "$CONFIG_LLDPD_MINIMUM_FRAME_SIZE" = "y" ]; then
echo "configure system description 'WR-SWITCH'" >> $LLDPD_CONFIG echo "configure system description 'WR-SWITCH'" >> $LLDPD_CONFIG
# disable capabilities-advertisements # disable capabilities-advertisements
echo "unconfigure ports all lldp capabilities-advertisements" >> $LLDPD_CONFIG echo "unconfigure ports all lldp capabilities-advertisements" >> $LLDPD_CONFIG
# disable management ip advertisements # disable management ip advertisements
echo "unconfigure ports all lldp management-addresses-advertisements" >> $LLDPD_CONFIG echo "unconfigure ports all lldp management-addresses-advertisements" >> $LLDPD_CONFIG
else else
echo "configure system description 'WR-SWITCH: $(/wr/bin/wrsw_version)'" >> $LLDPD_CONFIG echo "configure system description 'WR-SWITCH: $(/wr/bin/wrsw_version)'" >> $LLDPD_CONFIG
fi fi
if [ "$CONFIG_LLDPD_MANAGEMENT_PORT_DISABLE" = "y" ]; then if [ "$CONFIG_LLDPD_MANAGEMENT_PORT_DISABLE" = "y" ]; then
echo "configure system interface pattern '!eth*'" >> $LLDPD_CONFIG echo "configure system interface pattern '!eth*'" >> $LLDPD_CONFIG
fi fi
echo "resume" >> $LLDPD_CONFIG echo "resume" >> $LLDPD_CONFIG
start-stop-daemon -S -q -p /var/run/lldpd.pid --exec $LLDPD -- $LLDPD_OPT start-stop-daemon -S -q -p /var/run/lldpd.pid --exec $LLDPD -- $LLDPD_OPT
ret=$? ret=$?
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
start_counter start_counter
echo "OK" echo "OK"
elif [ $ret -eq 1 ]; then elif [ $ret -eq 1 ]; then
echo "Failed (already running?)" echo "Failed (already running?)"
else else
echo "Failed" echo "Failed"
fi
# check whether the process was monitored
$MONIT summary 2>&1 | grep lldpd | grep "Not monitored" &> /dev/null
if [ $? -eq 0 ]; then
echo "lldpd was not monitored, enabling monitoring"
# the process was not monitored, enable monitoring
# this will generate extra log entries from monit
$MONIT monitor lldpd
fi fi
} }
stop() { stop() {
echo -n "Stopping lldpd: " echo -n "Stopping lldpd: "
start-stop-daemon -K -q -p /var/run/lldpd.pid start-stop-daemon -K -q -p /var/run/lldpd.pid
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "OK" echo "OK"
else else
echo "Failed" echo "Failed"
fi fi
} }
...@@ -114,15 +99,15 @@ restart() { ...@@ -114,15 +99,15 @@ restart() {
} }
case "$1" in case "$1" in
start) start)
start "$2" start "$2"
;; ;;
stop) stop)
stop stop
;;
restart|reload)
restart
;; ;;
restart|reload)
restart
;;
*) *)
echo "Usage: $0 {start <force>|stop|restart}" echo "Usage: $0 {start <force>|stop|restart}"
echo " start force -- enable lldpd even it is disabled in the dot-config" echo " start force -- enable lldpd even it is disabled in the dot-config"
......
...@@ -10,8 +10,7 @@ start_counter() { ...@@ -10,8 +10,7 @@ start_counter() {
# increase boot counter # increase boot counter
COUNTER_FILE="/tmp/start_cnt_ldap" COUNTER_FILE="/tmp/start_cnt_ldap"
START_COUNTER=1 START_COUNTER=1
if [ -f "$COUNTER_FILE" ]; if [ -f "$COUNTER_FILE" ] ; then
then
read -r START_COUNTER < $COUNTER_FILE read -r START_COUNTER < $COUNTER_FILE
START_COUNTER=$((START_COUNTER+1)) START_COUNTER=$((START_COUNTER+1))
fi fi
...@@ -29,10 +28,6 @@ start() { ...@@ -29,10 +28,6 @@ start() {
if [ "$CONFIG_LDAP_ENABLE" != "y" ]; then if [ "$CONFIG_LDAP_ENABLE" != "y" ]; then
echo "LDAP not enabled in dot-config" | tee $log_output echo "LDAP not enabled in dot-config" | tee $log_output
# Unmonitor web server (nslcd), ignore all printouts
# from monit.
# Run in background since monit may wait for a timeout.
$MONIT unmonitor nslcd &>/dev/null &
exit 0 exit 0
fi fi
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
set init set init
#if "set init" don't run as daemon. "set daemon" only specify interval #if "set init" don't run as daemon. "set daemon" only specify interval
set daemon 10 # check services at 10 seconds intervals, set daemon 10 # check services at 10 seconds intervals,
# with start delay 240 # optional: delay the first check by 4-minutes (by with start delay 30 # optional: delay the first check by 30 seconds (by
# # default Monit check immediately after Monit start) # # default Monit check immediately after Monit start)
# #
# #
...@@ -64,7 +64,7 @@ set statefile /tmp/monit.state ...@@ -64,7 +64,7 @@ set statefile /tmp/monit.state
## It is possible to include additional configuration parts from other files or ## It is possible to include additional configuration parts from other files or
## directories. ## directories.
# #
include /etc/monit.d/*.conf include /etc/monit.d/*.conf.enabled
# #
# enable Monit CLI to start and stop services, disable or enable service # enable Monit CLI to start and stop services, disable or enable service
# monitoring as well as view the status of each service. # monitoring as well as view the status of each service.
......
...@@ -155,6 +155,43 @@ else ...@@ -155,6 +155,43 @@ else
echo "No valid PTP option in dot-config!" | tee $log_output >& 2 echo "No valid PTP option in dot-config!" | tee $log_output >& 2
fi fi
# Configure processes to be monitored by monit
# It creates a symbolic link with extension .enabled for all processes to monitor
rm -f /etc/monit.d/*.enabled
if [ "$CONFIG_MONIT_DISABLE" != "y" ]; then
# Evaluate all processes that must be monitored
monit_configs=`ls /etc/monit.d/*.conf`
if [ -n "$monit_configs" ]; then
for config in $monit_configs ; do
process=`basename $config .conf`
monitor=1
case $process in
lldpd) if [ "$CONFIG_LLDPD_DISABLE" == "y" ] ; then
monitor=0
fi
;;
nslcd) if [ "$CONFIG_LDAP_ENABLE" != "y" ] ; then
monitor=0;
fi
;;
lighttpd) if [ "$CONFIG_HTTPD_DISABLE" == "y" ] ; then
monitor=0
fi
;;
*) ;;
esac
if [[ $monitor = 1 ]] ; then
ln -s $config $config.enabled
fi
done
fi
fi
#if monit is running, force it to re-read its configuration
#monit_pid=/var/run/monit.pid
#if [ -f $monit_pid ] ; then
# kill -SIGHUP `cat $monit_pid`
#fi
# System clock monitor: program the cron tab # System clock monitor: program the cron tab
/etc/init.d/system_clock_monitor -s /etc/init.d/system_clock_monitor -s
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