Report this

What is the reason for this report?

How to stop and start droplets at particular time

Posted on January 3, 2022

We have a use case where we need to keep the droplet running for a time period i.e. 8 am to 5 pm. The droplet should be stopped out of these working hours.

Currently we are doing manually. Is there any way to automate this?



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.

Hi @speedo1947,

I’ll suggest giving the DigitalOcean API a look:

https://docs.digitalocean.com/reference/api/api-reference/

You can use the following CURL Post request:

curl -X POST -H "Content-Type: application/json" \
             -H "Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582" \
             -d '{"type":"power_off"}'  \ 
             "https://api.digitalocean.com/v2/droplets/3164450/actions" 

Just remember to replace b7d03a6947b217efb6f3ec3bd3504582 with your own API token and 3164450 with your Droplet’s ID.

Ofcourse, when you want to start the droplet, replace power_off with power_on.

Hi there,

In addition to what has already been mentioned, here are a few examples of how to use the DigitalOcean API with different types of programming languages:

https://www.digitalocean.com/community/questions/how-to-reboot-a-droplet-with-digitalocean-api-php-python-bash-examples

The example is with a reboot, but you can change this to power_off and power_on accordingly.

Best, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.