Full Stack Laravel Bytes Tutorial Supervisor not working

OK, here’s the “official” way to to run cron / queues in this new set.

Note: I started from a fresh application, and ran fly launch (using the latest flyctl) to ensure I got the newest setup. That creates files .dockerignore, files in docker, Dockerfile and fly.toml.

After that was up and running, I added the following based on the processes docs.

Here’s the whole fly.toml:

app = "red-sea-8756"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  [build.args]
    NODE_VERSION = "14"
    PHP_VERSION = "8.1"

[env]
  APP_ENV = "production"
  LOG_CHANNEL = "stderr"
  LOG_LEVEL = "info"
  LOG_STDERR_FORMATTER = "Monolog\\Formatter\\JsonFormatter"

###
# THIS IS A NEW SECTION AND IS THE ONLY CHANGE
##
[processes]
  app = ""
  worker = "php artisan queue:work"
  cron = "cron -f"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]    # THIS IS HERE BY DEFAULT, JUST NOTE IT IS HERE
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

The addition of the processes groups there sets the CMD that’s passed to the container’s ENTRYPOINT script. That’s why the app group is an empty string. We don’t need to pass a custom command to it!

The other 2 (queue and cron) are separate processes that run what you’d expect - a queue worker instance, and the cron daemon (which is pre-configured to run artisan schedule:run).

What You Might Not Like

You end up with 3 vm’s (one per process defined):

Running a single container instead:

If you want everything running within one container, you can do that manually by editing /creating some files.

It involves adding directories and a run shell script in /etc/services.d.

For example, create directories:

  • /etc/services.d/cron
  • /etc/services.d/queue

And then within each, create a run executable script like this:

For queue:

#!/usr/bin/with-contenv bash

su webuser

/usr/bin/php /var/www/html artisan queue:work

For cron:

#!/usr/bin/with-contenv bash

cron -f

You can create these new files in the docker directory, and then edit your Dockerfile to move those files to the correct location in the resulting image after they are copied into the Docker image via COPY . /var/www/html (which already will be in the Dockerfile near line 19)

Let me know if you run into trouble.

1 Like