1

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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282

1 Answers1

1

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.

Brett Holman
  • 743
  • 6
  • 18
  • Runcmd might help whenever Server boots up. But how abt just before it shuts down or about to reboot? My purpose is to have an event driven way to notify a centralised place the power State changes of a server. – Kim Stacks May 26 '22 at 00:23
  • Do you care about notifications during unexpected state changes (when the kernel crashes, during a Digital Ocean outage, etc)? You probably won't get your notifications in these scenarios regardless of whether you go with option 1, 2, or 3. – Brett Holman May 26 '22 at 03:48
  • Im okay not to care about unexpected notifications. No choice. – Kim Stacks May 26 '22 at 06:17
  • Gotcha, updated my answer. Also, you could poll from an external server which handles both scenarios I suggested, but then you have a monitoring server to monitor ;) All is fun with distributed systems. – Brett Holman May 26 '22 at 17:44
  • Kim Stacks: If this answers your question ([looks like it does](https://stackoverflow.com/questions/72385724/how-to-use-cloud-init-to-setup-a-bash-script-to-be-triggered-by-systemd-whenever)), don't forget to accept this answer as the solution :) – Brett Holman May 31 '22 at 14:33
  • 1
    Right sorry so just for future readers what worked for me was to use runcmd to create bash scripts and configure systemd to get what I want. Thank you Brett. I cannot use cloud knit alone to achieve what I want – Kim Stacks Jun 01 '22 at 03:13
  • Kim: No worries at all, I'm glad this helped. – Brett Holman Jun 01 '22 at 17:45