The 3 AM Job That Never Ran: Taming Sleep Mode on a Free Server
Description and use
Sleep mode on a free server stops a 3 AM cron job. The fix is to ping a lightweight Flask endpoint every few minutes to keep the server awake and trigger the job once per day.
Problem
A cron job scheduled at 3 AM on a free server stopped running because the server entered sleep mode after an hour of inactivity.
Outcome
By keeping the server awake with periodic HTTP requests and using a wake‑endpoint that triggers the job only once per day, the 3 AM cron job reliably executes on a free server that otherwise sleeps.
Workflow
- 1. Verify cron syntax and timezone. 2. Check system logs for sleep events. 3. Deploy a lightweight Flask app exposing a /wake endpoint. 4. Configure an external cron service (e.g., cron‑job.org) to send a GET request to /wake every 5 minutes. 5. In the Flask app, set a flag when /wake is hit. 6. Run a background thread that checks the flag, and if the current hour is 3 AM and the job hasn’t run today, execute the job. 7. Add a simple file lock to prevent concurrent executions. 8. Test by stopping the Flask app, restarting, and sending a wake request. 9. Monitor logs to confirm single execution per day.
Evidence
The system logs revealed the truth: the server had entered a sleep state after roughly an hour of inactivity.
The solution is to keep the server awake by sending periodic HTTP requests from an external service.
- Record date: 2026-09-07T01:37:39.966Z