I have a Node.js app that pulls data from an API to send emails based on a certain logic. It’s supposed to be an automated process. Since machines stop on fly.io after a while I have a cronjob to restart it regularly.
However the cronjob throws the following error in live logs:
2024-07-21T15:18:00.003 app[6e824271f31558] syd [info] time="2024-07-21T15:18:00Z" level=info msg=starting iteration=66 job.command="./start_app.sh >> cron_log.txt 2>&1" job.position=0 job.schedule="*/2 * * * *"
2024-07-21T15:18:00.004 app[6e824271f31558] syd [info] time="2024-07-21T15:18:00Z" level=error msg="error running command: exit status 127" iteration=66 job.command="./start_app.sh >> cron_log.txt 2>&1" job.position=0 job.schedule="*/2 * * * *"
The app’s working directory is /app (as defined in Dockerfile
) and I have checked the attributes of start_app.sh (–> -rwxr-xr-x 1 root root
).
cron_log.txt
has the following entries
/bin/sh: /app/start_app.sh: not found
Any idea why this is not working?
khuezy
July 21, 2024, 4:14pm
2
According to the error, that file doesn’t exist. fly ssh console
into your app and double check that it’s there.
I have checked and it’s there and executable. Also the log file cron_log.txt
gets created on first execution
Could it be related to the environment? Here’s my ‘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 = "/usr/local/bin/supercronic /app/crontab"
[mounts]
source="storage_dir"
destination="/app/storage"
and the Dockerfile
FROM node:alpine
WORKDIR /app
COPY package*.json ./
# Added --verbose to all RUN commands on 13/4
RUN npm install --verbose
COPY . .
EXPOSE 8080
# Create the storage directory that contains database.db; new on 19/4
RUN mkdir /app/storage
#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"]
khuezy
July 21, 2024, 11:29pm
4
hmmm are you overengineering/complicating things?
The reason why it stops is because:
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
Perhaps you can just use New feature: Scheduled machines
system
Closed
July 28, 2024, 11:29pm
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.