57

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.

1 Answer 1

61

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.

4
  • 1
    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
    Commented May 8, 2017 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
    Commented May 8, 2017 at 15:54
  • 5
    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. Commented May 8, 2017 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
    Commented May 8, 2017 at 17:34

You must log in to answer this question.

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