Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: unicorn
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Manage unicorn server
  9. # Description: Start, stop, restart unicorn server for a specific application.
  10. ### END INIT INFO
  11. set -e
  12.  
  13. # Feel free to change any of the following variables for your app:
  14. TIMEOUT=${TIMEOUT-60}
  15. #APP_ROOT=/home/deploy/apps/transpes/current
  16. APP_ROOT=/var/www/webroot/public
  17. PATH=$PATH:/usr/local/rvm/gems/ruby-2.1.0/bin/
  18. export PATH
  19. PID=$APP_ROOT/tmp/pids/unicorn.pid
  20. CMD="cd $APP_ROOT; /usr/local/rvm/gems/ruby-2.1.0/bin/bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
  21. AS_USER=root
  22. set -u
  23.  
  24. OLD_PIN="$PID.oldbin"
  25.  
  26. sig () {
  27. test -s "$PID" && kill -$1 `cat $PID`
  28. }
  29.  
  30. oldsig () {
  31. test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
  32. }
  33.  
  34. run () {
  35. if [ "$(id -un)" = "$AS_USER" ]; then
  36. eval $1
  37. else
  38. su -c "$1" - $AS_USER
  39. fi
  40. }
  41.  
  42. case "$1" in
  43. start)
  44. sig 0 && echo >&2 "Already running" && exit 0
  45. run "$CMD"
  46. ;;
  47. stop)
  48. sig QUIT && exit 0
  49. echo >&2 "Not running"
  50. ;;
  51. force-stop)
  52. sig TERM && exit 0
  53. echo >&2 "Not running"
  54. ;;
  55. restart|reload)
  56. sig HUP && echo reloaded OK && exit 0
  57. echo >&2 "Couldn't reload, starting '$CMD' instead"
  58. run "$CMD"
  59. ;;
  60. upgrade)
  61. if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
  62. then
  63. n=$TIMEOUT
  64. while test -s $OLD_PIN && test $n -ge 0
  65. do
  66. printf '.' && sleep 1 && n=$(( $n - 1 ))
  67. done
  68. echo
  69.  
  70. if test $n -lt 0 && test -s $OLD_PIN
  71. then
  72. echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
  73. exit 1
  74. fi
  75. exit 0
  76. fi
  77. echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  78. run "$CMD"
  79. ;;
  80. reopen-logs)
  81. sig USR1
  82. ;;
  83. *)
  84. echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
  85. exit 1
  86. ;;
  87. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement