Dalius's blog

Sunday, March 16, 2025

Kamal & Cron

My requirement was to have cron task running once a day, but Kamal documentation was not helpful enough. I have even created Github issue for that https://github.com/basecamp/kamal/issues/1388 and later figured out that there are more assumptions actually made in documentation.

What I have found out that Alpine actually has cron installed, but executable is named crond. In result it meant that I only need to use proper executable:

  cron:
    hosts:
      - 195.201.143.78
    cmd: sh -c "(env && cat crontab) | crontab - && crond -f"

You can even test you cron configuration. All you need to do is to run shell, e.g. (skaityta is my project name, so use your own):

docker exec -it skaityta sh

Then you can check what is inside cron then for example:

/app # crontab -l
NODE_VERSION=22.13.1
HOSTNAME=7c7c4ccd2a7f
YARN_VERSION=1.22.22
SHLVL=2
HOME=/root
DATA_PATH=/data
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/app
0 9 * * * /usr/local/bin/node /app/retrieve.js
* * * * * /usr/local/bin/node -e 'console.log(new Date().toString())'