Skip to main content

Posts

Showing posts with the label systemd

Run Two Systemd Services Alternately

To achieve the desired sequence where `app1` starts, runs for 10 minutes, then `app2` starts and runs for 10 minutes, and this cycle repeats, you can create two separate timer units and services, one for each application, and use a cyclic approach. Here's how you can do it: 1. Create two timer units, one for each application, with cyclic activation:    `myapp1.timer`:    ```ini    [Unit]    Description=Timer for My Application 1    [Timer]    OnBootSec=10min    OnUnitInactiveSec=10min    [Install]    WantedBy=timers.target    ```    `myapp2.timer`:    ```ini    [Unit]    Description=Timer for My Application 2    [Timer]    OnBootSec=20min    OnUnitInactiveSec=10min    [Install]    WantedBy=timers.target    ``` In this configuration, `myapp1.timer` is set to trigger `myapp1.service` 10 minut...