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() {
# increase boot counter
COUNTER_FILE="/tmp/start_cnt_httpd"
START_COUNTER=1
if [ -f "$COUNTER_FILE" ];
then
if [ -f "$COUNTER_FILE" ] ; then
read -r START_COUNTER < $COUNTER_FILE
START_COUNTER=$((START_COUNTER+1))
fi
......@@ -30,10 +29,6 @@ start() {
if [ "$CONFIG_HTTPD_DISABLE" = "y" ]; then
echo "web interface disabled in dot-config!"
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
fi
echo -n "Force start of lighttpd: "
......@@ -52,15 +47,6 @@ start() {
else
echo "Failed"
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() {
......
......@@ -17,34 +17,28 @@ start_counter() {
# increase start counter
COUNTER_FILE="/tmp/start_cnt_lldpd"
START_COUNTER=1
if [ -f "$COUNTER_FILE" ];
then
read -r START_COUNTER < $COUNTER_FILE
START_COUNTER=$((START_COUNTER+1))
if [ -f "$COUNTER_FILE" ] ; then
read -r START_COUNTER < $COUNTER_FILE
START_COUNTER=$((START_COUNTER+1))
fi
echo "$START_COUNTER" > $COUNTER_FILE
}
start() {
echo -n "Starting lldpd: "
if [ -f $dotconfig ]; then
. $dotconfig
. $dotconfig
else
echo "$0 unable to source dot-config ($dotconfig)!"
echo "$0 unable to source dot-config ($dotconfig)!"
fi
if [ "$CONFIG_LLDPD_DISABLE" = "y" ]; then
echo "lldpd disabled in dot-config!"
if [ "$1" != "force" ]; then
# Unmonitor lldpd, ignore all printouts from monit.
# Run in background since monit may wait for a timeout.
$MONIT unmonitor lldpd &>/dev/null &
exit 0
fi
echo -n "Force start of lldpd: "
echo "lldpd disabled in dot-config!"
if [ "$1" != "force" ]; then
exit 0
fi
echo -n "Force start of lldpd: "
fi
# Creating lldpd config
......@@ -54,57 +48,48 @@ start() {
tx_interval=5
if [ ! -z "$CONFIG_LLDPD_TX_INTERVAL" ]; then
tx_int=$CONFIG_LLDPD_TX_INTERVAL
# check if given value is an int
case $tx_int in
''|*[!0-9]*) echo -n "wrong CONFIG_LLDPD_TX_INTERVAL "$tx_int". Using 5 as the default interval. " ;;
*) echo tx_interval=$tx_int ;;
esac
tx_int=$CONFIG_LLDPD_TX_INTERVAL
# check if given value is an int
case $tx_int in
''|*[!0-9]*) echo -n "wrong CONFIG_LLDPD_TX_INTERVAL "$tx_int". Using 5 as the default interval. " ;;
*) echo tx_interval=$tx_int ;;
esac
fi
echo "configure lldp tx-interval $tx_interval" >> $LLDPD_CONFIG
if [ "$CONFIG_LLDPD_MINIMUM_FRAME_SIZE" = "y" ]; then
echo "configure system description 'WR-SWITCH'" >> $LLDPD_CONFIG
# disable capabilities-advertisements
echo "unconfigure ports all lldp capabilities-advertisements" >> $LLDPD_CONFIG
# disable management ip advertisements
echo "unconfigure ports all lldp management-addresses-advertisements" >> $LLDPD_CONFIG
echo "configure system description 'WR-SWITCH'" >> $LLDPD_CONFIG
# disable capabilities-advertisements
echo "unconfigure ports all lldp capabilities-advertisements" >> $LLDPD_CONFIG
# disable management ip advertisements
echo "unconfigure ports all lldp management-addresses-advertisements" >> $LLDPD_CONFIG
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
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
echo "resume" >> $LLDPD_CONFIG
start-stop-daemon -S -q -p /var/run/lldpd.pid --exec $LLDPD -- $LLDPD_OPT
ret=$?
if [ $ret -eq 0 ]; then
start_counter
echo "OK"
start_counter
echo "OK"
elif [ $ret -eq 1 ]; then
echo "Failed (already running?)"
echo "Failed (already running?)"
else
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
echo "Failed"
fi
}
stop() {
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
echo "OK"
echo "OK"
else
echo "Failed"
echo "Failed"
fi
}
......@@ -114,15 +99,15 @@ restart() {
}
case "$1" in
start)
start "$2"
;;
start)
start "$2"
;;
stop)
stop
;;
restart|reload)
restart
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start <force>|stop|restart}"
echo " start force -- enable lldpd even it is disabled in the dot-config"
......
......@@ -10,8 +10,7 @@ start_counter() {
# increase boot counter
COUNTER_FILE="/tmp/start_cnt_ldap"
START_COUNTER=1
if [ -f "$COUNTER_FILE" ];
then
if [ -f "$COUNTER_FILE" ] ; then
read -r START_COUNTER < $COUNTER_FILE
START_COUNTER=$((START_COUNTER+1))
fi
......@@ -29,10 +28,6 @@ start() {
if [ "$CONFIG_LDAP_ENABLE" != "y" ]; then
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
fi
......
......@@ -19,7 +19,7 @@
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
with start delay 30 # optional: delay the first check by 30 seconds (by
# # default Monit check immediately after Monit start)
#
#
......@@ -64,7 +64,7 @@ set statefile /tmp/monit.state
## It is possible to include additional configuration parts from other files or
## directories.
#
include /etc/monit.d/*.conf
include /etc/monit.d/*.conf.enabled
#
# enable Monit CLI to start and stop services, disable or enable service
# monitoring as well as view the status of each service.
......
......@@ -155,6 +155,43 @@ else
echo "No valid PTP option in dot-config!" | tee $log_output >& 2
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
/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