Advertisement
ctbrec

ctbrec linux server init script

Jan 2nd, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DIR="$(dirname "$0")"
  4. PIDFILE="${DIR}/ctbrec.pid"
  5. JAVA=java
  6.  
  7. terminate_ctbrec() {
  8.     echo "Caught SIGTERM signal"
  9.     kill -15 $(cat "${PIDFILE}")
  10. }
  11.  
  12. start() {
  13.     trap terminate_ctbrec SIGTERM
  14.     trap terminate_ctbrec SIGINT
  15.  
  16.     USERDIR="$(pwd)"
  17.     cd "${DIR}"
  18.  
  19.     # start ctbrec
  20.     $JAVA -version
  21.     $JAVA -Xmx256m -cp "${DIR}/ctbrec-server-3.0.3-final.jar" -Dctbrec.config=server.json ctbrec.recorder.server.HttpServer &
  22.  
  23.     # write a pid file
  24.     echo $! > "${PIDFILE}"
  25.  
  26.     # wait for the process to terminate and delete the PID file
  27.     wait $(cat "${PIDFILE}")
  28.     rm "${PIDFILE}"
  29.  
  30.     cd "${USERDIR}"
  31. }
  32.  
  33. stop() {
  34.     if [ -e "${PIDFILE}" ]; then
  35.         PID=$(cat "${PIDFILE}")
  36.         echo "Sending TERM signal"
  37.         kill $PID
  38.         echo -n "Waiting for ctbrec to terminate..."
  39.         tail --pid=$PID -f /dev/null
  40.         echo "done"
  41.         if [ -e "${PIDFILE}" ]; then
  42.             rm "${PIDFILE}"
  43.         fi
  44.     else
  45.         echo "PID file not found"
  46.     fi
  47. }
  48.  
  49. status() {
  50.     if [ -e "${PIDFILE}" ]; then
  51.         echo "running"
  52.     else
  53.         echo "stopped"
  54.     fi
  55. }
  56.  
  57. case "$1" in
  58. start)
  59.     start &
  60.     ;;
  61. stop)
  62.     stop
  63.     ;;
  64. status)
  65.     status
  66.     ;;
  67. *)
  68.     echo "Usage: $0 {start|stop|status}"
  69.     exit 1
  70.     ;;
  71. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement