From 367007267f46b2a91fc15a2a8671b7974e6fd28b Mon Sep 17 00:00:00 2001 From: Marvin Steadfast Date: Mon, 25 Jan 2021 10:53:58 +0100 Subject: [PATCH] adds init files --- init/openrc/wg-quicker.init | 33 ++++++++++++++++++++++++++++++++ init/systemd/wg-quicker@.service | 16 ++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 init/openrc/wg-quicker.init create mode 100644 init/systemd/wg-quicker@.service diff --git a/init/openrc/wg-quicker.init b/init/openrc/wg-quicker.init new file mode 100644 index 0000000..13c163f --- /dev/null +++ b/init/openrc/wg-quicker.init @@ -0,0 +1,33 @@ +#!/sbin/openrc-run + +name="WireGuard" +description="WireGuard via wg-quicker" + +depend() { + need net + use dns +} + +CONF="${SVCNAME#*.}" + +checkconfig() { + if [ "$CONF" = "$SVCNAME" ]; then + eerror "You cannot call this init script directly. You must create a symbolic link to it with the configuration name:" + eerror " ln -s /etc/init.d/wg-quicker /etc/init.d/wg-quicker.vpn0" + eerror "And then call it instead:" + eerror " /etc/init.d/wg-quicker.vpn0 start" + return 1 + fi +} + +start() { + ebegin "Starting $description for $CONF" + wg-quicker up "$CONF" + eend $? "Failed to start $description for $CONF" +} + +stop() { + ebegin "Stopping $description for $CONF" + wg-quicker down "$CONF" + eend $? "Failed to stop $description for $CONF" +} diff --git a/init/systemd/wg-quicker@.service b/init/systemd/wg-quicker@.service new file mode 100644 index 0000000..e3f3357 --- /dev/null +++ b/init/systemd/wg-quicker@.service @@ -0,0 +1,16 @@ +[Unit] +Description=WireGuard via wg-quicker for %I +After=network-online.target nss-lookup.target +Wants=network-online.target nss-lookup.target +PartOf=wg-quick.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/bin/wg-quicker up %i +ExecStop=/usr/local/bin/wg-quicker down %i +ExecReload=/usr/bin/local/wg-quicker sync %i + +[Install] +WantedBy=multi-user.target +