replaced the old Crontab with commands with a script to execute instead. Better logging for docker logs <container name>.

because cron does not execute script with env vars, they get dumped into a file and set for the runtime of the  script run-taks.sh
This commit is contained in:
2025-10-22 16:28:25 +02:00
parent 96e9e79aeb
commit f9a1919d08
2 changed files with 29 additions and 2 deletions

View File

@@ -1,2 +1,2 @@
8 * * * * bun run ./src/app.ts --today > /var/log/cron.log 2>&1 0 8 * * * root /opt/app/run-task.sh --today
*/15 * * * * bun run ./src/app.ts > /var/log/cron.log 2>&1 */15 * * * * root /opt/app/run-task.sh

27
run-task.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
set -e
set -o allexport
. /etc/environment || echo "[WARN] Failed to load env" >> /proc/1/fd/2
set +o allexport
export PATH="/root/.bun/bin:$PATH"
cd /opt/app
log_info() {
echo "[INFO] $(date) $1" >> /proc/1/fd/1
}
log_error() {
echo "[ERROR] $(date) $1" >> /proc/1/fd/2
}
log_info "Starting task with args: $*"
if bun run ./src/app.ts "$@" >> /proc/1/fd/1 2>> /proc/1/fd/2; then
log_info "Task completed successfully."
else
log_error "Task failed!"
exit 1
fi