improved cron tasks output and force authentication

This commit is contained in:
Eduardo Silva
2026-02-09 13:09:30 -03:00
parent 05b9644cd3
commit 6c37beece0
9 changed files with 79 additions and 33 deletions

View File

@@ -1,15 +1,12 @@
FROM ubuntu:latest
# Instalar cron
RUN apt-get update && apt-get install -y cron curl
RUN apt-get update && apt-get install -y cron curl && rm -rf /var/lib/apt/lists/*
# Adicionar seus scripts de cron
# Adicionar apenas o entrypoint script, as tasks serão geradas lá
COPY entrypoint.sh /entrypoint.sh
COPY cron_runner.sh /cron_runner.sh
RUN chmod +x /entrypoint.sh
RUN chmod +x /cron_runner.sh
# Criar um arquivo de log para armazenar os resultados do cron
RUN touch /var/log/cron.log
# Executar o entrypoint
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -0,0 +1,11 @@
#!/bin/bash
set -e
[ -z "$1" ] && exit 1
ENDPOINT="$1"
CRON_KEY="$(cat /app_secrets/cron_key)"
URL="http://wireguard-webadmin:8000/api/cron/${ENDPOINT}/?cron_key=${CRON_KEY}"
BODY="$(/usr/bin/curl -sS "$URL" 2>&1 || true)"
echo "[$(date -Is)] ${ENDPOINT} -> ${BODY}"

View File

@@ -16,32 +16,28 @@ echo "Starting cron with WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL=$WIREGUARD_STAT
# Create cron tasks
cat <<EOF > /etc/cron.d/cron_tasks
*/15 * * * * root sleep 20 ; /usr/bin/curl -s http://wireguard-webadmin:8000/api/cron_check_updates/ >> /var/log/cron.log 2>&1
*/10 * * * * root sleep 15 ; /usr/bin/curl -s http://wireguard-webadmin:8000/api/cron_update_peer_latest_handshake/ >> /var/log/cron.log 2>&1
* * * * * root sleep 10 ; /usr/bin/curl -s http://wireguard-webadmin:8000/api/cron_peer_scheduler/ >> /var/log/cron.log 2>&1
* * * * * root sleep 30 ; /usr/bin/curl -s http://wireguard-webadmin:8000/api/cron_calculate_peer_schedules/ >> /var/log/cron.log 2>&1
*/15 * * * * root sleep 20 ; /cron_runner.sh check_updates >> /var/log/cron.log 2>&1
*/10 * * * * root sleep 15 ; /cron_runner.sh update_peer_latest_handshake >> /var/log/cron.log 2>&1
* * * * * root sleep 10 ; /cron_runner.sh peer_scheduler >> /var/log/cron.log 2>&1
* * * * * root sleep 30 ; /cron_runner.sh calculate_peer_schedules >> /var/log/cron.log 2>&1
EOF
CMD="/usr/bin/curl -s http://wireguard-webadmin:8000/api/cron_refresh_wireguard_status_cache/ >> /var/log/cron.log 2>&1"
CMD="echo -n cron_refresh_wireguard_status_cache ; /cron_runner.sh refresh_wireguard_status_cache >> /var/log/cron.log 2>&1"
if [ "$WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL" -eq 30 ]; then
echo "* * * * * root $CMD" >> /etc/cron.d/cron_tasks
echo "* * * * * root sleep 30; $CMD" >> /etc/cron.d/cron_tasks
echo "* * * * * root $CMD" >> /etc/cron.d/cron_tasks
echo "* * * * * root sleep 30 ; $CMD" >> /etc/cron.d/cron_tasks
elif [ "$WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL" -eq 60 ]; then
echo "* * * * * root $CMD" >> /etc/cron.d/cron_tasks
echo "* * * * * root $CMD" >> /etc/cron.d/cron_tasks
elif [ "$WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL" -eq 150 ]; then
echo "*/5 * * * * root $CMD" >> /etc/cron.d/cron_tasks
echo "*/5 * * * * root sleep 150; $CMD" >> /etc/cron.d/cron_tasks
echo "*/5 * * * * root $CMD" >> /etc/cron.d/cron_tasks
echo "*/5 * * * * root sleep 150 ; $CMD" >> /etc/cron.d/cron_tasks
elif [ "$WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL" -eq 300 ]; then
echo "*/5 * * * * root $CMD" >> /etc/cron.d/cron_tasks
echo "*/5 * * * * root $CMD" >> /etc/cron.d/cron_tasks
fi
# Permissions
chmod 0644 /etc/cron.d/cron_tasks
# crontab /etc/cron.d/cron_tasks
# Touch log file
touch /var/log/cron.log
# Execute cron
exec cron -f
echo > /var/log/cron.log
cron
tail -n 0 -F /var/log/cron.log