forked from j62/ctbrec
1
0
Fork 0

Change the linux server start script to be more like an init script

This commit is contained in:
0xboobface 2020-01-02 15:13:02 +01:00
parent d7eccbf648
commit 5164512287
2 changed files with 69 additions and 4 deletions

1
server/.gitignore vendored
View File

@ -6,3 +6,4 @@
/ctbrec-tunnel.sh
/jre/
/server-local.sh
ctbrec.pid

View File

@ -1,7 +1,71 @@
#!/bin/bash
pushd $(dirname $0)
DIR="$(dirname "$0")"
PIDFILE="${DIR}/ctbrec.pid"
JAVA=java
terminate_ctbrec() {
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 -Xmx192m -cp ${name.final}.jar -Dctbrec.config=server.json ctbrec.recorder.server.HttpServer
popd
$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