queue-worker 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:
  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: Start daemon at boot time
  9. # Description: Enable service provided by daemon.
  10. ### END INIT INFO
  11. dir="/www/wwwroot/proxypanel"
  12. cmd="php artisan queue:work redis --daemon --queue=default --timeout=60 --tries=3 -vvv"
  13. user="www-data"
  14. name=`basename $0`
  15. pid_file="/var/run/$name.pid"
  16. #stdout_log="/var/log/$name.log"
  17. #stderr_log="/var/log/$name.err"
  18. stdout_log="/proc/self/fd/1"
  19. stderr_log="/proc/self/fd/2"
  20. get_pid() {
  21. cat "$pid_file"
  22. }
  23. is_running() {
  24. [ -f "$pid_file" ] && ps -p `get_pid` > /dev/null 2>&1
  25. }
  26. case "$1" in
  27. start)
  28. if is_running; then
  29. echo "Already started"
  30. else
  31. echo "Starting $name"
  32. cd "$dir"
  33. if [ -z "$user" ]; then
  34. sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
  35. else
  36. sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
  37. fi
  38. echo $! > "$pid_file"
  39. if ! is_running; then
  40. echo "Unable to start, see $stdout_log and $stderr_log"
  41. exit 1
  42. fi
  43. fi
  44. ;;
  45. stop)
  46. if is_running; then
  47. echo -n "Stopping $name.."
  48. kill `get_pid`
  49. for i in 1 2 3 4 5 6 7 8 9 10
  50. # for i in `seq 10`
  51. do
  52. if ! is_running; then
  53. break
  54. fi
  55. echo -n "."
  56. sleep 1
  57. done
  58. echo
  59. if is_running; then
  60. echo "Not stopped; may still be shutting down or shutdown may have failed"
  61. exit 1
  62. else
  63. echo "Stopped"
  64. if [ -f "$pid_file" ]; then
  65. rm "$pid_file"
  66. fi
  67. fi
  68. else
  69. echo "Not running"
  70. fi
  71. ;;
  72. restart)
  73. $0 stop
  74. if is_running; then
  75. echo "Unable to stop, will not attempt to start"
  76. exit 1
  77. fi
  78. $0 start
  79. ;;
  80. status)
  81. if is_running; then
  82. echo "Running"
  83. else
  84. echo "Stopped"
  85. exit 1
  86. fi
  87. ;;
  88. *)
  89. echo "Usage: $0 {start|stop|restart|status}"
  90. exit 1
  91. ;;
  92. esac
  93. exit 0