Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides: Click-AP
  5. # Required-Start: $all
  6. # Required-Stop: $all
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Resque worker via init.d (assumes you have Ruby, and a plugin to allow wildcards in queue names)
  10. # Description: starts YAKITORI-Queue using start-stop-daemon
  11. ### END INIT INFO
  12.  
  13. PROG="rake"
  14. NICE_NAME="resque"
  15. PROG_DIR="/opt/rubies/ruby-1.9.3-p547/bin"
  16. USER="root"
  17. PATH=/opt/yakitori/:/opt/rubies/ruby-1.9.3-p547/bin:/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
  18. QUEUE=videos,encodings,notifications
  19. PROG_PATH="/opt/yakitori/"
  20. PID_PATH="/opt/yakitori/log"
  21.  
  22. RAILS_ENV="production"
  23.  
  24. capitalize_first () {
  25. string0="$@"
  26. firstchar=${string0:0:1}
  27. string1=${string0:1}
  28. FirstChar=`echo "$firstchar" | tr a-z A-Z`
  29. echo "$FirstChar$string1"
  30. }
  31.  
  32. toUpper() {
  33. echo $1 | tr "[:lower:]" "[:upper:]"
  34. }
  35.  
  36. #PROG_ARGS="environment resque:work QUEUE='*'"
  37. PROG_ARGS="resque:work QUEUE='videos,encodings,notifications'"
  38. PID_FILE="$PID_PATH/$NICE_NAME.pid"
  39.  
  40. start() {
  41. if [ -e "$PID_FILE" ]; then
  42. echo "Error! Resque worker is currently running, or the pid file in $PID_PATH is stale!" 1>&2
  43. exit 1
  44. else
  45. su $USER -c "cd $PROG_PATH && $PROG_DIR/$PROG $PROG_ARGS 2>&1 > $PROG_PATH/log/workers.log &" &
  46.  
  47. echo "Starting up resque worker"
  48.  
  49. while [[ $WORKER_PID == "" ]]
  50. do
  51. WORKER_PID=`ps -ef | grep "Waiting for" | grep -v grep | awk '{ print $2 }'`
  52. echo -n "."
  53. sleep 3
  54. done
  55.  
  56. echo $WORKER_PID > "$PID_FILE"
  57. echo ""
  58. echo "Resque worker started with PID=$WORKER_PID."
  59. fi
  60. }
  61.  
  62. stop() {
  63. if [ -e "$PID_FILE" ]; then
  64. echo "PID_FILE ---> $PID_FILE"
  65. pid=`cat "$PID_FILE"`
  66. echo "PID ---> $pid"
  67. kill $pid > /dev/null 2>&1 # not using -9 so as not to have output
  68. sleep 3 # I should really check if the PID is still up here...
  69. rm "$PID_FILE"
  70.  
  71. echo "Resque worker stopped, brah!"
  72. else
  73. echo "Error! Resque worker is not running! C'mon, brah!" 1>&2
  74. exit 1
  75. fi
  76. }
  77.  
  78. if [ "$(id -u)" != "0" ]; then
  79. echo "This script must be run as root, brah!" 1>&2
  80. exit 1
  81. fi
  82.  
  83. case "$1" in
  84. start)
  85. start
  86. exit 0
  87. ;;
  88. stop)
  89. stop
  90. exit 0
  91. ;;
  92. reload|restart|force-reload)
  93. stop
  94. start
  95. exit 0
  96. ;;
  97. **)
  98. echo "Usage: $0 {start|stop|reload}" 1>&2
  99. exit 1
  100. ;;
  101. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement