Skip to main content
deleted 1 character in body
Source Link
mcv
  • 73
  • 8

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 Recquires=aRequires=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?

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 Recquires=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?

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?

Source Link
mcv
  • 73
  • 8

How the keyword `After` works in systemd service?

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 Recquires=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?