Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.57 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides:          unicorn
  5. # Required-Start:    $all
  6. # Required-Stop:     $all
  7. # Default-Start:     2 3 4 5
  8. # Default-Stop:      0 1 6
  9. # Short-Description: starts the unicorn app server
  10. # Description:       starts unicorn using start-stop-daemon
  11. ### END INIT INFO
  12.  
  13. set -e
  14.  
  15. USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
  16.  
  17. # app settings
  18. USER="prios"
  19. APP_NAME="consul"
  20. APP_ROOT="/home/$USER/$APP_NAME"
  21. ENV="production"
  22.  
  23. # environment settings
  24. PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH"
  25. GEM_PATH="/home/$USER/.rbenv/shims"
  26. CMD="cd $APP_ROOT && $GEM_PATH/bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
  27. PID="$APP_ROOT/shared/pids/unicorn.pid"
  28. OLD_PID="$PID.oldbin"
  29.  
  30. # make sure the app exists
  31. cd $APP_ROOT || exit 1
  32.  
  33. sig () {
  34.   test -s "$PID" && kill -$1 `cat $PID`
  35. }
  36.  
  37. oldsig () {
  38.   test -s $OLD_PID && kill -$1 `cat $OLD_PID`
  39. }
  40.  
  41. case $1 in
  42.   start)
  43.     sig 0 && echo >&2 "Already running" && exit 0
  44.     echo "Starting $APP_NAME"
  45.     su - $USER -c "$CMD"
  46.     ;;
  47.   stop)
  48.     echo "Stopping $APP_NAME"
  49.     sig QUIT && exit 0
  50.     echo >&2 "Not running"
  51.     ;;
  52.   force-stop)
  53.     echo "Force stopping $APP_NAME"
  54.     sig TERM && exit 0
  55.     echo >&2 "Not running"
  56.     ;;
  57.   restart|reload|upgrade)
  58.     sig USR2 && echo "reloaded $APP_NAME" && exit 0
  59.     echo >&2 "Couldn't reload, starting '$CMD' instead"
  60.     $CMD
  61.     ;;
  62.   rotate)
  63.     sig USR1 && echo rotated logs OK && exit 0
  64.     echo >&2 "Couldn't rotate logs" && exit 1
  65.     ;;
  66.   *)
  67.     echo >&2 $USAGE
  68.     exit 1
  69.     ;;
  70. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement