Files
youlegames/codes/agent/game-docker/docker/cronjob/entrypoint.sh
2026-04-10 16:44:13 +08:00

26 lines
989 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# cronjob 容器入口:注入环境变量到 crontab启动 crond
# 安装 curl仅首次后续重启容器时已安装则跳过
command -v curl > /dev/null 2>&1 || apk add --no-cache curl > /dev/null 2>&1
# 确保脚本有执行权限Windows 开发环境挂载的文件可能缺少 +x
chmod +x /app/daily-task.sh 2>/dev/null
# 将当前环境变量导出到文件,供 cron 任务使用cron 不会继承容器环境变量)
# 排除特殊变量,导出所有业务相关配置
env | grep -v -E '^(HOME|PATH|HOSTNAME|SHLVL|PWD|_)=' > /etc/environment 2>/dev/null
# 读取调度表达式,默认凌晨 4:00
CRON_SCHEDULE="${CRON_SCHEDULE:-0 4 * * *}"
# 生成 crontab
echo "${CRON_SCHEDULE} . /etc/environment; /app/daily-task.sh >> /proc/1/fd/1 2>&1" > /etc/crontabs/root
echo "[cronjob] schedule: ${CRON_SCHEDULE}"
echo "[cronjob] target: ${DLWEB_INTERNAL_URL:-http://dlweb}"
echo "[cronjob] starting crond..."
# 前台运行 crond
crond -f -l 2