-
Notifications
You must be signed in to change notification settings - Fork 1
/
initd-script-prototype
executable file
·57 lines (45 loc) · 1.3 KB
/
initd-script-prototype
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
#!/bin/sh
# Executable war file
WAR_FILE=/var/apps/<my-war-file>.war
# Configuration files
APP_NAME=<app-name>
JETTY_CONFIG=/etc/${APP_NAME}-jetty.properties
APP_CONFIG=/etc/${APP_NAME}-app.properties
LOGBACK_CONFIG=/etc/${APP_NAME}-logback.properties
# Process
PIDFILE=/var/run/${APP_NAME}.pid
# Java arguments
JAVA_ARGS="-Djetty.configurationFile=${JETTY_CONFIG} -Dapp.configurationFile=${APP_CONFIG} -Dlogback.configurationFile=${LOGBACK_CONFIG}"
# Command
CMD=$1
if [[ -z ${CMD} ]]; then
java ${JAVA_ARGS} -jar ${WAR_FILE} usage
exit 1
fi
if [[ ${CMD} == 'start' ]]; then
if [[ -f ${PIDFILE} ]]; then
echo "Already running"
exit 1
fi
if [[ -f ${WAR_FILE} ]]; then
echo "Starting jetty: ${WAR_FILE}"
java ${JAVA_ARGS} -jar ${WAR_FILE} start &
PID=$!
echo "$PID" > ${PIDFILE}
echo "Started ${APP_NAME} with pid: ${PID}"
fi
elif [[ ${CMD} == 'stop' ]]; then
# Try gracefully first
java ${JAVA_ARGS} -jar ${WAR_FILE} stop
sleep 10
if [[ -f ${PIDFILE} ]]; then
PID=`cat ${PIDFILE}`
test -z $PID || kill $PID
rm ${PIDFILE}
sleep 1
echo "Forcibly Stopped ${WAR_FILE} with pid: ${PID}"
fi
else # Just let the other cmds through...
java ${JAVA_ARGS} -jar ${WAR_FILE} ${CMD}
fi
exit 0