0

I have prepared two services a.service and b.service. The a.service run using a.timer.

a.service

[Unit]
Description=service a
After=network-online.target
Wants=network-online.target

[Service]
Type=simple

#restart on failure and tries 5 times. If fail in all, then reboot the system
ExecStart=/usr/bin/python /home/pi/.clar/a.py
Restart=on-failure
RestartSec=15
StartLimitBurst=5
StartLimitInterval=2min
StartLimitAction=reboot

a.timer

[Unit]
Description=10minute timer

[Timer]
# start this 20 Sec after boot:
OnBootSec=20

# ... and then every 10 minute:
OnUnitActiveSec=10m

[Install]
WantedBy=multi-user.target

b.service

[Unit]
Description=b service
After=a.service

[Service]
Type=simple

#restart on failure and tries 5 times. If fail in all, then reboot the system
ExecStartPre=/usr/bin/python /home/pi/.clar/c.py
ExecStart=/usr/bin/python /home/pi/.clar/b.py
Restart=on-failure
RestartSec=15
StartLimitBurst=5
StartLimitInterval=2min
StartLimitAction=reboot

[Install]
WantedBy=multi-user.target

As my configuration a.service will start after 20sec from boot up and b.service should run after a.service.

But in reallity b.service is started before the a.service. I have searched google and I tried by adding both Requires=a.service and Wants=a.service in b.service unit section. But neither one helped me.

I didn't understand the After working. Is there anything else to add in the configuration?

9
  • Why is b.service WantedBy=multi-user.target?
    – muru
    Commented Sep 5, 2019 at 6:05
  • to start on reboot
    – mcv
    Commented Sep 5, 2019 at 6:46
  • But you seem to want to start it after a.service is started. Which is it?
    – muru
    Commented Sep 5, 2019 at 6:51
  • without WanteBy b.service will start after a.service?
    – mcv
    Commented Sep 5, 2019 at 6:52
  • What is the actual flow you want?
    – muru
    Commented Sep 5, 2019 at 7:10

1 Answer 1

1

As muru said, You can modify it just like below.

[Unit]
Description=b service
After=a.service

[Service]
Type=simple

#restart on failure and tries 5 times. If fail in all, then reboot the system
ExecStartPre=/usr/bin/python /home/pi/.clar/c.py
ExecStart=/usr/bin/python /home/pi/.clar/b.py
Restart=on-failure
RestartSec=15
StartLimitBurst=5
StartLimitInterval=2min
StartLimitAction=reboot

[Install]
WantedBy=a.service

Then you have to do sudo systemctl disable b.service and sudo systemctl enable b.service

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .