xymon-client startup script issue (and fix)
list Bakkies Gatvol
I am documenting this for whomever else may need this. This file is from an rpm xymon-client-4.3.10-1 that I got off the net somewhere. I just figured out why the "stop" does not work.
I set CLIENTHOSTNAME in here
=> more /etc/default/xymon-client
# Configure the Xymon client settings.
# You MUST set the list of Xymon servers that this
# client reports to.
# It is good to use IP-adresses here instead of DNS
# names - DNS might not work if there's a problem.
#
# E.g. (a single Xymon server)
# XYMONSERVERS="192.168.1.1"
# or (multiple servers)
# XYMONSERVERS="10.0.0.1 192.168.1.1"
XYMONSERVERS="10.65.1.66 10.65.20.151"
# The defaults usually suffice for the rest of this file,
# but you can tweak the hostname that the client reports
# data with.
# Thu Mar 21 15:30:16 EDT 2013
CLIENTHOSTNAME="$(hostname | cut -f1 -d'.')"
# Red Hat EL version 3 uses a different vmstat layout
# than all other Linux versions. So for a client running this
# particular OS, set CLIENTOS as below.
# Do NOT set this on any other Red Hat version.
# CLIENTOS="rhel3"
but the script does not pass that info on the stop - so the start worked fine, but the stop not. Even the restart worked. I fixed below
#
# xymon-client This shell script takes care of starting and stopping
# the Xymon client.
#
# chkconfig: 2345 80 20
# description: Xymon is a network monitoring tool that allows \
# you to monitor hosts and services. This client reports local \
# system statistics (cpu-, memory-, disk-utilisation etc) \
# to the Xymon server.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/lib/xymon/client/runclient.sh
NAME=xymon-client
DESC=xymon-client
test -x $DAEMON || exit 0
CMD="$1"
# Include xymon-client defaults if available
DMNOPTS=""
if [ -f /etc/default/xymon-client ] ; then
. /etc/default/xymon-client
else
echo "Installation failure - missing /etc/default/xymon-client"
exit 1
fi
if [ "$XYMONSERVERS" = "" ]; then
echo "Please configure XYMONSERVERS in /etc/default/xymon-client"
exit 1
fi
set $XYMONSERVERS
if [ $# -eq 1 ]; then
echo "XYMSRV=\"$XYMONSERVERS\"" >/var/run/xymonclient-runtime.cfg
echo "XYMSERVERS=\"\"" >>/var/run/xymonclient-runtime.cfg
else
echo "XYMSRV=\"0.0.0.0\"" >/var/run/xymonclient-runtime.cfg
echo "XYMSERVERS=\"$XYMONSERVERS\"" >>/var/run/xymonclient-runtime.cfg
fi
if [ "$CLIENTHOSTNAME" != "" ]; then
DMNOPTS="${DMNOPTS} --hostname=${CLIENTHOSTNAME}"
fi
if [ "$CLIENTOS" != "" ]; then
DMNOPTS="${DMNOPTS} --os=${CLIENTOS}"
fi
set -e
case "$CMD" in
start)
echo -n "Starting $DESC: "
su -c "$DAEMON $DMNOPTS start" - xymon
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
su -c "$DAEMON stop" - xymon ### is
## su -c "$DAEMON $DMNOPTS stop" - xymon # ## should be this!!!
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
su -c "$DAEMON stop" - xymon
su -c "$DAEMON $DMNOPTS start" - xymon
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart}" >&2
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
list Jeremy Laidman
So when CLIENTHOSTNAME is defined, it needs to get passed into $DAEMON (ie runclient.sh) with the "--hostname=" parameter, because that overrides $MACHINEDOTS, which is used in the PID filename. If it cannot find the PID filename, it won't be able to get the PID and kill the process. Yes, this looks like a bug. I don't see how "restart" worked though. Perhaps it looked like it restarted because it never stopped? J
▸
On 25 September 2013 04:51, Bakkies Gatvol <user-66e2e196cd54@xymon.invalid> wrote:
I am documenting this for whomever else may need this. This file is from an rpm xymon-client-4.3.10-1 that I got off the net somewhere. I just figured out why the "stop" does not work. I set CLIENTHOSTNAME in here => more /etc/default/xymon-client # Configure the Xymon client settings. # You MUST set the list of Xymon servers that this # client reports to. # It is good to use IP-adresses here instead of DNS # names - DNS might not work if there's a problem. # # E.g. (a single Xymon server) # XYMONSERVERS="192.168.1.1" # or (multiple servers) # XYMONSERVERS="10.0.0.1 192.168.1.1" XYMONSERVERS="10.65.1.66 10.65.20.151" # The defaults usually suffice for the rest of this file, # but you can tweak the hostname that the client reports # data with. # Thu Mar 21 15:30:16 EDT 2013 CLIENTHOSTNAME="$(hostname | cut -f1 -d'.')" # Red Hat EL version 3 uses a different vmstat layout # than all other Linux versions. So for a client running this # particular OS, set CLIENTOS as below. # Do NOT set this on any other Red Hat version. # CLIENTOS="rhel3" but the script does not pass that info on the stop - so the start worked fine, but the stop not. Even the restart worked. I fixed below # # xymon-client This shell script takes care of starting and stopping # the Xymon client. # # chkconfig: 2345 80 20 # description: Xymon is a network monitoring tool that allows \ # you to monitor hosts and services. This client reports local \ # system statistics (cpu-, memory-, disk-utilisation etc) \ # to the Xymon server. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/lib/xymon/client/runclient.sh NAME=xymon-client DESC=xymon-client test -x $DAEMON || exit 0 CMD="$1" # Include xymon-client defaults if available DMNOPTS="" if [ -f /etc/default/xymon-client ] ; then . /etc/default/xymon-client else echo "Installation failure - missing /etc/default/xymon-client" exit 1 fi if [ "$XYMONSERVERS" = "" ]; then echo "Please configure XYMONSERVERS in /etc/default/xymon-client" exit 1 fi set $XYMONSERVERS if [ $# -eq 1 ]; then echo "XYMSRV=\"$XYMONSERVERS\"" >/var/run/xymonclient-runtime.cfg echo "XYMSERVERS=\"\"" >>/var/run/xymonclient-runtime.cfg else echo "XYMSRV=\"0.0.0.0\"" >/var/run/xymonclient-runtime.cfg echo "XYMSERVERS=\"$XYMONSERVERS\""/var/run/xymonclient-runtime.cfg fiif [ "$CLIENTHOSTNAME" != "" ]; then DMNOPTS="${DMNOPTS} --hostname=${CLIENTHOSTNAME}" fi if [ "$CLIENTOS" != "" ]; then DMNOPTS="${DMNOPTS} --os=${CLIENTOS}" fi set -e case "$CMD" in start) echo -n "Starting $DESC: " su -c "$DAEMON $DMNOPTS start" - xymon echo "$NAME." ;; stop) echo -n "Stopping $DESC: " su -c "$DAEMON stop" - xymon ### is *## su -c "$DAEMON $DMNOPTS stop" - xymon # ## should be this!!!* echo "$NAME." ;; restart) echo -n "Restarting $DESC: " su -c "$DAEMON stop" - xymon su -c "$DAEMON $DMNOPTS start" - xymon echo "$NAME." ;; *) N=/etc/init.d/$NAME # echo "Usage: $N {start|stop|restart}" >&2 echo "Usage: $N {start|stop|restart}" >&2 exit 1 ;; esac exit 0
list Bakkies Gatvol
I did not actually test restart, but I did a start on a running client and it said Xymon client already running, re-starting it and it seemed to actually successfully stop and start the client. (Timestamp on ps changed) So I was thinking that a restart would work because start does it's own restart. Which was not what I was expecting when I ran "start", but it was not a bad surprise. I contemplated if I could use start for stop ... but nope, that was not going to do what I needed! In my own code fix, I fixed restart as well / the same way as stop. But I thought best to be conservative with a public posting :) Bakkies
▸
From: user-71895fb2e44c@xymon.invalid
Date: Wed, 25 Sep 2013 11:02:40 +1000
Subject: Re: [Xymon] xymon-client startup script issue (and fix)
To: user-66e2e196cd54@xymon.invalid
CC: xymon at xymon.com
So when CLIENTHOSTNAME is defined, it needs to get passed into $DAEMON (ie runclient.sh) with the "--hostname=" parameter, because that overrides $MACHINEDOTS, which is used in the PID filename. If it cannot find the PID filename, it won't be able to get the PID and kill the process.
Yes, this looks like a bug.
I don't see how "restart" worked though. Perhaps it looked like it restarted because it never stopped?
J
On 25 September 2013 04:51, Bakkies Gatvol <user-66e2e196cd54@xymon.invalid> wrote:
I am documenting this for whomever else may need this. This file is from an rpm xymon-client-4.3.10-1 that I got off the net somewhere. I just figured out why the "stop" does not work.
I set CLIENTHOSTNAME in here
=> more /etc/default/xymon-client
# Configure the Xymon client settings.
# You MUST set the list of Xymon servers that this
# client reports to.
# It is good to use IP-adresses here instead of DNS
# names - DNS might not work if there's a problem.
#
# E.g. (a single Xymon server)
# XYMONSERVERS="192.168.1.1"
# or (multiple servers)
# XYMONSERVERS="10.0.0.1 192.168.1.1"
XYMONSERVERS="10.65.1.66 10.65.20.151"
# The defaults usually suffice for the rest of this file,
# but you can tweak the hostname that the client reports
# data with.
# Thu Mar 21 15:30:16 EDT 2013
CLIENTHOSTNAME="$(hostname | cut -f1 -d'.')"
# Red Hat EL version 3 uses a different vmstat layout
# than all other Linux versions. So for a client running this
# particular OS, set CLIENTOS as below.
# Do NOT set this on any other Red Hat version.
# CLIENTOS="rhel3"
but the script does not pass that info on the stop - so the start worked fine, but the stop not. Even the restart worked. I fixed below
#
# xymon-client This shell script takes care of starting and stopping
# the Xymon client.
#
# chkconfig: 2345 80 20
# description: Xymon is a network monitoring tool that allows \
# you to monitor hosts and services. This client reports local \
# system statistics (cpu-, memory-, disk-utilisation etc) \
# to the Xymon server.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/lib/xymon/client/runclient.sh
NAME=xymon-client
DESC=xymon-client
test -x $DAEMON || exit 0
CMD="$1"
# Include xymon-client defaults if available
DMNOPTS=""
if [ -f /etc/default/xymon-client ] ; then
. /etc/default/xymon-client
else
echo "Installation failure - missing /etc/default/xymon-client"
exit 1
fi
if [ "$XYMONSERVERS" = "" ]; then
echo "Please configure XYMONSERVERS in /etc/default/xymon-client"
exit 1
fi
set $XYMONSERVERS
if [ $# -eq 1 ]; then
echo "XYMSRV=\"$XYMONSERVERS\"" >/var/run/xymonclient-runtime.cfg
echo "XYMSERVERS=\"\"" >>/var/run/xymonclient-runtime.cfg
else
echo "XYMSRV=\"0.0.0.0\"" >/var/run/xymonclient-runtime.cfg
echo "XYMSERVERS=\"$XYMONSERVERS\"" >>/var/run/xymonclient-runtime.cfg
fi
if [ "$CLIENTHOSTNAME" != "" ]; then
DMNOPTS="${DMNOPTS} --hostname=${CLIENTHOSTNAME}"
fi
if [ "$CLIENTOS" != "" ]; then
DMNOPTS="${DMNOPTS} --os=${CLIENTOS}"
fi
set -e
case "$CMD" in
start)
echo -n "Starting $DESC: "
su -c "$DAEMON $DMNOPTS start" - xymon
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
su -c "$DAEMON stop" - xymon ### is
## su -c "$DAEMON $DMNOPTS stop" - xymon # ## should be this!!!
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
su -c "$DAEMON stop" - xymon
su -c "$DAEMON $DMNOPTS start" - xymon
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart}" >&2
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
exit 0