0

I have the following oneshot service+timer :

$ systemctl cat stop_syncro.service stop_syncro.timer
# /usr/local/lib/systemd/system/stop_syncro.service
[Unit]
Description=Service d_arret de la Synchro
After=network-online.target

[Service]
Type=oneshot
User=root
ExecStart=/root/shl/RUN/stop_syncro.sh

[Install]
WantedBy=multi-user.target

# /usr/local/lib/systemd/system/stop_syncro.timer
[Unit]
Description=Timer d_arret de la Synchro
[Timer]
OnCalendar=Mon-Fri *-*-* 8:00:00
[Install]
WantedBy=timers.target

Then I rebooted the server :

$ last reboot | head -1
reboot   system boot  3.10.0-1160.71.1 Tue May 30 17:53 - 15:02  (21:09)

And it appears the service has been run right after the reboot

$ journalctl -u stop_syncro.service
-- Logs begin at Tue 2023-05-30 17:53:15 CEST, end at Wed 2023-05-31 14:48:17 CEST. --
May 30 17:53:26 PAR-SCAL-01 systemd[1]: Starting Service d_arret de la Synchro...
May 30 17:53:27 PAR-SCAL-01 systemd[1]: Started Service d_arret de la Synchro...
May 31 08:00:01 PAR-SCAL-01 systemd[1]: Starting Service d_arret de la Synchro...
May 31 08:00:02 PAR-SCAL-01 systemd[1]: Started Service d_arret de la Synchro...
$ 

How do I prevent my oneshot service to be only triggered at 8am instead of beeing also launched after reboot ?

1 Answer 1

2

Do not [Install] the service into multi-user.target. I strongly suspect it's not being run by the timer – it's being run on boot because you asked it to be run on boot, by placing it in multi-user.target.

So systemctl disable the .service, and maybe remove its [Install] section to prevent it from being accidentally re-enabled in the future.

4
  • Additionally, RefuseManualStart=yes could be used.
    – Daniel B
    Commented May 31, 2023 at 13:18
  • @user1686 In short, I need to remove the [Install] section only from the service, right ?
    – SebMa
    Commented May 31, 2023 at 13:21
  • 1
    @SebMa They section does nothing on its own. The key part is that the service that must not be “enabled”.
    – Daniel B
    Commented May 31, 2023 at 13:28
  • 2
    @SebMa: From the service, yes. Roughly speaking, when the standard .targets are being used – If you "enable" a .timer unit, you're asking to start scheduling the timer on boot. If you "enable" a .service unit, you're asking to start the service on boot. It's not needed for manual or timer-based start. Commented May 31, 2023 at 13:58

You must log in to answer this question.

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