Automate the upgrade of your DigitalOcean droplets

Recently DigitalOcean released new pricing plans where they basically doubled the RAM for the same price of the old plans. But to get the benefits for your existing droplets, you have to upgrade all of your existing droplets in a process that involves shutting them down, selecting the new plan, waiting for the upgrade to happen and power on the droplets again. I have tens of droplets and had no intention of doing this manually, so I wrote a script to use the DigitalOcean API to automate a mass-upgrade of all droplets.

You need to have the PHP package manager Composer installed.

Then all you need to do is:

    1. Install the script by running
      composer create-project bjornjohansen/do-upgrade-plans
    2. Get your Personal Access Token with read and write access, which you can generate on the Applications & API page.
    3. Copy your access token and set it as an environment variable:
      export DO_ACCESS_TOKEN=<YOUR_64_CHAR_TOKEN_HERE>
    4. Run the script:
      php -f do-upgrade-plans/do-upgrade-plans.php
    5. Watch your droplets get upgraded.

In case an error happens, your droplets will power cycle, to make sure they are in a running state. This happened to 3 of my ~60 droplets. Further investigation (trying to upgrade manually) revealed that “Due to high demand and capacity restrictions we have temporarily disabled this size in this region.” – so oh, well, guess I’ll upgrade those droplets later.

If you want to inspect the script or make a Pull Requst, it is available on GitHub.

Please note that some downtime is expected. The script is something I pulled together on an evening to serve my need, it is quite crude: it works fine if you have tens of droplets like I do. If you have hundreds of droplets, or a high availability setup behind a load balancer, you will want to customize the script somewhat. The longest downtime I had, was 5 minutes and 3 seconds, but YMMV.

There is one comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.