# # needs a shebang # # Zabbix agent start/stop script. # # Written by Alexei Vladishev . # Hacked about by Dave Levy # Re-Published at Zabbix Forums 24 Sept 2010 # Ver.1.2 Revised Path statement, revised PID assignment, status # method, LSBB comment block, revised restart method # Ver 1.3 Uses log_*_msg functions # Ver 1.4 Cosmetic changes mainly about PATHs and binary locations ### BEGIN INIT INFO # Provides: zbxagentd # Required-Start: $network $local_fs # Required-Stop: $network $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts and stops zabbix_agentd # Description: starts and stops zabbix_agenta, suports all LSB script methods ### END INIT INFO # As we implement the distro specific display functions we may require . /lib/lsb/init-functions NAME=zabbix_agentd SCRIPTNAME=$0 #PATH=/bin:/usr/bin:/sbin:/usr/sbin:/home/zabbix/bin:/home/zabbix/sbin PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin # maybe put /usr/local/sbin in the path DAEMON=/usr/local/sbin/${NAME} DESC="Zabbix agent daemon" # Ubuntu keeps .pid files in /var/run but Zabbix User can't write there # The conf file is defaulted to /etc/zabbix # This next line is installation specific CONFIG_FILE=/etc/zabbix/${NAME}.conf # PID=/var/tmp/$NAME.pid PID=$( cat ${CONFIG_FILE} | egrep ^PidFile | cut -f2 -d"=" ) # Is there anything else that is needed from the config file. Should we # now pass it to the start stop daemom? # We may also need to know the configured port. test -f $DAEMON || exit 0 # whenever error exit #set -e case "$1" in start) # I am unsure as to which configuration creates the .pid file log_daemon_msg "Starting $DESC: $NAME" start-stop-daemon --oknodo --start --pidfile $PID \ --exec $DAEMON case $? in 0) log_end_msg 0 ;; *) log_end_msg 1 ;; esac ;; stop) log_daemon_msg "Stopping $DESC: $NAME" start-stop-daemon --oknodo --stop --pidfile $PID \ --exec $DAEMON case $? in 0) log_end_msg 0 ;; *) log_end_msg 1 ;; esac ;; restart|force-reload) # # If the "reload" option is implemented, move the "force-reload" # option to the "reload" entry above. If not, "force-reload" is # just the same as "restart". # # echo -n "Restarting $DESC: zabbix_agent" $0 stop sleep 3 $0 start # start-stop-daemon --stop --quiet --pidfile \ # /tmp/$NAME.pid --user zabbix --exec $DAEMON # sleep 1 # start-stop-daemon --start --quiet --pidfile \ # /tmp/$NAME.pid --user zabbix --exec $DAEMON # echo "$NAME." ;; status) HOST=127.0.0.1 log_daemon_msg "Checking Status $DESC: $NAME" # do I want this to be silent or noisy # this requires that zabbix get is in the PATH case $( zabbix_get -s${HOST} -k agent.ping 2> /dev/null ) in 1) log_end_msg 0 ; exit 0 ;; *) log_end_msg 1 ; exit 1 ;; esac ;; *) N=${SCRIPTNAME} # originally assumed that the rc script name = daemon name # echo "Usage: $N {start|stop|restart|force-reload}" >&2 echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 exit 1 ;; esac exit 0