Systemd: 필요한 서비스 후에 타이머를 실행하는 방법은 무엇입니까?

Systemd: 필요한 서비스 후에 타이머를 실행하는 방법은 무엇입니까?

현재 나는 이것을 가지고 있습니다.체계타이머( my.timer):

[Unit]
Description=My Timer

[Timer]
OnActiveSec=30 
Unit=my-subsequent.service

[Install]
WantedBy=multi-user.target

타이머는 다음과 같은 이유로 시작 시 활성화되도록 설정되었습니다: systemctl enable my.timersystemctl start my.timer.

활성화 후 타이머는 서비스를 시작하기 전에 30초 동안 기다립니다 my-subsequent.service.

하지만,시작 시 타이머를 활성화하는 대신 기다리기를 원합니다.다른 서비스( my-preceding.service)는 시작 시 활성화됩니다.

따라서 체인은 다음과 같습니다.시작하다> my-preceding.service> my.timer> my-subsequent.service.

어떻게 해야 하나요?


편집하다:

타이머에서 After=및 를 사용할 수 있는지 알아보려고 했지만 Requires=아무것도 찾지 못했습니다. 그러나 언뜻 보면 이것이 효과가 있는 것처럼 보입니다. 이것이 허용 가능한 솔루션입니까?

[Unit]
Description=My Timer
After=my-preceding.service
Requires=my-preceding.service

[Timer]
OnActiveSec=30 
Unit=my-subsequent.service

[Install]
WantedBy=multi-user.target

답변1

예, 을(를) 사용하는 After=것이 Requires=서비스를 주문하는 올바른 방법입니다. 또한 지정된 서비스가 Requires실패하면 서비스도 실패한다는 점에 유의할 수도 있습니다 . 맨페이지에서:

Often, it is a better choice to use Wants= instead of Requires= in order to 
achieve a system that is more robust when dealing with failing services.

관련 정보