Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Queue manager script, to make sure the required number of worker instances
- # are running. Schedule this in cron to make sure any crashed workers will
- # be restarted.
- #
- # Get the full path to ourselfs
- SCRIPTPATH="$( dirname "$( which "$0" )" )"
- # how many workers do we need to start?
- if [ $# -gt 0 ]; then
- WORKERS=$1
- else
- WORKERS=1;
- fi
- # where does the php binary live?
- PHP=`which php`
- # command that starts the worker
- COMMAND="$SCRIPTPATH/../../../oil refine queueworker"
- # loop to process the worker instantiation
- while :
- do
- # bail out if we have started enough workers
- PROCESS_COUNT=`pgrep -f "$COMMAND" | wc -l`
- if [ $PROCESS_COUNT -eq $WORKERS ]; then
- exit 0
- fi
- # too many workers running?
- if [ $PROCESS_COUNT -gt $WORKERS ]; then
- # kill a worker off nicely
- PROCESS=`pgrep -f -n "$COMMAND"`
- kill -15 $PROCESS
- sleep 1
- else
- # start a new worker
- $PHP $COMMAND &
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement