i had problems when i wanted to restart the zabbix server or agentd
i use the gentoo init.d script
it seems it is because pending tcp sockets are not closed when shutting down the service.
so if the service is restarted immediately, it can't bind the tcp port to listen.
so the started process stop, but doesn't remove the pid file, i had to rm it, killall the forked zabbix processes, wait for the connections to end (netstat -an | grep 10051 for zabbix_server) and then i can make /etc/init.d/zabbix-server start.
to avoid making it by hands i made a script :
usage : ./script.sh server
./script.sh agentd
note : - this script use the init.d scripts to start and stop zabbix, so the zabbix init.d scripts have to be installed
- the config files have to be in /etc/zabbix dir
- i made it for zabbix 1.1 alpha 10 but i think it will work for previous and future versions since config parameter names are not modified
- you have to be root to run the script
here is what the script make :
first if the zabbix service is started, it shut it down
verify that there is no processes remaining, and if there is, killall them
once the service is stopped, it verify that there is no pending connections (with netstat), and wait for the connections to end if there is
it start the init.d zabbix service
and verify that the correct number of processes are running
hope this can be useful for someone
i use the gentoo init.d script
it seems it is because pending tcp sockets are not closed when shutting down the service.
so if the service is restarted immediately, it can't bind the tcp port to listen.
so the started process stop, but doesn't remove the pid file, i had to rm it, killall the forked zabbix processes, wait for the connections to end (netstat -an | grep 10051 for zabbix_server) and then i can make /etc/init.d/zabbix-server start.
to avoid making it by hands i made a script :
Code:
#!/bin/sh
if [ $# = 0 ] ; then
echo usage : $0 server/agentd
exit 1
else
if [ -e /etc/init.d/zabbix-$1 ] ; then
SERV=$1
else
echo erreur : /etc/init.d/zabbix-$1 n\'existe pas
echo vous trouverez les scripts init.d pour zabbix dans le repertoire misc/init.d/ dans le repertoire ou vous avez decompresse l\'archive d\'installation
exit 1
fi
fi
zabstatus()
{
echo `/etc/init.d/zabbix-server status | grep started | wc -l`
}
zabps()
{
TMPRET=`ps alx | grep zabbix_$1 | wc -l`
echo `echo $TMPRET-1 | bc`
}
zabnetstat()
{
PORT=`cat /etc/zabbix/zabbix_$1.conf | grep ListenPort | cut -d = -f 2`
echo `netstat -an | grep $PORT | wc -l`
}
while [ `zabstatus $SERV` -ne 0 ] ; do
echo zabbix-$SERV est demarre, nous allons l\'arreter
/etc/init.d/zabbix-$SERV stop
PIDFILE=`cat /etc/zabbix/zabbix_$SERV.conf | grep PidFile | cut -d = -f 2`
if [ -e $PIDFILE ] ; then
rm $PIDFILE
echo $PIDFILE trouve et efface : OK
fi
while [ `zabps $SERV` -ne 0 ] ; do
killall zabbix_$SERV
echo processus zabbix_$SERV trouves et arretes : OK
done
done
echo le service zabbix-$SERV est arrete : OK
PIDFILE=`cat /etc/zabbix/zabbix_$SERV.conf | grep PidFile | cut -d = -f 2`
if [ -e $PIDFILE ] ; then
rm $PIDFILE
echo $PIDFILE trouve et efface
fi
echo $PIDFILE non present : OK
while [ `zabps $SERV` -ne 0 ] ; do
killall zabbix_$SERV
echo processus zabbix_$SERV trouves et arretes
done
echo pas de processus trouve : OK
while [ `zabnetstat $SERV` -ne 0 ] ; do
echo -n -e "`zabnetstat $SERV` connections encore actives (attente) \r"
sleep 1
done
echo aucune connection active, zabbix_$SERV peut etre demarre : OK
/etc/init.d/zabbix-$SERV start
sleep 1 # sometimes it takes a little time to fork processes
NBRS=`cat /etc/zabbix/zabbix_$SERV.conf | grep Start | cut -d = -f 2 | awk '{total += $1} END {print total}'`
if [ $SERV = "agentd" ] ; then
NBRS=`echo $NBRS + 1 | bc`
fi
if [ `zabps $SERV` -ne $NBRS ] ; then
echo il y a `zabps $SERV` processus de zabbix_$SERV lance alors qu\'il devrait y en avoir $NBRS, est ce normal?
else
echo il y a bien $NBRS processus de zabbix_$SERV lance : OK
fi
./script.sh agentd
note : - this script use the init.d scripts to start and stop zabbix, so the zabbix init.d scripts have to be installed
- the config files have to be in /etc/zabbix dir
- i made it for zabbix 1.1 alpha 10 but i think it will work for previous and future versions since config parameter names are not modified
- you have to be root to run the script
here is what the script make :
first if the zabbix service is started, it shut it down
verify that there is no processes remaining, and if there is, killall them
once the service is stopped, it verify that there is no pending connections (with netstat), and wait for the connections to end if there is
it start the init.d zabbix service
and verify that the correct number of processes are running
hope this can be useful for someone
Comment