Every morning my database connected to my droplet wakes up asleep, I need to enter the droplet console and run pm2 restart 0, how do I stop it from sleeping
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Heya @robertomedinack,
It’s possible something is killing your proccess. You can try using the metrics agent that DigitalOcean offers to see the exact reason behind this:
https://docs.digitalocean.com/products/monitoring/how-to/install-agent/
Another alternative would be to check your Droplet’s logs and see if it says about killing proccesses.
Other Solutions might be
Check Application Logs
/var/log/
or specific to your application) to see if there are any errors or warnings before it crashes or becomes unresponsive.Keep the Application Alive with
pm2
pm2
has a built-in feature to automatically restart an application if it crashes. Ensure your process is being monitored correctly bypm2
:--watch
flag ensures thatpm2
will watch your files and restart the process if any file changes. This might help if your application is crashing or going to sleep due to file changes or other issues.4. Configure
pm2
to Restart on Failurepm2
is set up to restart your application on failure:Hi there,
This is quite interesting as the Droplets do not have that concept of sleeping like some serverless platforms.
Your droplet might be running out of memory or CPU, causing the database to be terminated or put into a killed state by the operating system. What I could suggest here is to check your resource usage with commands like
top
,htop
, orfree -m
.And also check the DigitalOcean monitoring graphs to see if this is indeed the case:
If this is indeed the case, you might want to upgrade your Droplet to add some extra RAM and CPU power:
Alternatively, you could also add a SWAP file to have some extra memory buffer:
As a temporary workaround, what you could do is to create a simple cron job that could run every morning to restart the database service:
Let me know how it goes!
- Bobby