Configure Torizon OS to execute custom script before docker-compose.service is started

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


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:

  1. 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.

  2. 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.

Creating a Drop-in Configuration File

  1. Create the Directory for the Drop-in File:

    sudo mkdir -p /etc/systemd/system/docker-compose.service.d
    
  2. Create the Drop-in Configuration File:
    Create a file named override.conf in the directory you just created:

    sudo nano /etc/systemd/system/docker-compose.service.d/override.conf
    
  3. Add the ExecStartPre Directive:
    Add the following content to the override.conf file:

    [Service]
    ExecStartPre=/path/to/your/custom-script.sh
    

    Replace /path/to/your/custom-script.sh with the actual path to your custom script.

  4. Reload Systemd Configuration:
    After creating the drop-in configuration file, reload the systemd configuration to apply the changes:

    sudo systemctl daemon-reload
    
  5. 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:

[TorizonCoreBuilder] Dropped capabilities while building image.