Guest User

Untitled

a guest
May 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 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. usage() {
  14. echo "Usage: $0 {rails_env} {start|stop|force-stop|restart|force-reload|reload|upgrade|commit|rollback|reopen-logs|status|inc|dec}" >&2
  15. }
  16.  
  17. RAILS_ENV=$1
  18. APP_ROOT=/var/www/$RAILS_ENV/current
  19. PIDFILE=$APP_ROOT/tmp/pids/unicorn.pid
  20. UNICORN_CONFIG=$APP_ROOT/config/unicorn/$RAILS_ENV.rb
  21. UNICORN_UID=deployer
  22. UNICORN_GID=deployer
  23. UNICORN_PROCESS_NAME=unicorn_rails
  24.  
  25. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  26. DAEMON=/usr/local/rvm/gems/ree-1.8.7-2010.02/bin/$UNICORN_PROCESS_NAME
  27. DAEMON_OPTS="-D -E $RAILS_ENV -c $UNICORN_CONFIG"
  28. NAME=unicorn
  29. DESC=unicorn
  30.  
  31. test -x $DAEMON || exit 0
  32.  
  33. # Include unicorn defaults if available
  34. if [ -f /etc/default/unicorn ] ; then
  35. . /etc/default/unicorn
  36. fi
  37.  
  38. if [ -z $RAILS_ENV ] ; then
  39. usage && exit 1
  40. fi
  41.  
  42. set -e
  43.  
  44. . /lib/lsb/init-functions
  45.  
  46. sig() {
  47. test -s "$2" && kill -s $1 `cat $2`
  48. }
  49.  
  50. start() {
  51. start-stop-daemon --start --quiet \
  52. --chdir $APP_ROOT \
  53. --chuid $UNICORN_UID:$UNICORN_GID \
  54. --exec $DAEMON -- $DAEMON_OPTS || true
  55. }
  56.  
  57. case "$2" in
  58. start)
  59. echo -n "Starting $DESC: "
  60. sig 0 $PIDFILE || start
  61. echo "$NAME."
  62. ;;
  63. stop)
  64. echo -n "Stopping $DESC: "
  65. sig QUIT $PIDFILE || true
  66. echo "$NAME."
  67. ;;
  68. force-stop)
  69. echo -n "Force stopping $DESC: "
  70. sig TERM $PIDFILE || true
  71. echo "$NAME."
  72. ;;
  73. restart|force-reload)
  74. echo -n "Restarting $DESC: "
  75. sig 0 $PIDFILE || ( start && echo "$NAME." && exit 0 )
  76. sig USR2 $PIDFILE && sleep 4 && sig QUIT $PIDFILE.oldbin && \
  77. echo -n "restarted "
  78. echo "$NAME."
  79. ;;
  80. reload)
  81. echo -n "Reloading $DESC configuration: "
  82. sig HUP $PIDFILE || echo -n "not running "
  83. echo "$NAME."
  84. ;;
  85. upgrade)
  86. echo -n "Upgrading $DESC: "
  87. sig USR2 $PIDFILE && sleep 4 && sig WINCH $PIDFILE.oldbin && \
  88. echo -n "check app, then commit or rollback "
  89. echo "$NAME."
  90. ;;
  91. commit)
  92. echo -n "Commit $DESC to new master: "
  93. sig 0 $PIDFILE || ( echo "no new master found" && exit 0 )
  94. sig QUIT $PIDFILE.oldbin || echo -n "no previous master found "
  95. echo "$NAME."
  96. ;;
  97. rollback)
  98. echo -n "Rollback $DESC to previous master: "
  99. sig 0 $PIDFILE.oldbin || ( echo "no previous master found" && exit 0 )
  100. sig HUP $PIDFILE.oldbin && sig QUIT $PIDFILE || true
  101. echo "$NAME."
  102. ;;
  103. reopen-logs)
  104. echo -n "Reopen $DESC logs: "
  105. sig USR1 $PIDFILE || true
  106. echo "$NAME."
  107. ;;
  108. status)
  109. status_of_proc -p $PIDFILE "$DAEMON" $NAME && exit 0 || exit $?
  110. ;;
  111. inc)
  112. echo -n "Increment $DESC workers by one: "
  113. sig TTIN $PIDFILE || echo -n "not running "
  114. echo "$NAME."
  115. ;;
  116. dec)
  117. echo -n "Decrement $DESC workers by one: "
  118. sig TTOU $PIDFILE || echo -n "not running "
  119. echo "$NAME."
  120. ;;
  121. *)
  122. usage
  123. exit 1
  124. ;;
  125. esac
  126.  
  127. exit 0
Add Comment
Please, Sign In to add comment