mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-01-17 04:56:18 +00:00
46 lines
1.7 KiB
Bash
Executable File
46 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL=${WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL:-60}
|
|
|
|
case "$WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL" in
|
|
30|60|150|300)
|
|
;;
|
|
*)
|
|
echo "Error: Invalid WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL value: $WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL. Allowed values are 30, 60, 150, 300."
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
echo "Starting cron with WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL=$WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL"
|
|
|
|
# Create cron tasks
|
|
cat <<EOF > /etc/cron.d/cron_tasks
|
|
* * * * * root /usr/bin/curl -s http://wireguard-webadmin:8000/api/cron_check_updates/ >> /var/log/cron.log 2>&1
|
|
*/10 * * * * root /usr/bin/curl -s http://wireguard-webadmin:8000/api/cron_update_peer_latest_handshake/ >> /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"
|
|
|
|
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
|
|
elif [ "$WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL" -eq 60 ]; then
|
|
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
|
|
elif [ "$WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL" -eq 300 ]; then
|
|
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
|