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!
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
, or free -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:
https://docs.digitalocean.com/products/droplets/how-to/resize/
Alternatively, you could also add a SWAP file to have some extra memory buffer:
https://www.digitalocean.com/community/tutorial-collections/how-to-add-swap-space
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:
0 6 * * * pm2 restart 0
Let me know how it goes!
- Bobby
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
/var/log/
or specific to your application) to see if there are any errors or warnings before it crashes or becomes unresponsive.pm2
pm2
has a built-in feature to automatically restart an application if it crashes. Ensure your process is being monitored correctly by pm2
:pm2 start your_app.js --name "your-app" --watch
--watch
flag ensures that pm2
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.pm2
to Restart on Failurepm2
is set up to restart your application on failure:pm2 start your_app.js --name "your-app" --restart-delay 10000 --max-restarts 10
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.