#2 is the really easy and graceful way to close down your system from inside a Torizon container running a Storyboard GUI application.
For everybody else’s benefit when they found themselves in the hope of finding help to do this…
Make a wee script to shut everything down, called goodNight.sh in your home directory.
$ nano goodNight.sh
# (c) Richard Day
# stop the container with a GUI in it, then shut down Linux ready to start again
# Check if file exists
if test -f /tmp/goodNight; then
# delete the sentinel file straight away otherwise we get stuck in a loop
echo "Shutting down Storyboard GUI application"
echo "Shutting down Torizon gracefully "
# save off anything else we want to keep
# send turn off to the bluetooth devices
echo "Starting ostree-goodNight services"
Copy this over to the right directory
sudo cp goodNight.sh /usr/local/bin/goodNight.sh
Create a Service file to run that script when requested
sudo systemctl edit ostree-goodNight.service --full --force
This will bring up an editor for you to insert the following definitions:
Description="Calls the graceful shutdown goodNight"
Make that service start up and go
sudo systemctl start ostree-goodNight.service
sudo systemctl enable ostree-goodNight.service
Make a Path unit file to watch for a file to be changed
In your home directory make another file, ostree-goodNight.path
Description="Monitor the /tmp/goodNight file for changes to its datestamp"
Copy this over to the right directory
$ sudo cp ostree-goodNight.path /etc/systemd/system/ostree-goodNight.path
Make that Path Unit service start up and go
$ sudo systemctl start ostree-goodNight.path
$ sudo systemctl enable ostree-goodNight.path
Finally restart the systemctl daemon , see what these are doing…
$ sudo systemctl daemon-reload
$ systemctl status ostree-goodNight.path
● ostree-goodNight.path - "Monitor the /tmp/goodNight file for changes to its datestamp"
Loaded: loaded (/etc/systemd/system/ostree-goodNight.path; enabled; vendor preset: disabled)
Active: active (waiting) since Sun 2023-02-26 16:58:50 UTC; 10min ago
Triggers: ● ostree-goodNight.service
Feb 26 16:58:50 colibri-imx8x-07021201 systemd: Started "Monitor the /tmp/goodNight file for changes to its datestamp".
$ systemctl status ostree-goodNight.service
● ostree-goodNight.service - "Calls the gracefull shutdown ostree-goodNight"
Loaded: loaded (/etc/systemd/system/ostree-goodNight.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sun 2023-02-26 16:58:51 UTC; 11min ago
TriggeredBy: ● ostree-goodNight.path
Process: 667 ExecStart=/usr/local/bin/goodNight.sh (code=exited, status=0/SUCCESS)
Main PID: 667 (code=exited, status=0/SUCCESS)
Feb 26 16:58:51 colibri-imx8x-07021201 systemd: Started "Calls the gracefull shutdown ostree-goodNight".
Feb 26 16:58:51 colibri-imx8x-07021201 goodNight.sh: Starting ostree-goodNight services
Feb 26 16:58:51 colibri-imx8x-07021201 systemd: ostree-goodNight.service: Succeeded.
Now test it by writing a suitable file with the touch command
$ touch /tmp/goodNight
The module closes itself and powers down (note you need another posting -link- to add the gpio-powerdown device tree overlay to your device tree make a GPIO pin low that can feed into your power switch on the board, if you have this already the board will be off too)
So I would recommend just commenting out the “shutdown” command in the goodNight.sh shell script until you have finished your testing. I got into an infinite system up and shutdown loop the first time I ran my prototype version.
In your storyboard LUA code you need something like this…
local symboLink = "touch /tmp/goodNight"
local popHandle = io.popen(symboLink)
When you call this lua function it writes a file which triggers off the SYSTEMD.path event and that will call up the goodNight.sh file, which has the docker-compose down, and poweroff now commands in it. Everything will be closed down just right and ready for next time.
> application_1 | [INFO tini (1)] Spawned child process '/opt/entryscript.sh' with pid '7'
> application_1 | [INFO tini (1)] Main child exited normally (with status '0')
> torizon_application_1 exited with code 0
One final thing, make sure that in the docker-compose.yml file there is a section that binds the /tmp directory inside the container to the host /tmp directory.
- type: bind
You are very welcome…
(ps. I am looking for a job)