1 |
jpp |
1.1 |
#!/bin/bash |
2 |
|
|
|
3 |
|
|
if [ -r /etc/zabbix/zabbix_java_gateway.conf ]; then |
4 |
|
|
. /etc/zabbix/zabbix_java_gateway.conf |
5 |
|
|
fi |
6 |
|
|
|
7 |
|
|
if [ -z $GATEWAY_HOME ]; then |
8 |
|
|
GATEWAY_HOME="/usr/share/zabbix-java-gateway" |
9 |
|
|
fi |
10 |
|
|
|
11 |
|
|
if [ -r "/etc/sysconfig/zabbix-java-gateway" ]; then |
12 |
|
|
. /etc/sysconfig/zabbix-java-gateway |
13 |
|
|
fi |
14 |
|
|
|
15 |
|
|
if [ -n "$PID_FILE" -a -f "$PID_FILE" ]; then |
16 |
|
|
PID=`cat "$PID_FILE"` |
17 |
|
|
if ps -p "$PID" > /dev/null 2>&1; then |
18 |
|
|
echo "Zabbix Java Gateway is already running" |
19 |
|
|
exit 1 |
20 |
|
|
fi |
21 |
|
|
rm -f "$PID_FILE" |
22 |
|
|
fi |
23 |
|
|
|
24 |
|
|
JAVA=${JAVA:-java} |
25 |
|
|
JAVA_OPTIONS="-server $JAVA_OPTIONS" |
26 |
|
|
JAVA_OPTIONS="$JAVA_OPTIONS -Dlogback.configurationFile=/etc/zabbix/zabbix_java_gateway_logback.xml" |
27 |
|
|
|
28 |
|
|
cd $GATEWAY_HOME |
29 |
|
|
|
30 |
|
|
CLASSPATH="lib" |
31 |
|
|
for jar in lib/*.jar bin/*.jar; do |
32 |
|
|
CLASSPATH="$CLASSPATH:$jar" |
33 |
|
|
done |
34 |
|
|
|
35 |
|
|
if [ -n "$PID_FILE" ]; then |
36 |
|
|
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.pidFile=$PID_FILE" |
37 |
|
|
fi |
38 |
|
|
if [ -n "$LISTEN_IP" ]; then |
39 |
|
|
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.listenIP=$LISTEN_IP" |
40 |
|
|
fi |
41 |
|
|
if [ -n "$LISTEN_PORT" ]; then |
42 |
|
|
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.listenPort=$LISTEN_PORT" |
43 |
|
|
fi |
44 |
|
|
if [ -n "$START_POLLERS" ]; then |
45 |
|
|
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.startPollers=$START_POLLERS" |
46 |
|
|
fi |
47 |
|
|
if [ -n "$TIMEOUT" ]; then |
48 |
|
|
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.timeout=$TIMEOUT" |
49 |
|
|
fi |
50 |
|
|
|
51 |
|
|
tcp_timeout=${TIMEOUT:=3}000 |
52 |
|
|
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dsun.rmi.transport.tcp.responseTimeout=$tcp_timeout" |
53 |
|
|
|
54 |
|
|
COMMAND_LINE="$JAVA $JAVA_OPTIONS -classpath $CLASSPATH $ZABBIX_OPTIONS com.zabbix.gateway.JavaGateway" |
55 |
|
|
|
56 |
|
|
if [ -n "$PID_FILE" ]; then |
57 |
|
|
|
58 |
|
|
# check that the PID file can be created |
59 |
|
|
|
60 |
|
|
touch "$PID_FILE" |
61 |
|
|
if [ $? -ne 0 ]; then |
62 |
|
|
echo "Zabbix Java Gateway did not start: cannot create PID file" |
63 |
|
|
exit 1 |
64 |
|
|
fi |
65 |
|
|
|
66 |
|
|
# start the gateway and output pretty errors to the console |
67 |
|
|
|
68 |
|
|
STDOUT=`$COMMAND_LINE & echo $! > "$PID_FILE"` |
69 |
|
|
if [ -n "$STDOUT" ]; then |
70 |
|
|
echo "$STDOUT" |
71 |
|
|
fi |
72 |
|
|
|
73 |
|
|
# verify that the gateway started successfully |
74 |
|
|
|
75 |
|
|
PID=`cat "$PID_FILE"` |
76 |
|
|
ps -p "$PID" > /dev/null 2>&1 |
77 |
|
|
if [ $? -ne 0 ]; then |
78 |
|
|
echo "Zabbix Java Gateway did not start" |
79 |
|
|
rm -f "$PID_FILE" |
80 |
|
|
exit 1 |
81 |
|
|
fi |
82 |
|
|
|
83 |
|
|
else |
84 |
|
|
exec $COMMAND_LINE |
85 |
|
|
fi |