Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Queue manager script, to make sure the required number of worker instances
  4. # are running. Schedule this in cron to make sure any crashed workers will
  5. # be restarted.
  6. #
  7.  
  8. # Get the full path to ourselfs
  9. SCRIPTPATH="$( dirname "$( which "$0" )" )"
  10.  
  11. # how many workers do we need to start?
  12. if [ $# -gt 0 ]; then
  13. WORKERS=$1
  14. else
  15. WORKERS=1;
  16. fi
  17.  
  18. # where does the php binary live?
  19. PHP=`which php`
  20.  
  21. # command that starts the worker
  22. COMMAND="$SCRIPTPATH/../../../oil refine queueworker"
  23.  
  24. # loop to process the worker instantiation
  25. while :
  26. do
  27. # bail out if we have started enough workers
  28. PROCESS_COUNT=`pgrep -f "$COMMAND" | wc -l`
  29. if [ $PROCESS_COUNT -eq $WORKERS ]; then
  30. exit 0
  31. fi
  32.  
  33. # too many workers running?
  34. if [ $PROCESS_COUNT -gt $WORKERS ]; then
  35. # kill a worker off nicely
  36. PROCESS=`pgrep -f -n "$COMMAND"`
  37. kill -15 $PROCESS
  38. sleep 1
  39. else
  40. # start a new worker
  41. $PHP $COMMAND &
  42. fi
  43. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement