How to delay a systemd service at startup?

I’d like to know if there is away to delay the start of a systemd service during boot. I have both Sonarr and qBittorrent and need to delay Sonarr a minute or two to allow for qBittorrent to start so I don’t have to go into the Sonarr settings and make it see qBittorrent. Currently Sonarr starts looks for qBittorrent or it’s service, doesn’t find it and say no download client found. This is because Sonarr starts prior to QBT starting.

Manjaro KDE Testing

    ~  inxi -Fxxxza                                                    ✔ 
System:
  Kernel: 5.15.1-1-MANJARO x86_64 bits: 64 compiler: gcc v: 11.1.0
  parameters: BOOT_IMAGE=/@/boot/vmlinuz-5.15-x86_64
  root=UUID=0e474eb0-4b46-41af-8757-51221e62c250 rw rootflags=subvol=@
  quiet apparmor=1 security=apparmor udev.log_priority=3
  Desktop: KDE Plasma 5.23.2 tk: Qt 5.15.2 wm: kwin_x11 vt: 1 dm: SDDM
  Distro: Manjaro Linux base: Arch Linux
Machine:
  Type: Desktop System: ASUS product: N/A v: N/A serial: <filter>
  Mobo: ASUSTeK model: ROG STRIX B550-F GAMING v: Rev X.0x serial: <filter>
  UEFI: American Megatrends v: 2423 date: 08/10/2021
Battery:
  Device-1: hidpp_battery_0 model: Logitech Wireless Mouse M325
  serial: <filter> charge: 55% (should be ignored) rechargeable: yes
  status: Discharging
  Device-2: hidpp_battery_1 model: Logitech Wireless Keyboard K360
  serial: <filter> charge: 100% (should be ignored) rechargeable: yes
  status: Discharging
CPU:
  Info: 6-Core model: AMD Ryzen 5 3600 bits: 64 type: MT MCP arch: Zen 2
  family: 17 (23) model-id: 71 (113) stepping: 0 microcode: 8701021 cache:
  L2: 3 MiB
  flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
  bogomips: 86257
  Speed: 2052 MHz min/max: 2200/3600 MHz boost: enabled Core speeds (MHz):
  1: 2052 2: 2109 3: 2195 4: 2194 5: 2056 6: 2196 7: 2187 8: 2192 9: 3592
  10: 2209 11: 2054 12: 2196
  Vulnerabilities: Type: itlb_multihit status: Not affected
  Type: l1tf status: Not affected
  Type: mds status: Not affected
  Type: meltdown status: Not affected
  Type: spec_store_bypass
  mitigation: Speculative Store Bypass disabled via prctl and seccomp
  Type: spectre_v1
  mitigation: usercopy/swapgs barriers and __user pointer sanitization
  Type: spectre_v2 mitigation: Full AMD retpoline, IBPB: conditional,
  STIBP: conditional, RSB filling
  Type: srbds status: Not affected
  Type: tsx_async_abort status: Not affected
Graphics:
  Device-1: NVIDIA TU116 [GeForce GTX 1650 SUPER] vendor: eVga.com.
  driver: nvidia v: 495.44 alternate: nouveau,nvidia_drm bus-ID: 08:00.0
  chip-ID: 10de:2187 class-ID: 0300
  Display: x11 server: X.Org 1.20.13 compositor: kwin_x11 driver:
  loaded: nvidia display-ID: :0 screens: 1
  Screen-1: 0 s-res: 2560x1080 s-dpi: 97 s-size: 670x283mm (26.4x11.1")
  s-diag: 727mm (28.6")
  Monitor-1: HDMI-0 res: 2560x1080 hz: 60 dpi: 97
  size: 673x284mm (26.5x11.2") diag: 730mm (28.8")
  OpenGL: renderer: NVIDIA GeForce GTX 1650 SUPER/PCIe/SSE2
  v: 4.6.0 NVIDIA 495.44 direct render: Yes
Audio:
  Device-1: NVIDIA TU116 High Definition Audio vendor: eVga.com.
  driver: snd_hda_intel v: kernel bus-ID: 08:00.1 chip-ID: 10de:1aeb
  class-ID: 0403
  Device-2: AMD Starship/Matisse HD Audio vendor: ASUSTeK
  driver: snd_hda_intel v: kernel bus-ID: 0a:00.4 chip-ID: 1022:1487
  class-ID: 0403
  Sound Server-1: ALSA v: k5.15.1-1-MANJARO running: yes
  Sound Server-2: sndio v: N/A running: no
  Sound Server-3: JACK v: 1.9.19 running: no
  Sound Server-4: PulseAudio v: 15.0 running: yes
  Sound Server-5: PipeWire v: 0.3.39 running: yes
Network:
  Device-1: Intel Ethernet I225-V vendor: ASUSTeK driver: igc v: kernel
  port: N/A bus-ID: 07:00.0 chip-ID: 8086:15f3 class-ID: 0200
  IF: enp7s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
Drives:
  Local Storage: total: 20.82 TiB used: 11.26 TiB (54.1%)
  SMART Message: Unable to run smartctl. Root privileges required.
  ID-1: /dev/nvme0n1 maj-min: 259:1 vendor: Seagate
  model: XPG GAMMIX S11 Pro size: 476.94 GiB block-size: physical: 512 B
  logical: 512 B speed: 31.6 Gb/s lanes: 4 type: SSD serial: <filter>
  rev: 32B3T8EB temp: 33.9 C scheme: GPT
  ID-2: /dev/nvme1n1 maj-min: 259:0 vendor: Patriot model: Viper M.2 VPN100
  size: 238.47 GiB block-size: physical: 512 B logical: 512 B
  speed: 31.6 Gb/s lanes: 4 type: SSD serial: <filter> rev: ECFM22.6
  temp: 29.9 C scheme: GPT
  ID-3: /dev/sda maj-min: 8:0 type: USB vendor: Seagate
  model: ST8000AS0002-1NA17Z size: 7.28 TiB block-size: physical: 4096 B
  logical: 512 B type: HDD rpm: 5980 serial: <filter> scheme: GPT
  ID-4: /dev/sdb maj-min: 8:16 type: USB vendor: Seagate
  model: ST330006 51NS size: 2.73 TiB block-size: physical: 4096 B
  logical: 512 B type: N/A serial: <filter> rev: 7101 scheme: GPT
  SMART Message: Unknown USB bridge. Flash drive/Unsupported enclosure?
  ID-5: /dev/sdc maj-min: 8:32 type: USB vendor: Seagate
  model: Expansion HDD size: 7.28 TiB block-size: physical: 4096 B
  logical: 512 B type: N/A serial: <filter> rev: 1801 scheme: GPT
  ID-6: /dev/sdd maj-min: 8:48 type: USB vendor: Seagate
  model: ST3000DM 001-1E6166 size: 2.73 TiB block-size: physical: 4096 B
  logical: 512 B type: N/A serial: <filter> rev: 7101 scheme: GPT
  SMART Message: Unknown USB bridge. Flash drive/Unsupported enclosure?
  ID-7: /dev/sde maj-min: 8:64 type: USB vendor: PNY model: USB 3.0 FD
  size: 115.38 GiB block-size: physical: 512 B logical: 512 B type: N/A
  serial: <filter> rev: PMAP scheme: MBR
  SMART Message: Unknown USB bridge. Flash drive/Unsupported enclosure?
Partition:
  ID-1: / raw-size: 476.64 GiB size: 476.64 GiB (100.00%)
  used: 89.11 GiB (18.7%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:3
  ID-2: /boot/efi raw-size: 300 MiB size: 299.4 MiB (99.80%)
  used: 568 KiB (0.2%) fs: vfat dev: /dev/nvme0n1p1 maj-min: 259:2
  ID-3: /home raw-size: 476.64 GiB size: 476.64 GiB (100.00%)
  used: 89.11 GiB (18.7%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:3
  ID-4: /var/log raw-size: 476.64 GiB size: 476.64 GiB (100.00%)
  used: 89.11 GiB (18.7%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:3
Swap:
  Kernel: swappiness: 60 (default) cache-pressure: 100 (default)
  ID-1: swap-1 type: file size: 512 MiB used: 80.7 MiB (15.8%) priority: -2
  file: /swap/swapfile
Sensors:
  Message: No sensor data found. Is lm-sensors configured?
Info:
  Processes: 471 Uptime: 3h 2m wakeups: 37 Memory: 31.33 GiB
  used: 8.67 GiB (27.7%) Init: systemd v: 249 tool: systemctl Compilers:
  gcc: 11.1.0 Packages: 1703 pacman: 1660 lib: 446 flatpak: 32 snap: 11
  Shell: Zsh v: 5.8 default: Bash v: 5.1.8 running-in: konsole inxi: 3.3.08

It sounds like you want to create a systemd timer or a cronjob?

https://wiki.archlinux.org/title/Systemd/Timers

2 Likes

https://stackoverflow.com/questions/43001223/how-to-ensure-that-there-is-a-delay-before-a-service-is-started-in-systemd

2 Likes

This is normally done by WantedBy/RequiredBy: https://www.freedesktop.org/software/systemd/man/systemd.unit.html#WantedBy=

2 Likes