The Slackware Linux distribution (http://www.slackware.com/) uses a simpler startup script system. Here's an example of a script to start and stop the Zabbix server and agent daemon on Slackware systems. This script is dependant on bash, but it shouldn't be too hard to rewrite for sh compatibility, if so desired. Create script /etc/rc.d/rc.zabbix
with the following content:
#!/bin/bash # Init script to start/stop Zabbix server and agent daemon BINLOCATION=/usr/local/sbin AGENTPID=/var/tmp/zabbix_agentd.pid SERVERPID=/var/tmp/zabbix_server.pid TERMINATEWAIT=5 processcheck() { [[ "$(ps -C $1 -o pid=)" ]] || return 1 } # Check for stray pidfiles and remove them processcheck zabbix_agentd || { [ -f $AGENTPID ] && ( echo "Removing stray $AGENTPID file"; rm $AGENTPID ) } processcheck zabbix_server || { [ -f $SERVERPID ] && ( echo "Removing stray $SERVERPID file"; rm $SERVERPID ) } killprocess() { processcheck $2 || { echo "No process $2 running" Slackwarescript, creatingreturn } if [ -f $1 ]; then kill -15 $(cat $1) else echo "pidfile $1 not found" processcheck $2 && killall -15 $2 fi echo -n "Waiting for $2 to terminate" for i in $(seq 1 $TERMINATEWAIT); do processcheck $2 || break sleep 1 echo -n "." done processcheck $2 && echo "Warning! $2 did not terminate in $TERMINATEWAIT seconds" } zagent_start() { if [ -x $BINLOCATION/zabbix_agentd ]; then if processcheck zabbix_agentd; then echo "Zabbix agent daemon already running" else echo "Starting zabbix agent daemon: $BINLOCATION/zabbix_agentd" $BINLOCATION/zabbix_agentd fi else echo "Executable $BINLOCATION/zabbix_agentd not present" fi } zserver_start() { if [ -x $BINLOCATION/zabbix_server ]; then if processcheck zabbix_server; then echo "Zabbix server already running" else echo "Starting zabbix server: $BINLOCATION/zabbix_server" $BINLOCATION/zabbix_server fi else echo "Executable $BINLOCATION/zabbix_server not present" fi } zagent_stop() { Slackwarescript, creatingecho "Stopping Zabbix agent daemon" killprocess $AGENTPID zabbix_agentd } zserver_stop() { echo "Stopping zabbix server" killprocess $SERVERPID zabbix_server } zagent_restart() { zagent_stop zagent_start } zserver_restart() { zserver_stop zserver_start } case "$1" in 'start') case "$2" in 'agent') zagent_start ;; 'server') zserver_start ;; *) zagent_start zserver_start ;; esac ;; 'stop') case "$2" in 'agent') zagent_stop ;; 'server') zserver_stop ;; *) zagent_stop zserver_stop ;; esac ;; 'restart') case "$2" in 'agent') zagent_restart Slackwarescript, creating;; 'server') zserver_restart ;; *) zagent_restart zserver_restart ;; esac ;; *) echo "Usage: $0 start|stop|restart [agent|server]" ;; esac
This script combines agent and server controlling. To start both, execute the following as root:
# /etc/rc.d/rc.zabbix start
To control the server or agent only, pass its name as a second argument. For example:
# /etc/rc.d/rc.zabbix restart server
Adding a script to the system's startup sequence is quite trivial. It's invocation has to be added to the /etc/rc.d/rc.local
as follows:
# echo /etc/rc.d/rc.zabbix start >> /etc/rc.d/rc.local
While the init script method is a nice way to check a service's state for some distributions, it's not available everywhere and isn't always enough. Sometimes you might want to check whether the Zabbix server or agent is running with other methods.
Checking running processes:
The most common method to check whether a particular process is running is by looking at running processes. You can verify if Zabbix agent daemon processes are actually running by using the following:
$ ps -C zabbix_agentd
Sometimes, an agent daemon might start up, but fail to bind to the port, or the port might be used by some other process. You can verify whether some other process is listening on the Zabbix port, or whether Zabbix agent daemon is listening on the correct port by issuing:
$ netstat -ntpl
Note that process names won't be printed for other users' processes unless you are root. In the output, look for a line looking similar to:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 19843/zabbix_agentd
This indicates that the process zabbix_agentd is running and listening on all addresses, on port 10050, just what we need.
Telnetting to the port
Even when a service starts up and successfully binds to a port, there might be some connectivity issues; perhaps due to a local firewall. To quickly check connectivity to the desired port, you can try:
$ telnet localhost 10050
This command should open a connection to the Zabbix agent daemon, and the daemon should not close the connection immediately.