Job Control/background process (using ampersand) in .ebextensions config commands

amazon-web-servicesbackground-processelastic-beanstalk

Take for example the following .config file in .ebextensions/

container_commands: 
  000_run_queue_daemon: 
    command: "nohup php artisan queue:work --daemon &"
    test: "ps -ef | grep artisan | grep -v grep > /dev/null || echo 1"

If the daemon is not already running, start a queue worker. The queue worker daemon runs forever (by design) and therefore needs to be run as a background process.

The ampersand seems to have no effect and tailing cfn-init.log just halts at

2014-09-15 00:24:53,921 [DEBUG] Running test for command 000_run_queue_daemon
2014-09-15 00:24:53,929 [DEBUG] Test command output: 1

2014-09-15 00:24:53,929 [DEBUG] Test for command 000_run_queue_daemon passed

This then stays as such until the EB process times out and it gives up with the deployment.

How can I make this run as a background process?

Best Answer

In order to make this work I had to run the command from a file using the post deployment hooks

commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_workers.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      nohup php /var/app/current/artisan queue:work --daemon >/dev/null 2>&1 &