Guest User

Untitled

a guest
Dec 11th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: APPLICATION
  4. # Required-Start: $all
  5. # Required-Stop: $network $local_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Start the APPLICATION unicorns at boot
  9. # Description: Enable APPLICATION at boot time.
  10. ### END INIT INFO
  11. #
  12. # Use this as a basis for your own Unicorn init script.
  13. # Change APPLICATION to match your app.
  14. # Make sure that all paths are correct.
  15.  
  16. set -u
  17. set -e
  18.  
  19. # Change these to match your app:
  20. USER=USER
  21. APP_NAME=APPLICATION
  22. RVM_STRING=1.9.2@$APP_NAME
  23. APP_ROOT="/srv/$APP_NAME/current"
  24. PID="/srv/$APP_NAME/shared/pids/$APP_NAME.pid"
  25. ENV=production
  26.  
  27. # assumes multi-user RVM installation
  28. GEM_HOME="/usr/local/rvm/gems/$RVM_STRING/"
  29.  
  30. UNICORN_OPTS="-D -E $ENV -c $APP_ROOT/config/unicorn.rb"
  31.  
  32. SET_PATH="cd $APP_ROOT; rvm use $RVM_STRING; export GEM_HOME=$GEM_HOME"
  33. CMD="$SET_PATH; $GEM_HOME/bin/unicorn $UNICORN_OPTS"
  34.  
  35. old_pid="$PID.oldbin"
  36.  
  37. cd $APP_ROOT || exit 1
  38.  
  39. sig () {
  40. test -s "$PID" && kill -$1 `cat $PID`
  41. }
  42.  
  43. oldsig () {
  44. test -s $old_pid && kill -$1 `cat $old_pid`
  45. }
  46.  
  47. case ${1-help} in
  48. start)
  49. sig 0 && echo >&2 "Already running" && exit 0
  50. su - $USER -c "$CMD"
  51. ;;
  52. stop)
  53. sig QUIT && exit 0
  54. echo >&2 "Not running"
  55. ;;
  56. force-stop)
  57. sig TERM && exit 0
  58. echo >&2 "Not running"
  59. ;;
  60. restart|reload)
  61. sig HUP && echo reloaded OK && exit 0
  62. echo >&2 "Couldn't reload, starting '$CMD' instead"
  63. su - $USER -c "$CMD"
  64. ;;
  65. upgrade)
  66. sig USR2 && exit 0
  67. echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  68. su - $USER -c "$CMD"
  69. ;;
  70. rotate)
  71. sig USR1 && echo rotated logs OK && exit 0
  72. echo >&2 "Couldn't rotate logs" && exit 1
  73. ;;
  74. *)
  75. echo >&2 "Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
  76. exit 1
  77. ;;
  78. esac
Add Comment
Please, Sign In to add comment