Skip to content

Instantly share code, notes, and snippets.

@jozefcipa
Last active January 30, 2018 15:13
Show Gist options
  • Select an option

  • Save jozefcipa/78a68bcd0e837baaed71c0ce6b0268f6 to your computer and use it in GitHub Desktop.

Select an option

Save jozefcipa/78a68bcd0e837baaed71c0ce6b0268f6 to your computer and use it in GitHub Desktop.

Revisions

  1. jozefcipa revised this gist Jan 30, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion watcher.sh
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ queue() {
    # If file not exists launch program (for the first time)
    if [ ! -f /tmp/my_queue.pid ]
    then
    cmd1;
    queue;
    fi


  2. jozefcipa revised this gist Jan 30, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion watcher.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@

    # Define program to run
    queue() {
    cd /path/to/your/project && nohup php artisan queue:work & echo $! > /tmp/my_queue.pid
    cd /path/to/your/project && php artisan queue:work & echo $! > /tmp/my_queue.pid
    }

    # If file not exists launch program (for the first time)
  3. jozefcipa revised this gist Jan 30, 2018. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions watcher.sh
    Original file line number Diff line number Diff line change
    @@ -8,22 +8,22 @@
    # * * * * * /path/to/your/project/watcher.sh # Schedules watcher to run every minute

    # Define program to run
    cmd1() {
    your_command_here & echo $! > /tmp/cmd1.pid
    queue() {
    cd /path/to/your/project && nohup php artisan queue:work & echo $! > /tmp/my_queue.pid
    }

    # If file not exists launch program (for the first time)
    if [ ! -f /tmp/cmd1.pid ]
    if [ ! -f /tmp/my_queue.pid ]
    then
    cmd1;
    fi


    # Check if process with given ID (/tmp/cmd1.pid) is running
    # Check if process with given ID (/tmp/my_queue.pid) is running
    # If not, launch again
    if [ ! -d /proc/$(</tmp/cmd1.pid) ]
    if [ ! -d /proc/$(</tmp/my_queue.pid) ]
    then
    cmd1; # launch script
    queue; # launch script

    now=`date`; # Store current date
    echo "$now - relaunching" >> /path/to/your/project/watcher.log # Log date of re-run
  4. jozefcipa created this gist Jan 30, 2018.
    30 changes: 30 additions & 0 deletions watcher.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/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
    cmd1() {
    your_command_here & echo $! > /tmp/cmd1.pid
    }

    # If file not exists launch program (for the first time)
    if [ ! -f /tmp/cmd1.pid ]
    then
    cmd1;
    fi


    # Check if process with given ID (/tmp/cmd1.pid) is running
    # If not, launch again
    if [ ! -d /proc/$(</tmp/cmd1.pid) ]
    then
    cmd1; # launch script

    now=`date`; # Store current date
    echo "$now - relaunching" >> /path/to/your/project/watcher.log # Log date of re-run
    fi