replaced /etc/environment with /etc/cron-env.sh to work with cron

This commit is contained in:
2025-10-22 19:10:04 +02:00
parent 4e21b1372f
commit 5546d5511e
3 changed files with 39 additions and 19 deletions

View File

@@ -1,2 +1,5 @@
0 8 * * * root /opt/app/run-task.sh --today
*/15 * * * * root /opt/app/run-task.sh
SHELL=/bin/bash
MAILTO=""
0 8 * * * root . /etc/cron-env.sh && /opt/app/run-task.sh --today >> /proc/1/fd/1 2>&1
*/15 * * * * root . /etc/cron-env.sh && /opt/app/run-task.sh >> /proc/1/fd/1 2>&1
* * * * * root echo "cron test ran at $(date)" >> /proc/1/fd/1 2>&1

View File

@@ -1,15 +1,33 @@
#!/bin/bash
bun run ./src/app.ts --today
echo "ntfy_on=$ntfy_on" >> /etc/environment
echo "ntfy_username=$ntfy_username" >> /etc/environment
echo "ntfy_password=$ntfy_password" >> /etc/environment
echo "ntfy_host=$ntfy_host" >> /etc/environment
echo "ntfy_topic=$ntfy_topic" >> /etc/environment
echo "dc_on=$dc_on" >> /etc/environment
echo "dc_webhook=$dc_webhook" >> /etc/environment
echo "dc_botname=$dc_botname" >> /etc/environment
echo "dc_avatar_url=$dc_avatar_url" >> /etc/environment
# Create or overwrite the cron env file
cat /dev/null > /etc/cron-env.sh
chmod 600 /etc/cron-env.sh
chmod +x /etc/cron-env.sh
# Write the Env Vars into a file for cron. happens during runtime of the container and not build.
# List your environment variables here
env_vars=(
ntfy_on
ntfy_username
ntfy_password
ntfy_host
ntfy_topic
dc_on
dc_webhook
dc_botname
dc_avatar_url
)
for var in "${env_vars[@]}"; do
val="${!var}"
if [ -n "$val" ]; then
# Safely export the variable with proper quoting
printf 'export %s=%q\n' "$var" "$val" >> /etc/cron-env.sh
fi
done
export PATH="/root/.bun/bin:$PATH"
bun run /opt/app/src/app.ts --today
# Start cron in foreground
exec cron -f