2

I have a systemd service I would like to keep running between set times (let's say midnight to 6 AM). The closest thing I have found so far is limiting it to a set amount of runtime:

[Unit]
Description=Do stuff

[Service]
ExecStart=/bin/do/stuff 
#Stop service after hours
RuntimeMaxSec=21590s
#Once timeout is reached, kill all child processes (SIG15)
KillMode=control-group
#If service does not stop after 10s, consider it failed
TimeoutStopSec=10s

[Install]
WantedBy=multi-user.target

This service should be started at midnight by a timer, but it would be best if I could specify an exact time to stop the service in case it is manually started later.

Is there a method to this this with systemd? I prefer to avoid other tools to keep it simple.

Thanks!

PGEL
  • 117
  • 1
  • 2
  • 15
  • 2
    i don't think there is a clean way, although there is a strategy discussed here: https://unix.stackexchange.com/questions/265704/start-stop-a-systemd-service-at-specific-times – toppk Sep 22 '22 at 12:22

0 Answers0