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!


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!


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.


Can you please confirm which balenaFin version you have?

Also, as you probably realised, the fin-block would indeed help you here.

You would need to call the /sleep endpoint with

  "sleepTime" : <time to put compute module to sleep>,
  "sleepDelay" : <time to allow before cutting power to the compute module>

@ipearx were you able to sleep your fin with the recommendations from my colleague?

Let us know if you succeeded.

Hi yes I’m using the fin block container sleep command, which shuts down the device as expected, but still not 100% clear if it is shutting down the host OS cleanly. I suspect it is. I hope it is :slight_smile: I can’t figure out how to issue a Host OS shutdown command from a container after I’ve told the fin block container to shutdown in X seconds. I just saw the message from @rahul-thakoor I couldn’t see a sleep command listed in the API docs when I looked months ago. And still nothing there:

Is that /sleep command you give for fin block? or the balena API?

I also have the occasional device that shuts down and won’t wake up again without a hard power off/on. Hard to diagnose what’s going on as they are out in the field, but I’m sure I saw one with lights on the device still, so it’s like it tried to shutdown, the logs say it did a shutdown, but didn’t actually shut all the way down and is stuck. Or it’s stuck coming back on. Not sure.

I guess my problem is I’m not sure if I’m using the fin block sleep command correctly. There’s very few examples of using this sleep mode online. Also in the logs it mentions looking for updates of the fin block firmware which I don’t understand, I wonder if it freezes sometimes when this happens? Should firmware updates be turned off in production? I don’t know.

Any ideas still welcome. We are waiting on some replacement boards arriving any day now, then I can do more testing.

@ipearx indeed the /sleep command belongs to the fin block you have more documentation here

As far as i know the device Compute Module that runs on the fin is shut down. And the co-processor is managing the shutdown/sleeping time. You can check the power usage meanwhile is sleeping. You can read more here.

Thanks for your feedback and i will see if someone from the balenaFin team can give you more insights about your questions.

@ipearx, from what I’ve seen in the fin-block sleep command code, calling it should trigger a clean shutdown from the supervisor.
You can check it by yourself: fin-block/index.js at master · balenablocks/fin-block · GitHub

You don’t have to bother calling the supervisor directly, as long as your fin-block has the supervisor-api capability in the docker-compose.yml file (template here ), you should be safe only using the /sleep command.

1 Like