Search code examples
digital-oceancloud-init

How to get notified when droplet reboots and when droplet finishes boot?


I found this answer https://stackoverflow.com/a/35456310/80353 and it recommends either API or using user_data which actually is cloud-init underneath.

I can think of several ways to possibly get notified that a server is up:

  1. detect droplet status via API

    I notice that the status never changes during reboot so I guess this is out.

  2. using DigitalOcean native monitoring agent

    The monitoring agent seems to only cover resource utilisation. No alert when the server is being rebooted or finishes booting up

  3. using cloud-init

    This answer https://stackoverflow.com/a/35456310/80353 I mentioned earlier uses wget to send signals out. I can possibly use wget for every time the droplet finishes booting up using bootcmd in cloud-init. But not for reboot.

    There's also the issue of how to ensure the wget request from the right DigitalOcean droplet can correctly identify itself to my server.

Any advice on how to accomplish getting notifications at my server whenever a droplet reboots or finishes booting up?


Solution

  • cloud-init

    bootcmd actually runs every time. Check out the module frequency key in the docs

    Another module you might consider for this is phone home.

    Systemd

    Since the OP is looking for notifications on shutdown/reboot as well, cloud-init is probably not the best for a single solution since it handles boot/init primarily. Assuming systemd:

    This post discusses setting up a service to run on shutdown.

    This post discusses setting up a service to run on startup.