[PATCH] tools: add wireguard at .service

Florian Klink flokli at flokli.de
Fri May 26 10:44:23 CEST 2017


If you simply want to create wireguard interfaces and configure them,
wg-quick might be too much, as it also configures Addresses, MTU and
adds routes. This unit file can be used in cases where you want to use
wg(8) to configure the wireguard interface, but do regular network
configuration on top of the link by something else (possibly not knowing
wireguard, like systemd-networkd or NetworkManager.

Signed-off-by: Florian Klink <flokli at flokli.de>
---
 src/tools/Makefile           |  3 ++-
 src/tools/wireguard at .service | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 src/tools/wireguard at .service

diff --git a/src/tools/Makefile b/src/tools/Makefile
index 2dd7f6a..5206832 100644
--- a/src/tools/Makefile
+++ b/src/tools/Makefile
@@ -51,6 +51,7 @@ clean:
 install: wg
 	@install -v -d "$(DESTDIR)$(BINDIR)" && install -m 0755 -v wg "$(DESTDIR)$(BINDIR)/wg"
 	@install -v -d "$(DESTDIR)$(MANDIR)/man8" && install -m 0644 -v wg.8 "$(DESTDIR)$(MANDIR)/man8/wg.8"
+	[ "$(WITH_SYSTEMDUNITS)" = "yes" ] && install -v -d "$(DESTDIR)$(SYSTEMDUNITDIR)" && install -m 0644 -v wireguard at .service "$(DESTDIR)$(SYSTEMDUNITDIR)/wireguard at .service"
 	@[ "$(WITH_BASHCOMPLETION)" = "yes" ] || exit 0; \
 	install -v -d "$(DESTDIR)$(BASHCOMPDIR)" && install -m 0644 -v completion/wg.bash-completion "$(DESTDIR)$(BASHCOMPDIR)/wg"
 	@[ "$(WITH_WGQUICK)" = "yes" ] || exit 0; \
@@ -60,7 +61,7 @@ install: wg
 	@[ "$(WITH_WGQUICK)" = "yes" -a "$(WITH_BASHCOMPLETION)" = "yes" ] || exit 0; \
 	install -m 0644 -v completion/wg-quick.bash-completion "$(DESTDIR)$(BASHCOMPDIR)/wg-quick"
 	@[ "$(WITH_WGQUICK)" = "yes" -a "$(WITH_SYSTEMDUNITS)" = "yes" ] || exit 0; \
-	install -v -d "$(DESTDIR)$(SYSTEMDUNITDIR)" && install -m 0644 -v wg-quick at .service "$(DESTDIR)$(SYSTEMDUNITDIR)/wg-quick at .service"
+	install -m 0644 -v wg-quick at .service "$(DESTDIR)$(SYSTEMDUNITDIR)/wg-quick at .service"
 
 check: clean
 	CFLAGS=-g scan-build --view --keep-going $(MAKE) wg
diff --git a/src/tools/wireguard at .service b/src/tools/wireguard at .service
new file mode 100644
index 0000000..b6d53bf
--- /dev/null
+++ b/src/tools/wireguard at .service
@@ -0,0 +1,19 @@
+[Unit]
+Description=WireGuard via wg(8) for %I
+After=network-online.target
+Wants=network-online.target
+Documentation=man:wg(8)
+Documentation=https://www.wireguard.io/
+Documentation=https://www.wireguard.io/quickstart/
+Documentation=https://git.zx2c4.com/WireGuard/about/src/tools/wg.8
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStartPre=/sbin/ip link add dev %i type wireguard
+ExecStart=/usr/bin/wg setconf %i /etc/wireguard/%i.conf
+ExecStop=/sbin/ip link del %i
+ExecReload=/usr/bin/wg setconf %i /etc/wireguard/%i.conf
+
+[Install]
+WantedBy=multi-user.target
-- 
2.13.0



More information about the WireGuard mailing list