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 rapporteer@tien.timer /etc/systemd/system/ cp rapporteer@twaalf.timer /etc/systemd/system/ cp rapporteer@minuut.timer /etc/systemd/system/ cp rapporteer@.service /etc/systemd/system/ systemctl daemon-reload systemctl start rapporteer@tien.timer systemctl start rapporteer@twaalf.timer systemctl start rapporteer@minuut.timer deinstall: -systemctl stop rapporteer@tien.timer -systemctl stop rapporteer@twaalf.timer -systemctl stop rapporteer@minuut.timer rm -f /usr/local/bin/rapporteer rm -f /etc/systemd/system/rapporteer@tien.timer rm -f /etc/systemd/system/rapporteer@twaalf.timer rm -f /etc/systemd/system/rapporteer@minuut.timer rm -f /etc/systemd/system/rapporteer@.service 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 ==> rapporteer@.service <== [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 ==> rapporteer@minuut.timer <== [Unit] Description=Rapporteer Proof of concept [Timer] Unit=rapporteer@%i.service OnCalendar=*-*-* *:*:00 [Install] WantedBy=timers.target # l l ==> rapporteer@tien.timer <== [Unit] Description=Rapporteer Proof of concept [Timer] Unit=rapporteer@%i.service OnCalendar=*-*-* *:*:10,30,50 [Install] WantedBy=timers.target # l l ==> rapporteer@twaalf.timer <== [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
Attachment:
rapporteerpoc.tgz
Description: application/gtar-compressed