Dynamically scheduling shutdown on Ubuntu Core

Let’s say I have an endpoint which returns a payload with a scheduling. Is there any way I can build a snap that performs reboot and shutdown based on that?

I have already built a snap using the solution suggested by @ogra

and I could setup a systemd timer using this in the snapcraft.yaml command: bin/pwr_mgmt.sh daemon: simple plugs: - shutdown timer: mon-fri,04:00

However, I would like to setup systemd timer from inside the snap after making a call to the endpoint.

i fear there is no way to adjust timers yet (neither via snapctl from within the snap, nor from the outside via the snap command) … you might need to implement your own internal timer setup within the snap (i.e. via some script) …

Gosh! It means I should write myself a scheduler, am I right? Because this is exactly what I was trying to avoid :worried:

well, it would be a simple shell script using something like:

sleep $(( $(date -f - +%s- <<< "tomorrow 21:30"$'\nnow') 0 ))

(you could indeed make it a bit more complex if needed)

I will give it a go. Thanks for the hint. I will let you know when I get to a working and reliable solution.

I have taken a bit before going out with this snap because I didn’t want to publish something that was not fully tested. Now that I have used this scheduler in production environments, I feel comfortable sharing it here as well. Hopefully it might help somebody else https://snapcraft.io/powerscheduler.

Hah, cute !

I wonder if @alexmurray would be willing to grant autoconnect for the shutdown interface for this one … this is normally not lightly granted but with a description starting with:

" Shutdown scheduler for Ubuntu and Ubuntu Core systems."

and this being the only purpose of the snap, it seems to make a lot of sense …

Sure, I think that seems quite reasonable - as per the Process for aliases, auto-connections and tracks please create a new post in the store-requests category and we can discuss this there.

1 Like

It sounds cool! I open a new post in the store-request. Thank you guys!

1 Like