Search code examples
vagranthomesteadsupervisord

Provision Supervisor worker on Homestead


I am trying to provision a supervisor work via after.sh but for some reason, I keep getting a bunch of permission errors. Anyone have any ideas how I might resolve these?

after.sh

# Add the laravel service to supervisor
if [ ! -f /etc/supervisor/conf.d/laravel-worker.conf ]; then

  laravel_worker_block="[program:term-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/vagrant/laravel/artisan queue:work sqs-term --sleep=3 --tries=3
autostart=true
autorestart=true
user=vagrant
numprocs=8
redirect_stderr=true
stdout_logfile=/home/vagrant/laravel/term-worker.log

[program:default-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/vagrant/laravel/artisan queue:work sqs-default --sleep=3 --tries=3
autostart=true
autorestart=true
user=vagrant
numprocs=8
redirect_stderr=true
stdout_logfile=/home/vagrant/laravel/default-worker.log"

  echo "$laravel_worker_block" > "/etc/supervisor/conf.d/laravel-worker.conf"
  supervisorctl reread
  supervisorctl update

fi

ERRORS

==> default: /tmp/vagrant-shell: 38: /tmp/vagrant-shell: cannot create /etc/supervisor/conf.d/laravel-worker.conf: Permission denied
==> default: error: <class 'socket.error'>, [Errno 13] Permission denied: file: /usr/lib/python2.7/socket.py line: 228
==> default: error: <class 'socket.error'>, [Errno 13] Permission denied: file: /usr/lib/python2.7/socket.py line: 228

Solution

  • I was able to fix it with some sudo additions.

    # Add the laravel service to supervisord
    if sudo [ ! -f /etc/supervisor/conf.d/laravel-worker.conf ]; then
    
      laravel_worker_block="[program:term-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /home/vagrant/laravel/artisan queue:work sqs-term --sleep=3 --tries=3
    autostart=true
    autorestart=true
    user=vagrant
    numprocs=8
    redirect_stderr=true
    stdout_logfile=/home/vagrant/laravel/term-worker.log
    
    [program:default-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /home/vagrant/laravel/artisan queue:work sqs-default --sleep=3 --tries=3
    autostart=true
    autorestart=true
    user=vagrant
    numprocs=8
    redirect_stderr=true
    stdout_logfile=/home/vagrant/laravel/default-worker.log"
    
      sudo sh -c "echo '$laravel_worker_block' > '/etc/supervisor/conf.d/laravel-worker.conf'"
      sudo supervisorctl reread
      sudo supervisorctl update
    
    fi