systemd start stop enable and disable multiple services with one target unit
1
vote
1
answer
2640
views
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/watch-for-sync-need@.service
[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/watch-for-sync-need@.service; disabled; vendor preset: enabled)
Active: inactive (dead)
How can I make systemd start the target (all "sub"-units) at system boot?
Asked by bejo
(175 rep)
Mar 8, 2022, 09:34 PM
Last activity: Mar 31, 2022, 09:26 PM
Last activity: Mar 31, 2022, 09:26 PM