package/quagga: Add systemd.service file
PATCH 1/1 package/quagga: Add systemd.service file
Use a template service file as all of the daemons use almost identical arguments and generally appear the same to the init system.
We "Wants=" zebra as that's the daemon for interfacing to the kernel, and it's not required for the other daemons to work but it's probably going to be used in nearly all setups.
/usr/bin/env is needed as systemd doesn't allow the instance variable (%i) in the executable path.
We don't enable these services by default as this would require creating configuration and /etc/default files. (And is easily achieved with an FS overlay)
---
Changes v1 -> v2:
(As suggested by Arnout Vandecappelle)
- Completely remove shim and use /usr/bin/env instead
- Don't tell quagga to fork as systemd prefers it
- Add comment to .service file about /usr/bin/env
- Explain not enabling the service on build in patch
--- package/quagga/quagga.mk | 3 +++ package/quagga/quagga at .service | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 package/quagga/quagga at .service
package/quagga/quagga.mk +3 -0
@@ -75,6 +75,9 @@ endif define QUAGGA_INSTALL_INIT_SYSTEMD $(INSTALL) -D -m 644 package/quagga/quagga_tmpfiles.conf \ $(TARGET_DIR)/usr/lib/tmpfiles.d/quagga.conf + + $(INSTALL) -D -m 644 package/quagga/quagga at .service \ + $(TARGET_DIR)/usr/lib/systemd/system/quagga at .service endef $(eval $(autotools-package))
package/quagga/quagga at .service new file +20 -0
@@ -0,0 +1,20 @@ +[Unit] +Description=Quagga %i routing daemon +PartOf=quagga.service +ReloadPropagatedFrom=quagga.service +Wants=quagga at zebra.service + +[Service] +PrivateTmp=true +KillMode=mixed +Type=simple +EnvironmentFile=/etc/default/quagga-%i +# Systemd doesn't like having %i in the executable path. +ExecStart=/usr/bin/env /usr/sbin/%i $OPTS -f /etc/quagga/%i.conf -i /var/run/quagga/%i.pid +PIDFile=/var/run/quagga/%i.pid +KillSignal=SIGINT +Restart=on-failure +RestartSec=1 + +[Install] +WantedBy=multi-user.target
Signature · 1 line
2.8.1
PATCH 1/1 package/quagga: Add systemd.service file
Quoted 8 lines · Nathaniel Roach
Use a template service file as all of the daemons use almost identical arguments and generally appear the same to the init system.
We "Wants=" zebra as that's the daemon for interfacing to the kernel, and it's not required for the other daemons to work but it's probably going to be used in nearly all setups.
Quoted 6 lines
/usr/bin/envis needed as systemd doesn't allow the instance variable (%i) in the executable path.We don't enable these services by default as this would require creating configuration and
/etc/defaultfiles. (And is easily achieved with an FS overlay)
^missing .
So the goal of this patch is that the user simply can symlink to instead of
having to create the service file.
However, since the Wants= is added for zebra, it would make sense to create the
zebra symlink, no?
Quoted 21 lines
Signed-off-by Nathaniel Roach <[email protected]>---
Changes v1 -> v2:
(As suggested by Arnout Vandecappelle)
- Completely remove shim and use/usr/bin/envinstead
- Don't tell quagga to fork as systemd prefers it
- Add comment to .service file about/usr/bin/env
- Explain not enabling the service on build in patch--- package/quagga/quagga.mk | 3 +++ package/quagga/quagga at .service | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 package/quagga/quagga at .servicepackage/quagga/quagga.mk +0
-0
package/quagga/quagga.mk endif · line 78
Quoted 4 lines
package/quagga/quagga.mk +1
-0@@ -75,6 +75,9 @@ endif define QUAGGA_INSTALL_INIT_SYSTEMD $(INSTALL) -D -m 644 package/quagga/quagga_tmpfiles.conf \ $(TARGET_DIR)/usr/lib/tmpfiles.d/quagga.conf +
This empty line is redundant.
Quoted 11 lines
package/quagga/quagga.mk +2
-0+ $(INSTALL) -D -m 644 package/quagga/quagga at .service \ + $(TARGET_DIR)/usr/lib/systemd/system/quagga at .service endef $(eval $(autotools-package))package/quagga/quagga at .service new file +0
-0
package/quagga/quagga at .service line 3
Quoted 3 lines
package/quagga/quagga at .service new file +3
-0@@ -0,0 +1,20 @@ +[Unit] +Description=Quagga %i routing daemon +PartOf=quagga.service
I don't understand this. Doesn't the quagga.service actually have to exist for
this to be valid?
package/quagga/quagga at .service line 5
Quoted 2 lines
package/quagga/quagga at .service new file +2
-0+ReloadPropagatedFrom=quagga.service +Wants=quagga at zebra.service
I just realize now: this line should probably be removed whenBR2_PACKAGE_QUAGGA_ZEBRA is not set.
package/quagga/quagga at .service line 9
Quoted 4 lines
package/quagga/quagga at .service new file +4
-0+ +[Service] +PrivateTmp=true +KillMode=mixed
It would make sense to keep this together with KillSignal.
package/quagga/quagga at .service line 14
Quoted 5 lines
package/quagga/quagga at .service new file +5
-0+Type=simple +EnvironmentFile=/etc/default/quagga-%i +# Systemd doesn't like having %i in the executable path. +ExecStart=/usr/bin/env /usr/sbin/%i $OPTS -f /etc/quagga/%i.conf -i /var/run/quagga/%i.pid +PIDFile=/var/run/quagga/%i.pid
I repeat, I'm not very familiar with systemd, but as I understand it PID files
shouldn't be needed anymore with a Type=simple daemon. Unless of course if quagga uses them somewhere else too.
Regards,
Arnout
Quoted 7 lines
package/quagga/quagga at .service new file +6
-0+KillSignal=SIGINT +Restart=on-failure +RestartSec=1 + +[Install] +WantedBy=multi-user.target
Signature · 6 lines
Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
PATCH 1/1 package/quagga: Add systemd.service file
Quoted 15 lines · Arnout Vandecappelle
Quoted 8 lines · Nathaniel Roach
Use a template service file as all of the daemons use almost identical arguments and generally appear the same to the init system.
We "Wants=" zebra as that's the daemon for interfacing to the kernel, and it's not required for the other daemons to work but it's probably going to be used in nearly all setups.
Quoted 6 lines
/usr/bin/envis needed as systemd doesn't allow the instance variable (%i) in the executable path.We don't enable these services by default as this would require creating configuration and
/etc/defaultfiles. (And is easily achieved with an FS overlay)
Quoted 7 lines
^missing .
So the goal of this patch is that the user simply can symlink to instead of
having to create the service file.However, since the Wants= is added for zebra, it would make sense to create the
zebra symlink, no?
No, systemd will automatically start zebra when it's needed. It's not needed until one of the other daemons start (which systemd will start zebra beforehand if the daemon is local). If they are remote, the user can enable zebra themselves.
Quoted 31 lines
Quoted 21 lines
Signed-off-by Nathaniel Roach <[email protected]>---
Changes v1 -> v2:
(As suggested by Arnout Vandecappelle)
- Completely remove shim and use/usr/bin/envinstead
- Don't tell quagga to fork as systemd prefers it
- Add comment to .service file about/usr/bin/env
- Explain not enabling the service on build in patch--- package/quagga/quagga.mk | 3 +++ package/quagga/quagga at .service | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+)create mode 100644 package/quagga/quagga at .service
package/quagga/quagga.mk +0
-0package/quagga/quagga.mk endif · line 78
Quoted 4 lines
package/quagga/quagga.mk +1
-0@@ -75,6 +75,9 @@ endif define QUAGGA_INSTALL_INIT_SYSTEMD $(INSTALL) -D -m 644 package/quagga/quagga_tmpfiles.conf \ $(TARGET_DIR)/usr/lib/tmpfiles.d/quagga.conf +This empty line is redundant.
Quoted 4 lines
package/quagga/quagga.mk +2
-0+ $(INSTALL) -D -m 644 package/quagga/quagga at .service \ + $(TARGET_DIR)/usr/lib/systemd/system/quagga at .service endef
Quoted 12 lines
package/quagga/quagga at .service line 3
Quoted 10 lines
package/quagga/quagga.mk +0
-0$(eval $(autotools-package))package/quagga/quagga at .service new file +3
-0@@ -0,0 +1,20 @@ +[Unit] +Description=Quagga %i routing daemon +PartOf=quagga.serviceI don't understand this. Doesn't the quagga.service actually have to exist for
this to be valid?
That is true, it's left over from my openvpn service file. Will remove that and ReloadPropagatedFrom=
Quoted 5 lines
package/quagga/quagga at .service line 5
Quoted 3 lines
package/quagga/quagga at .service new file +2
-0+ReloadPropagatedFrom=quagga.service +Wants=quagga at zebra.serviceI just realize now: this line should probably be removed when
BR2_PACKAGE_QUAGGA_ZEBRAis not set.
Also true, however that's why I said Wants= and not Requires= so systemd handles the lack of zebra fine.
Quoted 7 lines
package/quagga/quagga at .service line 9
Quoted 5 lines
package/quagga/quagga at .service new file +4
-0+ +[Service] +PrivateTmp=true +KillMode=mixedIt would make sense to keep this together with KillSignal.
Quoted 8 lines
package/quagga/quagga at .service line 14
Quoted 5 lines
package/quagga/quagga at .service new file +5
-0+Type=simple +EnvironmentFile=/etc/default/quagga-%i +# Systemd doesn't like having %i in the executable path. +ExecStart=/usr/bin/env /usr/sbin/%i $OPTS -f /etc/quagga/%i.conf -i /var/run/quagga/%i.pid +PIDFile=/var/run/quagga/%i.pidI repeat, I'm not very familiar with systemd, but as I understand it PID files
shouldn't be needed anymore with a Type=simple daemon. Unless of course if quagga uses them somewhere else too.
Also correct. I left the -i argument in as I thought it was required for vtysh, but it is not.
Quoted 5 lines
Regards,
Arnout
Quoted 8 lines
package/quagga/quagga at .service line 20
Quoted 7 lines
package/quagga/quagga at .service new file +6
-0+KillSignal=SIGINT +Restart=on-failure +RestartSec=1 + +[Install] +WantedBy=multi-user.target
Thanks for the feedback!
Nathaniel Roach
PATCH 1/1 package/quagga: Add systemd.service file
(Mainly improving my systemd knowledge here :-)
Quoted 2 lines · Nathaniel Roach
Quoted 1 line · Arnout Vandecappelle
On 25-06-16 19:02, Nathaniel Roach wrote:
[snip]
Quoted 5 lines
Quoted 2 lines
However, since the Wants= is added for zebra, it would make sense to create the
zebra symlink, no?No, systemd will automatically start zebra when it's needed. It's not needed until one of the other daemons start (which systemd will start zebra beforehand if the daemon is local). If they are remote, the user can enable zebra themselves.
So, if there is a Wants=quagga at zebra.service line, then systemd will look for
quagga at zebra.service in /usr/lib/systemd/services, and failing that it will automatically try quagga at .service? Nice!
[snip]
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+Wants=quagga at zebra.service
I just realize now: this line should probably be removed when
BR2_PACKAGE_QUAGGA_ZEBRAis not set.Also true, however that's why I said Wants= and not Requires= so systemd handles the lack of zebra fine.
So in case zebra doesn't exist, systemd will still try to execute the service
file, but the ExecStart command will fail because /usr/sbin/zebra doesn't exist, right? But in that case, won't it retry every second (Restart=on-failure) and spam the journal horribly?
Maybe there should be a ConditionFileIsExecutable in the [Unit] section?
Regards,
Arnout
Signature · 6 lines
Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
PATCH 1/1 package/quagga: Add systemd.service file
Quoted 6 lines · Arnout Vandecappelle
(Mainly improving my systemd knowledge here :-)
Quoted 2 lines · Nathaniel Roach
Quoted 1 line · Arnout Vandecappelle
On 25-06-16 19:02, Nathaniel Roach wrote:
[snip]
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
However, since the Wants= is added for zebra, it would make sense to create the
zebra symlink, no?No, systemd will automatically start zebra when it's needed. It's not needed until one of the other daemons start (which systemd will start zebra beforehand if the daemon is local). If they are remote, the user can enable zebra themselves.
So, if there is a Wants=quagga at zebra.service line, then systemd will look for
quagga at zebra.service in/usr/lib/systemd/services, and failing that it will automatically try quagga at .service? Nice!
Pretty much! /etc/systemd/system/multi-user.target.wants/quagga at zebra.service is installed on systemctl enable [...] and it's just a symlink to quagga at .service
Quoted 4 lines
[snip]
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+Wants=quagga at zebra.service
I just realize now: this line should probably be removed when
BR2_PACKAGE_QUAGGA_ZEBRAis not set.
Quoted 8 lines
Quoted 2 lines
Also true, however that's why I said Wants= and not Requires= so systemd handles the lack of zebra fine.
So in case zebra doesn't exist, systemd will still try to execute the service
file, but the ExecStart command will fail because/usr/sbin/zebradoesn't exist, right? But in that case, won't it retry every second (Restart=on-failure) and spam the journal horribly?Maybe there should be a ConditionFileIsExecutable in the [Unit] section?
That was a good condition that I didn't think of. In that case the unit will fail and restart until it hits the start limit. I've since added in the Condition stanza and everything works as intended.
Quoted 6 lines
Regards,
Arnout
PATCH 1/1 package/quagga: Add systemd.service file
Hello,
Quoted 4 lines · Nathaniel Roach
Quoted 1 line
Maybe there should be a ConditionFileIsExecutable in the [Unit] section?
That was a good condition that I didn't think of. In that case the unit will fail and restart until it hits the start limit. I've since added in the Condition stanza and everything works as intended.
Could you send an updated version that takes into account Arnout's comments and especially the addition of this condition?
Thanks a lot!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com