Search code examples
phplaravelredislaravel-artisansupervisord

Can't run artisan redis:subscribe command as service, in background and daemon


I'm trying to run redis:subscribe artisan command as a service, in background mode and need that script not to die on error.

I have tried Supervisor, but no result.

Do you have any suggestions?


  • OS: CentOS 7
  • Lang: PHP
  • Framework: Laravel

Solution

  • I think I found best solution for this.

    I've made bash file, that is running my script. It's checking for error and restarting script execution. And I've put this bash file in startup, to run as server.

    This is my whole magic:

    #!/bin/bash
    
    while true; do
    
    nohup path/to/php /path/to/artisan redis:subscribe >> /path/to/logs/redis.log &
    
    PID=$!
    wait $PID
    echo $PID has ended
    
    sleep 1;
    done;
    

    I hope someone will find it helpful.