Pi Shutdown from Container?

Hi I’m running some Fins with a couple of containers installed:

  1. My own python container, running some basic scripts to control a camera and upload the photos
  2. A Fin block container GitHub - balenablocks/fin-block: The fin block is a balenaBlock that provides flashing utilities, status tagging, sleep control and firmata control functionality of the balenaFin. so I can easily put the device into low power mode between photos and overnight using the http API. (Side note, surely there should be a way to do this from my own container?! I couldn’t figure it out…)

I’m assuming when I call this fin block sleep API, I can give it a time to pause before powering down the pi, so that means I’m meant to shut down the pi nicely? But the normal linux shutdown command isn’t available in my container (with or without sudo). And couldn’t find anything on the internet about shutting down the linux system on a Fin.

So the questions:

  • Do I actually need to shutdown the pi nicely? I assume so to avoid the traditional filesystem issues…
  • how do I shutdown the pi nicely from a container?

Some more information on this in the docs would be really useful, surely it’s quite a common thing to do? And make fin-block much more discoverable, took me ages to find it, lots of old links to it are broke. Or document a simpler alternative if one exists. IFor someone who has never used docker/containers before it was quite a stumbling block having to figure out how multi-container development works, figure out docker-compose.yml files (no simple examples easily found) etc just so I can sleep the device for a time.

Cheers for any help!

Hi,

Shutting down nicely is always advisable to prevent data corruption.

You can ask the supervisor to do this for you.
As far as I can tell, the supervisor API doesn’t take a delay like the normal shutdown command.

1 Like

Perfect thank you for that, for some reason I thought those APIs were only for the external web api…

Hmm well I have the shutdown command working, but it doesn’t appear to be waking up again.

The shutdown command: is that shutting down:

a) just the pi’s host OS?
b) the full balena fin board including the co-processor?

i.e. will issuing the API shutdown command allow the sleep to wake up again? and will the services all start again? At this point it shuts down as expected, then lights come back on, but services never start.

I’m issuing the following commands:

os.system('curl -v POST localhost:1337/sleep --data \'{{"sleepTime" : {},"sleepDelay" : 30}}\' --header "Content-Type: application/json"'.format(interval));

os.system('curl -X POST --header "Content-Type:application/json" "{}/v1/shutdown?apikey={}"'.format(BALENA_SUPERVISOR_ADDRESS, BALENA_SUPERVISOR_API_KEY))

Any ideas welcome!

Hi,

The shutdown command is just that, shut down everything gracefully, so you can remove power.
Wake up is not included in it.

If you want to reboot the device, there’s a separate command for that.
Stopping and starting containers are their own commands as well.

In all cases, your containers should come back up when your host OS boots again.

I have no experience with the fin-block and its implementation of the sleep function.
I might be able to experiment a little with it somewhere this week though.

The host OS should be pretty well designed against data corruption, so I think the main question is how your containers behave.

Hey thanks for the reply - yeah I was wondering if shutting down my containers would be enough. But I’m assuming we could still corrupt the filesystem in the parent system.

Restart wouldn’t be a good idea because it’ll be re-booting when the pi power is cut.

From what I understand, the fin-block container provides a simple http accessible API to the co-processor functions. The sleep function in particular tells the FIN board co-processor to wake up at a certain time, and the pi, modem and all ports are shutdown.
Cheers