I've successfully migrated a few of my cron jobs over to systemd. I followed some guides and have taken the standard approach of creating 3 files:

myjob.timer - systemd timer unit
myjob.service - systemd service unit
myjob.sh

As you can probably guess, at a certain time myjob.timer is triggered, which runs myjob.service which in turn executes myjob.sh.

I have the same setup for all of my timers and now that I see everything is working fine I want to disable myjob.timer, which is just a tester.

Do I just do:

systemctl --user disable myjob.timer

or do I also have to do:

systemctl --user disable myjob.service

What is the correct thing to do? I'm quite new to systemd, so I'd like to learn how to do stuff the proper way. I'm guessing that it's correct to disable both units in order to keep the system free of excess baggage running.

up vote 10 down vote accepted

if myjob.service contains no [Install] block, then it is sufficient to just disable the timer. The timer was the only thing starting the .service file, so with the .timer disabled, nothing will start the .service file.

Also remember to run systemctl --user stop myjob.timer. Disabling the timer prevents it from being started on the next boot, but it does not stop the timer currently running.

  • I have an [Install] block in each of my timer units. It has one entry, saying 'WantedBy=default.target'. I got this from the guides I followed. Can I just get rid of the [Install] block altogether? – bitofagoob May 8 '17 at 15:44
  • 1
    OK. I have read about the [Install] section and I think that WantedBy=default.target is just there to ensure that the unit, when enabled, is brought to life during any normal boot session (either multi-user or graphical). I will take Mark Stosberg's advice and disable only the timer unit. I will also mark his answer as the solution. Cheers Mark! – bitofagoob May 8 '17 at 15:54
  • 2
    You want the [Install] section on your timer units so they are started on boot. Usually WantedBy=timers.target. You only need an [Install] section for a service if you want the service to be started at boot time, which it sounds like you don't want in this case. – Mark Stosberg May 8 '17 at 17:22
  • 1
    Thanks. I have removed the [Install] section from the service unit and changed the [Install] section in my timer to WantedBy=timers.target. – bitofagoob May 8 '17 at 17:34

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.