1

I have created a target file /etc/systemd/system/watch-for-sync-need-all.target

[Unit]
Description=systemd target to group services for all folders that create a sync need by changes
After=multi-user.target
Wants=watch-for-sync-need@_sl_home_sl_.service
Wants=watch-for-sync-need@_sl_stream_sl_.service

[Install]
Also=watch-for-sync-need@_sl_home_sl_.service
Also=watch-for-sync-need@_sl_stream_sl_.service

Its purpose is to be able to start, stop, enable or disable all in the target specified systemd template services /etc/systemd/system/[email protected]

[Unit]
Description=watch sync folders for changes then flag sync need and set rtcwake
BindsTo=watch-for-sync-need-all.target
After=watch-for-sync-need-all.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/bin/bash /etc/custom/notify-on-change %i
Restart=on-failure
RestartSec=3

[Install]
WantedBy=watch-for-sync-need-all.target

In case it has to deal with my problem I post the called script content of /etc/custom/notify-on-change

#! /usr/bin/env bash

inotifywait -q -m -r -e modify,delete,create "${1//_sl_//}" | while read DIRECTORY EVENT FILE
do
    echo "yes" > /etc/custom/log/sync-needed
    bash /etc/custom/set-rtcwake
    systemctl stop watch-for-sync-need-all.target
done

If there is a change in the folders /home/ or /stream/ inotifywait notices that, flags a sync need, sets a computer self wakeup in the upcoming night at 3 o'clock and stops the services. (There is a cronjob on the machine that syncs to another computer at some minutes past 3 o'clock, if a sync need is flagged. The computer shuts itself down, when not used. Like that, I can work on my computer and make changes in /home/ or /stream/ and then and only then a sync will be started shortly automatically.)

My Problem is, that I can't enable my target adequately. The target can be started or stopped without problems. That means, that both "sub"-units are running. Enabling does not give out any warnings and creates corresponding links in the directory /etc/systemd/system/watch-for-sync-need-all.target.wants but when my machine boots, the "sub"-units are not running. After a new boot I get the following output of

systemctl status watch-for-sync-need-all.target 

watch-for-sync-need-all.target - systemd target to group services for all folders that create a sync need by ch>
Loaded: loaded (/etc/systemd/system/watch-for-sync-need-all.target; indirect; vendor preset: enabled)
Active: inactive (dead)`enter code here`

or

systemctl status watch-for-sync-need@_sl_home_sl.service

watch-for-sync-need@_sl_home_sl.service - watch sync folders for changes then flag sync need and set rtcwake
Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: enabled)
Active: inactive (dead)

How can I make systemd start the target (all "sub"-units) at system boot?

bejo
  • 165
  • 4
  • 16

1 Answers1

1

In the Install-section of /etc/systemd/system/watch-for-sync-need-all.target multi-user.target had to be added as WantedBy and now it works. In this stack overflow thread Systemd with multiple execStart comment 5 by Johny mentions that.

I do not understand, why this is needed, since the target is supposed to start after multi-user.target like defined in the Unit-section and as far as I have understood, the unit-section accounts for all actions to it including enabling at system boot.

I hope this thread and answer helps anyway.

bejo
  • 165
  • 4
  • 16