Can't define cron job for periodic container start

I have an app that pulls data from a workflow system, creates a table of qualifying records and sends an email containing the table to a group of people for downstream processing.

The issue is there is no event other than manually going to the URL the app is exposed on to trigger this.

So I thought to create a cron job that runs every 15mins. I have followed this guide (Crontab with Supercronic · Fly Docs) but get an error during fly deploy

==> Verifying app config
Validating C:\Users\tfmei\Documents\Projects\ready2invoice\fly.toml
Service specifies 'app' as one of its processes, but no processes are defined with that name; update fly.toml [processes] to add 'app' process or remove it from service's processes list

   ✘invalid app configuration
Error: App configuration is not valid

Here’s the updated fly.toml that generated the above message

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ['app']

[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1

### Added to include crontab
[processes]
  cron = "supercronic /app/crontab"

[mounts]
  source="storage_dir"
  #destination="/var/www/html/storage"
  destination="/workspace/storage"

While I kind of understand the message I don’t know how to define the app process under [processes]

Hi @camodue, it looks your fly.toml has defined a http service that runs the app process but it is not defined in the [processes] section. You should add the app process to the process group if you want to have both the http service and the cron running simultaneously.

[processes]
  app = "bundle exec rails server -b [::] -p 8080" # or whatever starts your internet facing app 
  cron = "supercronic /app/crontab"

Take a peek at Running Multiple Processes Inside A Fly.io App · Fly Docs for a more in depth guide how to set it up.

Hope this helps!

Ok I have some updates. The invalid app configuration error is gone but I’m not sure that supercronic and curl actually get installed.

Here’s the Dockerfile

FROM node:alpine

WORKDIR /app

COPY package*.json ./

RUN npm install 

COPY . .

EXPOSE 8080 

#CMD ["node", "app.js"]

# Install necessary packages for curl
RUN apk update && apk install -y curl

# Install necessary packages for supercronic
RUN apk add --no-cache curl

# Latest releases available at https://github.com/aptible/supercronic/releases
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64 \
    SUPERCRONIC=supercronic-linux-amd64 \
    SUPERCRONIC_SHA1SUM=cd48d45c4b10f3f0bfdd3a57d054cd05ac96812b

RUN curl -fsSLO "$SUPERCRONIC_URL" \
 && echo "${SUPERCRONIC_SHA1SUM}  ${SUPERCRONIC}" | sha1sum -c - \
 && chmod +x "$SUPERCRONIC" \
 && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
 && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic

# Copy the crontab file
COPY crontab /app/crontab

# Run the app and the cron process
CMD ["sh", "-c", "npm run start & supercronic /app/crontab"]

and the updated fly.toml

# fly.toml app configuration file generated for ready2invoice on 2024-03-14T11:54:26+11:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'ready2invoice'
primary_region = 'syd'

[experimental]

[build]
  builder = "gcr.io/buildpacks/builder"
  args = { target = "x86_64-unknown-linux-musl" }

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ['app']

[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1

### Added to include crontab
[processes]
  app = "npm run start" # command to start the Node.js app
  cron = "supercronic /app/crontab"

[mounts]
  source="storage_dir"
  destination="/workspace/storage"

Partial output from fly deploy

 ✔ [1/2] Machine 91852306f50258 [app] update succeeded
 ✖ [2/2] Machine 6e824271f31558 [cron] update failed: smoke checks for 6e824271f31558 failed: the app appears to be c…
-------
Checking DNS configuration for ready2invoice.fly.dev
Error: smoke checks for 6e824271f31558 failed: the app appears to be crashing
Stacktrace:
goroutine 1 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.21.7/x64/src/runtime/debug/stack.go:24 +0x5e
github.com/superfly/flyctl/internal/cli.printError(0xc0004daaa0, 0xc0013e7b3e, 0x264ba60?, {0x2e8f200, 0xc00111cb40})
        /home/runner/work/flyctl/flyctl/internal/cli/cli.go:162 +0x4db
github.com/superfly/flyctl/internal/cli.Run({0x2eac180?, 0xc000875140?}, 0xc0004daaa0, {0xc000140090?, 0x2, 0x3})
        /home/runner/work/flyctl/flyctl/internal/cli/cli.go:110 +0x928
main.run()
        /home/runner/work/flyctl/flyctl/main.go:47 +0x156
main.main()
        /home/runner/work/flyctl/flyctl/main.go:26 +0x18


C:\Users\tfmei\Documents\Projects\ready2invoice>

Based on the log it can’t find supercronic

   INFO Starting init (commit: 5b8fb02)...
   INFO Preparing to run: `launcher supercronic /app/crontab` as cnb
   INFO [fly api proxy] listening at /.fly/api
  2024/04/09 22:47:38 listening on [fdaa:2:f5a2:a7b:243:abb8:a64a:2]:22 (DNS: [fdaa::3]:53)
  Machine started in 439ms
  supercronic: line 1: supercronic: command not found
   INFO Main child exited normally with code: 127
   INFO Starting clean up.
  machine did not have a restart policy, defaulting to restart

I have followed this guide (Crontab with Supercronic · Fly Docs) for the updates to Dockerfile.

Any further ideas?

Still trying to figure this out. Is there a way to get more info from fly deploy? Or alternatively how can I check the details of the Docket image?

Can you try passing the full path to supercronic in your fly.toml?

[processes]
  app = "npm run start" # command to start the Node.js app
  cron = "/usr/local/bin/supercronic /app/crontab"

Also, you seem to be installing curl twice. You just need apk add curl.

If you want to debug further, one thing you can try is to run a new machine using the latest image (which should be in your fly deploy output) and open up a shell:

fly m run --shell registry.fly.io/app:image-hash
1 Like

Ok txs.

Have updated fly.toml and Dockerfile accordingly and was able to run a new machine via the fly m run... command

I found this command fly ssh console but can’t find /usr/local/bin/supercronic

curl on the command line gives me a command not found error…

Just for completeness this is the updated Dockerfile. I have taken the supercronic details from their GitHub

FROM node:alpine

WORKDIR /app

COPY package*.json ./

# Added --verbose to all RUN commands on 13/4
RUN npm install --verbose

COPY . .

EXPOSE 8080 

#CMD ["node", "app.js"]

# Install necessary packages for curl
#RUN apk update && apk install -y curl --verbose

# Install necessary packages for supercronic
#RUN apk add --no-cache curl --verbose

RUN apk add curl

# Latest releases available at https://github.com/aptible/supercronic/releases
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64 \
    SUPERCRONIC=supercronic-linux-amd64 \
    SUPERCRONIC_SHA1SUM=cd48d45c4b10f3f0bfdd3a57d054cd05ac96812b

RUN curl -fsSLO "$SUPERCRONIC_URL" \
 && echo "${SUPERCRONIC_SHA1SUM}  ${SUPERCRONIC}" | sha1sum -c - \
 && chmod +x "$SUPERCRONIC" \
 && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
 && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic

# Copy the crontab file
COPY crontab /app/crontab

# Run the app and the cron process
CMD ["sh", "-c", "npm run start & supercronic /app/crontab"]

If I build your docker image, I can see supercronic

$ which supercronic
/usr/local/bin/supercronic

Your Dockerfile is not being used because of this section in your fly.toml:

[build]
  builder = "gcr.io/buildpacks/builder"
  args = { target = "x86_64-unknown-linux-musl" }

removing those lines should fix it.

Thank you so much… it finally works

1 Like

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