Help with supercronic - process exits, machine shuts down

I’m trying to run supercronic. I followed Crontab with Supercronic · Fly Docs to add supercronic to the dockerfile etc.

Running supercronic /path/to/crontab exits immediately, and the machine shuts down. If I try to restart it, it shuts down again.

I tried adding a every-minute cronjob to see if the machine would magically restart itself, but it does not.

  1. Is the supercronic process supposed to exit 0? If not, what other settings do I need to keep it alive?
  2. What do I need to do to keep a specific process’ machine which is not http_service alive at all times?

Some debug info

2024-01-23T22:12:30Z app[91857e72a96448] sea [info] INFO Preparing to run: `/rails/bin/docker-entrypoint bundle exec whenever > crontab && supercronic crontab` as 1000
2024-01-23T22:12:30Z app[91857e72a96448] sea [info] INFO [fly api proxy] listening at /.fly/api
2024-01-23T22:12:30Z app[91857e72a96448] sea [info]2024/01/23 22:12:30 listening on [fdaa:4:e9ed:a7b:124:8244:dd91:2]:22 (DNS: [fdaa::3]:53)
2024-01-23T22:12:31Z app[91857e72a96448] sea [info]0 0 * * * /bin/bash -l -c 'cd /rails && RAILS_ENV=production bundle exec rake update_genome --silent'
2024-01-23T22:12:31Z app[91857e72a96448] sea [info]0 0 * * * /bin/bash -l -c 'cd /rails && RAILS_ENV=production bundle exec rake db_dump --silent'
2024-01-23T22:12:31Z app[91857e72a96448] sea [info]* * * * * /bin/bash -l -c 'echo '\''Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing '\'''
2024-01-23T22:12:31Z app[91857e72a96448] sea [info]## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
2024-01-23T22:12:31Z app[91857e72a96448] sea [info]## [message] Run `whenever --help' for more options.
2024-01-23T22:12:31Z app[91857e72a96448] sea [info] INFO Main child exited normally with code: 0
2024-01-23T22:12:31Z app[91857e72a96448] sea [info] INFO Starting clean up.
2024-01-23T22:12:31Z app[91857e72a96448] sea [info] WARN hallpass exited, pid: 306, status: signal: 15 (SIGTERM)

fly.toml

app = "frdm-pr-preview" # will be overwritten
primary_region = "sea"
swap_size_mb = 1024
console_command = "/rails/bin/rails console"

[build]

[deploy]
  release_command = "./bin/rails db:migrate"

[processes]
  app = "./bin/rails server"
  cron = "bundle exec whenever > crontab && supercronic crontab"

[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = false
  auto_start_machines = true
  min_machines_running = 1
  processes = ["app"]

[[vm]]
  cpu_kind = "shared"
  cpus = 1
  memory_mb = 256
  processes = ["app", "sidekiq", "cron"]

[[statics]]
  guest_path = "/rails/public"
  url_prefix = "/"

[env]
  SECRET_KEY_BASE = "..."

Ah, seems like the issue is with the process. This:

cron = "bundle exec whenever > crontab && supercronic -debug crontab && while true; do sleep 1; done"

Gets concatted into one huge command:

fly m status -d 5683d5d1b31628  -a frdm-pr-cron-test-13
# ...
Command       = ["bundle","exec","whenever","\u003e","crontab","\u0026\u0026","supercronic","-debug","crontab","\u0026\u0026","while","true;","do","sleep","1;","done"]  

Found out after adding the -debug flag for supercronic; it got picked up by whenever instead:

2024-01-23T23:40:46Z app[5683d5d1b31628] sea [info]bundler: failed to load command: whenever (/rails/vendor/bundle/ruby/3.2.0/bin/whenever)
2024-01-23T23:40:46Z app[5683d5d1b31628] sea [info]/rails/vendor/bundle/ruby/3.2.0/gems/whenever-1.0.0/bin/whenever:42:in `<top (required)>': invalid option: -debug (OptionParser::InvalidOption)

While you can work around this by making your command of the form bash -C "...", generally it is better to make a small script, place it in your application’s bin directory, make the script executable and have the command run that script.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.