forked from j62/ctbrec
Change the linux server start script to be more like an init script
This commit is contained in:
parent
d7eccbf648
commit
5164512287
|
@ -6,3 +6,4 @@
|
||||||
/ctbrec-tunnel.sh
|
/ctbrec-tunnel.sh
|
||||||
/jre/
|
/jre/
|
||||||
/server-local.sh
|
/server-local.sh
|
||||||
|
ctbrec.pid
|
||||||
|
|
|
@ -1,7 +1,71 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
pushd $(dirname $0)
|
DIR="$(dirname "$0")"
|
||||||
|
PIDFILE="${DIR}/ctbrec.pid"
|
||||||
JAVA=java
|
JAVA=java
|
||||||
$JAVA -version
|
|
||||||
$JAVA -Xmx192m -cp ${name.final}.jar -Dctbrec.config=server.json ctbrec.recorder.server.HttpServer
|
terminate_ctbrec() {
|
||||||
popd
|
echo "Caught SIGTERM signal"
|
||||||
|
kill -15 $(cat "${PIDFILE}")
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
trap terminate_ctbrec SIGTERM
|
||||||
|
trap terminate_ctbrec SIGINT
|
||||||
|
|
||||||
|
USERDIR="$(pwd)"
|
||||||
|
cd "${DIR}"
|
||||||
|
|
||||||
|
# start ctbrec
|
||||||
|
$JAVA -version
|
||||||
|
$JAVA -Xmx256m -cp "${DIR}/${name.final}.jar" -Dctbrec.config=server.json ctbrec.recorder.server.HttpServer &
|
||||||
|
|
||||||
|
# write a pid file
|
||||||
|
echo $! > "${PIDFILE}"
|
||||||
|
|
||||||
|
# wait for the process to terminate and delete the PID file
|
||||||
|
wait $(cat "${PIDFILE}")
|
||||||
|
rm "${PIDFILE}"
|
||||||
|
|
||||||
|
cd "${USERDIR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
if [ -e "${PIDFILE}" ]; then
|
||||||
|
PID=$(cat "${PIDFILE}")
|
||||||
|
echo "Sending TERM signal"
|
||||||
|
kill $PID
|
||||||
|
echo -n "Waiting for ctbrec to terminate..."
|
||||||
|
tail --pid=$PID -f /dev/null
|
||||||
|
echo "done"
|
||||||
|
if [ -e "${PIDFILE}" ]; then
|
||||||
|
rm "${PIDFILE}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "PID file not found"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
status() {
|
||||||
|
if [ -e "${PIDFILE}" ]; then
|
||||||
|
echo "running"
|
||||||
|
else
|
||||||
|
echo "stopped"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
start &
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
status
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|status}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
Loading…
Reference in New Issue