Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!
Did you like my answer?
Yes, it is possible to configure Torizon OS to execute a custom script before the docker-compose.service is started without recompiling Torizon OS from sources. You can achieve this by creating a custom systemd service that includes the ExecStartPre directive.
Here are the steps to do this:
Create a Custom Systemd Service File:
You need to create a custom systemd service file that includes the ExecStartPre directive to run your custom script before starting the docker-compose.service.
Edit the Custom Service File:
You can create a new service file or override the existing docker-compose.service by creating a drop-in configuration file.
Replace /path/to/your/custom-script.sh with the actual path to your custom script.
Reload Systemd Configuration:
After creating the drop-in configuration file, reload the systemd configuration to apply the changes:
sudo systemctl daemon-reload
Restart the Docker Compose Service:
Finally, restart the docker-compose.service to ensure it picks up the new configuration:
sudo systemctl restart docker-compose.service
Example Custom Script
Make sure your custom script is executable:
sudo chmod +x /path/to/your/custom-script.sh
Summary
By following these steps, you can configure Torizon OS to execute a custom script before the docker-compose.service is started without the need to recompile Torizon OS from sources. The key is to use systemd’s drop-in configuration mechanism to add the ExecStartPre directive.
Please, also check if these links can help you solve your problem:
You can either add the connection/dependency in docker-compose.service via an override (systemctl edit <service-name>). Or if you don’t want to override the base service you could probably create the connection in your new custom service. See the following systemd documentation for an idea: systemd.unit
Particularly the Before/After options. With this, in theory you could use Before in your custom service so that it’s configured to start before docker-compose.service starts. That way you wouldn’t have to touch/override the existing service.
I forgot to mention this prior, but it may not be ideal to modify docker-compose.service if you plan to update the OS. There is always a possibility that we update or change docker-compose.service ourselves and then you’ll need to account for this since you’re modifying/overriding the service yourself.
[Unit]
Description=My custom service
Before=docker-compose.service
[Service]
ExecStart=/usr/bin/bash /etc/my-custom-script.sh
Type=simple
As you can see, my service doesn’t have any requisite/dependency (After …)
It seems working, but I’m going to test it heavily.
My custom script runs a mkfifo command, so I think it requires that the file system is “ready”.
Should I specify this with some dependency/requirement?
My custom script runs a mkfifo command, so I think it requires that the file system is “ready”.
Should I specify this with some dependency/requirement?
Probably what you want to add is After=systemd-remount-fs.service to your service. The systemd-remout-fs.service is a special service. In summary this service ensures all mount options have been applied to the filesystem, this implies the filesystem is “ready”. So configuring your service to run after this, should ensure the root filesystem is in a “ready” state. For more info on this service you can see here: systemd-remount-fs.service