1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#!/bin/sh
### BEGIN INIT INFO
# Provides: zabbix-java-gateway
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start zabbix-java-gateway daemon
# Description: Control zabbix-java-gateway daemon
### END INIT INFO
NAME=zabbix-java-gateway
DAEMON=/usr/bin/java
# Exit if executable is not installed
[ -x $DAEMON ] || exit 0
DIR=/var/run/zabbix
PID_FILE=$DIR/$NAME.pid
RETRY=TERM/30/KILL/5
#if [ "$(id -u)" -ne 0 ]; then
# echo "Error: root privileges are needed to run $0"
# exit 1
#fi
# Source Zabbix java gateway configuration file
. /etc/zabbix/zabbix_java_gateway.conf
ZABBIX_OPTIONS=""
if [ -n "$PID_FILE" ]; then
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.pidFile=$PID_FILE"
fi
if [ -n "$LISTEN_IP" ]; then
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.listenIP=$LISTEN_IP"
fi
if [ -n "$LISTEN_PORT" ]; then
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.listenPort=$LISTEN_PORT"
fi
if [ -n "$START_POLLERS" ]; then
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.startPollers=$START_POLLERS"
fi
if [ -n "$TIMEOUT" ]; then
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.timeout=$TIMEOUT -Dsun.rmi.transport.tcp.responseTimeout=${TIMEOUT}000"
fi
DAEMON_ARGS="${JAVA_OPTIONS} -server ${ZABBIX_OPTIONS} -Dlogback.configurationFile=/etc/zabbix/zabbix_java_gateway.logback.xml -Djava.library.path=/usr/lib/jni -jar /usr/sbin/zabbix-java-gateway.jar"
#COMMAND_LINE="${DAEMON} $DAEMON_ARGS -classpath $CLASSPATH com.zabbix.gateway.JavaGateway"
# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS
# define LSB log_* functions.
. /lib/lsb/init-functions
_ev_ () {
[ "$VERBOSE" = "no" ] || eval $@
}
[ -d "$DIR" ] || mkdir "$DIR"
chown -R zabbix:zabbix "$DIR"
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
case "$1" in
start)
start-stop-daemon --start --pidfile $PID_FILE --exec $DAEMON --test --quiet > /dev/null
[ $? -ne 0 ] && log_action_msg "$NAME is already running" && exit 0
_ev_ log_action_begin_msg \"$NAME starting\"
R=$(start-stop-daemon --start --background --make-pidfile --user zabbix --group zabbix --chuid zabbix --pidfile $PID_FILE --exec $DAEMON --oknodo -- ${DAEMON_ARGS} 2>&1) \
&& _ev_ log_action_end_msg 0 \"$R\" \
|| _ev_ log_action_end_msg 1 \"$R\"
;;
stop)
_ev_ log_action_begin_msg "$NAME stopping"
R=$(start-stop-daemon --stop --pidfile $PID_FILE --oknodo --retry=$RETRY 2>&1)
if [ $? -ne 0 ]; then
_ev_ log_action_end_msg 1 \"$R\"
else
t=5
while $0 status >/dev/null; do
_ev_ log_action_cont_msg \"[$t]\"
t=$(($t-1))
if [ $t -ne 0 ]; then
sleep 1
continue
else
break
fi
done
$0 status >/dev/null \
&& _ev_ log_action_end_msg 1 \"still running after 5 sec., unable to stop\" \
|| _ev_ log_action_end_msg 0 \"$R\"
fi
;;
status)
## return status 0 if process is running.
status_of_proc -p $PID_FILE "$DAEMON" "$NAME"
;;
restart|force-reload)
$0 stop
$0 status >/dev/null \
&& exit 1 \
|| $0 start
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
|