Hello Mike,
I’m new on the forum, but here are my thoughts.
If you have a multi docker environment, and define it via a docker-compose yaml file, you should be able interact with the supervisor via the host APIvia the local docker network.
See https://www.balena.io/docs/learn/develop/runtime/ for the environment variables you can use ( BALENA_SUPERVISOR_ADDRESS
seems convenient). Be sure to also set the label io.balena.features.supervisor-api: '1'
on the container where you want to implement the shutdown timer.
This resource https://www.balena.io/docs/reference/supervisor/supervisor-api/ gives an example command to shut down the hardware:
curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/shutdown?apikey=$BALENA_SUPERVISOR_API_KEY"
We can wrap this in a python script for example and put it in it’s own container. Something that I quickly have thrown together:
import requests
import os
import re
from dateutil.relativedelta import relativedelta
import datetime
headers = {
'Content-Type': 'application/json',
}
params = (
('apikey', os.getenv('BALENA_SUPERVISOR_API_KEY')),
)
nap_time = os.getenv('NAP_TIME')
match = re.match('(\d{1,2}):(\d{1,2})', nap_time)
if match is not None:
hour = match.group[1]
minute = match.group[2]
today = datetime.date.today()
nap_time_today = datetime.date(
today.year,
today.month,
today.day,
hour,
minute
)
while (datetime.datetime.today() < nap_time_today):
time.sleep(5)
requests.post('http://{}/v1/shutdown'.format(os.getenv('BALENA_SUPERVISOR_ADDRESS')), headers=headers, params=params)
Then we can set the environment variable NAP_TIME
to e.g.: 4:00 (or any 24-hour clock time) and the script should shut down the host.
I hope this brings you some inspiration.
Woody