Skip to content

Instantly share code, notes, and snippets.

@jozefcipa
Last active January 30, 2018 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jozefcipa/78a68bcd0e837baaed71c0ce6b0268f6 to your computer and use it in GitHub Desktop.
Save jozefcipa/78a68bcd0e837baaed71c0ce6b0268f6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Process watcher
# Watches for processes if they run, if not, launch them again
# chmod +x /path/to/your/project/watcher.sh
# crontab -e
# * * * * * /path/to/your/project/watcher.sh # Schedules watcher to run every minute
# Define program to run
queue() {
cd /path/to/your/project && php artisan queue:work & echo $! > /tmp/my_queue.pid
}
# If file not exists launch program (for the first time)
if [ ! -f /tmp/my_queue.pid ]
then
queue;
fi
# Check if process with given ID (/tmp/my_queue.pid) is running
# If not, launch again
if [ ! -d /proc/$(</tmp/my_queue.pid) ]
then
queue; # launch script
now=`date`; # Store current date
echo "$now - relaunching" >> /path/to/your/project/watcher.log # Log date of re-run
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment