Blame SOURCES/zabbix-java-gateway.init

1c3a77
#! /bin/sh
1c3a77
#
1c3a77
# chkconfig: - 85 15
1c3a77
# description: zabbix java gateway
1c3a77
#
1c3a77
1c3a77
### BEGIN INIT INFO
1c3a77
# Provides: zabbix
1c3a77
# Required-Start: $local_fs $network
1c3a77
# Required-Stop: $local_fs $network
1c3a77
# Default-Start:
1c3a77
# Default-Stop: 0 1 2 3 4 5 6
1c3a77
# Short-Description: start and stop zabbix java gateway
1c3a77
# Description: Zabbix Java Gateway
1c3a77
### END INIT INFO
1c3a77
1c3a77
# Source function library.
1c3a77
. /etc/rc.d/init.d/functions
1c3a77
1c3a77
# Source networking configuration.
1c3a77
. /etc/sysconfig/network
1c3a77
1c3a77
# Source Zabbix Java Gateway configuration
1c3a77
. /etc/zabbix/zabbix_java_gateway.conf
1c3a77
1c3a77
if [ -r "/etc/sysconfig/zabbix-java-gateway" ]; then
1c3a77
    . /etc/sysconfig/zabbix-java-gateway
1c3a77
fi
1c3a77
1c3a77
# Check that networking is up.
1c3a77
[ ${NETWORKING} = "no" ] && exit 0
1c3a77
1c3a77
RETVAL=0
1c3a77
EXECDIR=/usr/sbin/zabbix_java
1c3a77
1c3a77
case "$1" in
1c3a77
    start)
1c3a77
        echo -n "Starting zabbix java gateway: "
1c3a77
        if [ -n "$PID_FILE" -a -e "$PID_FILE" ]; then
1c3a77
            echo "zabbix java gateway is already running"
1c3a77
            exit 1
1c3a77
        fi
1c3a77
1c3a77
        JAVA=${JAVA:-java}
1c3a77
1c3a77
        JAVA_OPTIONS="-server $JAVA_OPTIONS"
1c3a77
        if [ -z "$PID_FILE" ]; then
1c3a77
            JAVA_OPTIONS="$JAVA_OPTIONS -Dlogback.configurationFile=logback-console.xml"
1c3a77
        fi
1c3a77
1c3a77
        cd $EXECDIR
1c3a77
1c3a77
        CLASSPATH="lib"
1c3a77
        for jar in {lib,bin}/*.jar; do
1c3a77
            if [[ $jar != *junit* ]]; then
1c3a77
                CLASSPATH="$CLASSPATH:$jar"
1c3a77
            fi
1c3a77
        done
1c3a77
1c3a77
        if [ -n "$PID_FILE" ]; then
1c3a77
            ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.pidFile=$PID_FILE"
1c3a77
        fi
1c3a77
        if [ -n "$LISTEN_IP" ]; then
1c3a77
            ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.listenIP=$LISTEN_IP"
1c3a77
        fi
1c3a77
        if [ -n "$LISTEN_PORT" ]; then
1c3a77
            ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.listenPort=$LISTEN_PORT"
1c3a77
        fi
1c3a77
        if [ -n "$START_POLLERS" ]; then
1c3a77
            ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.startPollers=$START_POLLERS"
1c3a77
        fi
1c3a77
        if [ -n "$TIMEOUT" ]; then
1c3a77
            ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.timeout=$TIMEOUT"
1c3a77
        fi
1c3a77
1c3a77
        tcp_timeout=${TIMEOUT:=3}000
1c3a77
        ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dsun.rmi.transport.tcp.responseTimeout=$tcp_timeout"
1c3a77
1c3a77
        COMMAND_LINE="$JAVA $JAVA_OPTIONS -classpath $CLASSPATH $ZABBIX_OPTIONS com.zabbix.gateway.JavaGateway"
1c3a77
1c3a77
        if [ -n "$PID_FILE" ]; then
1c3a77
            PID=$(su -s /bin/bash -c "$COMMAND_LINE > /dev/null 2>&1 & echo \$!" zabbix)
1c3a77
            if ps -p $PID > /dev/null 2>&1; then
1c3a77
                echo $PID > $PID_FILE
1c3a77
            else
1c3a77
                echo "zabbix java gateway did not start"
1c3a77
                exit 1
1c3a77
            fi
1c3a77
        else
1c3a77
            exec $COMMAND_LINE
1c3a77
            RETVAL=$?
1c3a77
        fi
1c3a77
        ;;
1c3a77
    stop)
1c3a77
        echo -n "Shutting down zabbix java gateway: "
1c3a77
        if [ -n "$PID_FILE" ]; then
1c3a77
            if [ -e "$PID_FILE" ]; then
1c3a77
                    kill `cat $PID_FILE` && rm $PID_FILE
1c3a77
            else
1c3a77
                echo "zabbix java gateway is not running"
1c3a77
                exit 1
1c3a77
            fi
1c3a77
        else
1c3a77
            echo "zabbix java gateway is not configured as a daemon: variable \$PID_FILE is not set"
1c3a77
            exit 1
1c3a77
        fi
1c3a77
        ;;
1c3a77
    restart)
1c3a77
        $0 stop
1c3a77
        $0 start
1c3a77
        RETVAL=$?
1c3a77
        ;;
1c3a77
    condrestart)
1c3a77
        if [ -n "$PID_FILE" -a -e "$PID_FILE" ]; then
1c3a77
            $0 stop
1c3a77
            $0 start
1c3a77
        fi
1c3a77
        RETVAL=$?
1c3a77
        ;;
1c3a77
    status)
1c3a77
        status -p $PID_FILE $0
1c3a77
        RETVAL=$?
1c3a77
        exit $RETVAL
1c3a77
        ;;
1c3a77
    *)
1c3a77
        echo "Usage: $0 {start|stop|restart|condrestart|status}"
1c3a77
        exit 1
1c3a77
        ;;
1c3a77
esac
1c3a77
1c3a77
[ "$RETVAL" -eq 0 ] && success $"$base startup" || failure $"$base startup"
1c3a77
echo
1c3a77
exit $RETVAL
1c3a77