I have configured my application to automatically startup by creating a docker-compose.yml file in
/var/sota/storage/docker-compose/
So when the module boots up with torizon it starts to run the docker-compose process. Here is my docker-compose.yml file
version: “2.4”
services:
lol:
image: clotspot/lol
# The line below doesn’t work, really need to run this bash shell outside of the container
command: bash -c “source ./BTini.sh”>
privileged: true
# Accept the EULA required to run imx8 vivante graphic drivers
environment:
- ACCEPT_FSL_EULA=1
ports:
- “55555:55555”
device_cgroup_rules:
# … for /dev/dri devices
- ‘c 226:* rmw’
- ‘c 199:* rmw’
# … for USB devices
- ‘b 8:* rmw’
volumes:
- type: bind
source: /tmp
target: /tmp
- type: bind
source: /dev
target: /dev
- type: bind
source: /media
target: /media
bind:
propagation: shared
- type: bind
source: /var/run/dbus
target: /var/run/dbus
- data:/opt/data
volumes:
data:
The problem is that the docker-compose.yml script above does not call the BTini.sh script, and that is needed to connect my bluetooth printer. BTini.sh is a simple script that sets up rfcomm0.
if [ “$(paired)” = “yes” ]; then
echo “Paired”
else
echo “pair ${MAC}” | bluetoothctl | grep Attempting
fi
if [ “$(rfcommIn)” = “rfcomm0” ]; then
echo “rfcomm device bound on ${MAC}”
else
echo "no rfcomm, setting up binding printer ${MAC} "
sudo rfcomm bind rfcomm0 14:B4:57:F4:7C:96
fi
Inside the debian container there is no bluetooth.service, and setting up the rfcomm0 device first up seems to be the simplest way forward.
My app in the container happily prints to the bluetooth device provided BTini.sh is run manually before “docker-compose up” is run manually.
The problem is that torizoncore calls up docker-compose, and I can’t see how to execute BTini.sh before starting the container launch process?
Any ideas how I can achieve automatic container boot up which calls the BTini.sh script before launching the container?
As an alternative solution you might be able to do this using systemd services. On TorizonCore there is a service that runs on boot that starts the docker-compose file located at /var/sota/storage/docker-compose/.
You could modify or override this service to add the ExecStartPre field as described here: systemd.service
This field will run before the main ExecStart command defined in this service. In this way it may be possible to run your script before your compose file is brought up.