forked from stealthly/minotaur
/
service-control.erb
115 lines (100 loc) · 3.17 KB
/
service-control.erb
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
108
109
110
111
112
113
114
115
#!/bin/sh
# Setup basic path information.
MAIN="<%= @java_class %>"
LOG_OUT="<%= File.join(@log_dir,"kafka.out") %>"
LOG_ERR="<%= File.join(@log_dir,"kafka.err") %>"
HOME_DIR="<%= @install_dir %>"
JAVA_HOME="<%= @java_home %>"
SERVER_CONFIG="<%= @install_dir %>/config/server.properties"
# Setup classpath, initially empty.
CLASSPATH=""
for file in $HOME_DIR/core/target/scala-${SCALA_VERSION}/*.jar;
do
CLASSPATH=$CLASSPATH:$file
done
for file in $HOME_DIR/perf/target/scala-${SCALA_VERSION}/kafka*.jar;
do
CLASSPATH=$CLASSPATH:$file
done
# classpath addition for release
for file in $HOME_DIR/libs/*.jar;
do
CLASSPATH=$CLASSPATH:$file
done
for file in $HOME_DIR/kafka*.jar;
do
CLASSPATH=$CLASSPATH:$file
done
# Add the JMX options.
if [ -z "$JMX_OPTS"]; then
JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "
fi
# Add the JMX port.
if [ -z "$JMX_PORT" ]; then
JMX_PORT="<%=@java_jmx_port%>"
fi
# Add JMX options and port together.
JMX_OPTS="$JMX_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT "
if [ -z "$KAFKA_OPTS" ]; then
KAFKA_OPTS="-Xms512m -Xmx1024M -server -Djava.net.preferIPv4Stack=true -Dlog4j.configuration=file:$HOME_DIR/config/log4j.properties"
fi
# JVM performance options
if [ -z "$KAFKA_JVM_PERFORMANCE_OPTS" ]; then
KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true"
fi
if [ -z "$JAVA_HOME" ]; then
JAVA="java"
else
JAVA="$JAVA_HOME/bin/java"
fi
# Create the JSVC command line.
CMD="$JAVA $KAFKA_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $JMX_OPTS -cp $CLASSPATH"
# Find current PID if any.
FOUND_PID=`ps -ef |grep $MAIN |grep -v grep |awk '{print $2}'`
# Check what the caller wants.
case "$1" in
start)
if [ "" = "$FOUND_PID" ]; then
cd $HOME_DIR
echo $CMD $MAIN $SERVER_CONFIG
# For compatibility with runit we cannot backgroud
# ourselves with a '&' at the end, though we do
# need to exec.
exec $CMD $MAIN $SERVER_CONFIG >>$LOG_OUT 2>>$LOG_ERR
else
echo "Service already running"
exit 1
fi
;;
stop)
if [ "" = "$FOUND_PID" ]; then
echo "Service not running, nothing to stop"
exit 1
else
kill $FOUND_PID
sleep 4
# Find PID again to see if we need to use kill -9 termination.
FOUND_PID=`ps -ef |grep $MAIN |grep -v grep |awk '{print $2}'`
if [ "" != "$FOUND_PID" ]; then
echo "Using kill did not work, sending kill -9 to process"
kill -9 $FOUND_PID
fi
exit 0
fi
;;
status)
# Status is found via actual running processes, rather than
# trusting the PID log file.
if [ "" = "$FOUND_PID" ]; then
echo "Not running"
exit 1
else
echo "Running"
exit 0
fi
;;
*)
echo "usage: daemon {start|stop|status}" >&2
exit 1
;;
esac