On Sat, May 16, 2020 at 06:51:04PM +0200, Geert Stappers wrote: > On Sat, May 16, 2020 at 01:41:00PM +0200, Luuk wrote: > > On 15-5-2020 22:42, Geert Stappers wrote: > > > > > > Wat ik zoek is > > > how configure multiple systemd timers to use same systemd service > > > > > > > > > Met cron zou het iets zijn als > > > > > > #m h d m day > > > * 7 * * Mon-Sat periodiekejob dagelijks > > > * 5 * * Sun periodiekejob wekelijks > > > 0 * * * * periodiekejob elkuur > > > > > > > > > Met systemd heb ik dan drie timers en drie service files nodig.
Het blijkt dat @%i doet wat ik zocht.
Wat volgt is een proof of concept ( staat ook in de tarball )
==> README.md <==
Proof of concept of several systemd timers
starting the same systemd service
sudo make install
journalctl -fu rapporteer@\*
(control-C to exit)
sudo make deinstall
# l l
==> Makefile <==
#
all:
@echo nothing to build ...
install:
cp rapporteer /usr/local/bin/
cp [email protected] /etc/systemd/system/
cp [email protected] /etc/systemd/system/
cp [email protected] /etc/systemd/system/
cp [email protected] /etc/systemd/system/
systemctl daemon-reload
systemctl start [email protected]
systemctl start [email protected]
systemctl start [email protected]
deinstall:
-systemctl stop [email protected]
-systemctl stop [email protected]
-systemctl stop [email protected]
rm -f /usr/local/bin/rapporteer
rm -f /etc/systemd/system/[email protected]
rm -f /etc/systemd/system/[email protected]
rm -f /etc/systemd/system/[email protected]
rm -f /etc/systemd/system/[email protected]
systemctl daemon-reload
tarball:
mkdir rapporteerpoc
-cp * rapporteerpoc/
rm -f rapporteerpoc/*.tgz
tar czf rapporteerpoc.tgz rapporteerpoc/
rm -rf rapporteerpoc
clean:
rm -f rapporteerpoc.tgz
# l l
==> rapporteer <==
#!/usr/bin/python3
'''
rapporteer
Proof Of Concept for handing over parameter
through environment variables
'''
import os
if os.getenv('RAPPORTEER'):
parameter = os.getenv('RAPPORTEER')
else:
parameter = "not_present"
print("parameter value is {}".format(parameter))
# l l
==> [email protected] <==
[Unit]
Description=rapporteer %i POC, several timers will start us
[Service]
Type=oneshot
Environment=RAPPORTEER=%i
ExecStart=/usr/local/bin/rapporteer
[Install]
WantedBy=multi-user.target
# l l
==> [email protected] <==
[Unit]
Description=Rapporteer Proof of concept
[Timer]
Unit=rapporteer@%i.service
OnCalendar=*-*-* *:*:00
[Install]
WantedBy=timers.target
# l l
==> [email protected] <==
[Unit]
Description=Rapporteer Proof of concept
[Timer]
Unit=rapporteer@%i.service
OnCalendar=*-*-* *:*:10,30,50
[Install]
WantedBy=timers.target
# l l
==> [email protected] <==
[Unit]
Description=Rapporteer Proof of concept
[Timer]
Unit=rapporteer@%i.service
OnCalendar=*-*-* *:*:12,32,52
[Install]
WantedBy=timers.target
# l l
Groeten
Geert Stappers
--
Silence is hard to parse
rapporteerpoc.tgz
Description: application/gtar-compressed
