Hi Jeremias,
#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
#!/bin/bash
# (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
rm /tmp/goodNight
echo "Shutting down Storyboard GUI application"
cd /home/torizon/
docker-compose down
echo "Shutting down Torizon gracefully "
# save off anything else we want to keep
# send turn off to the bluetooth devices
poweroff
else
echo "Starting ostree-goodNight services"
fi
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:
[Unit]
Description="Calls the graceful shutdown goodNight"
[Service]
ExecStart=/usr/local/bin/goodNight.sh
[Install]
WantedBy=multi-user.target
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
nano ostree-goodNight.path
[Unit]
Description="Monitor the /tmp/goodNight file for changes to its datestamp"
[Path]
PathExists=/tmp/goodNight
Unit=ostree-goodNight.service
[Install]
WantedBy=multi-user.target
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[1]: Started "Monitor the /tmp/goodNight file for changes to its datestamp".
status ostree-goodNight.path
$ 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[1]: Started "Calls the gracefull shutdown ostree-goodNight".
Feb 26 16:58:51 colibri-imx8x-07021201 goodNight.sh[667]: Starting ostree-goodNight services
Feb 26 16:58:51 colibri-imx8x-07021201 systemd[1]: 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…
function Application:goodNight()
local symboLink = "touch /tmp/goodNight"
local popHandle = io.popen(symboLink)
end
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.
volumes:
- type: bind
source: /tmp
target: /tmp
You are very welcome…
Richard
(ps. I am looking for a job)