Last active
January 30, 2018 15:13
-
-
Save jozefcipa/78a68bcd0e837baaed71c0ce6b0268f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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