I wrote simple script to check status of a service and when service is down search live processes for the service and kill them, then remove pid file and restart service.

The problem is that the script is not always able to remove the pid file which results in that the script is not able to restart the service.

This is the script:

echo $(date +%d/%m/%Y-%H:%M)
service zabbix-java-gateway restart
sleep 1
service zabbix-java-gateway status > /tmp/status_zabbix_java_gateway
if grep  "is running..." /tmp/status_zabbix_java_gateway
    echo "zabbix-java-gateway is runnign on $HOSTNAME"
    echo " "
rm -rf /tmp/status_zabbix_java_gateway
echo "zabbix-java-gateway is stopped on $HOSTNAME"
echo " "
output=`ps aux|grep zabbix_java`
set -- $output
kill $pid
sleep 2
kill -9 $pid >/dev/null 2>&1
sleep 2
rm -rf /var/run/zabbix/zabbix_java.pid
echo "zabbix-java-gateway is stopped on $HOSTNAME!!!" > /tmp/mail_zabbix_java_gateway
mail -s "Zabbix Java Gateway is down on !!!" [email protected] < /tmp/mail_zabbix_java_gateway
/etc/init.d/zabbix-java-gateway restart
rm -rf /tmp/mail_zabbix_java_gateway
rm -rf /tmp/status_zabbix_java_gateway

Please give me some advice.

1 Answer 1


First, you should probably just use the startup.sh script that comes with Zabbix. Second, why do you need such a check at all? If the gateway is not running properly, you should resolve the underlying problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .