Skip to content

Instantly share code, notes, and snippets.

@TBK
Last active April 6, 2020 15:31
Show Gist options
  • Save TBK/0c40903abe32b4e0ac79be48998803df to your computer and use it in GitHub Desktop.
Save TBK/0c40903abe32b4e0ac79be48998803df to your computer and use it in GitHub Desktop.
WireGuard openrc-run service
#!/sbin/openrc-run
description="WireGuard VPN tunnel"
required_dirs="/etc/wireguard"
extra_started_commands="up down"
depend() {
need localmount net
use dns
after bootmisc
}
start_pre() {
modinfo wireguard
return $?
}
start() {
ip link add dev ${WG_IFACE} type wireguard
ip address add dev ${WG_IFACE} ${WG_ADDR}
wg setconf ${WG_IFACE} /etc/wireguard/${WG_IFACE}.conf
for conf in /etc/wireguard/peers.d/*
do
wg addconf ${WG_IFACE} ${conf}
done
up
}
up() {
ip link set ${WG_IFACE} up
}
down() {
ip link set ${WG_IFACE} down
}
stop() {
down
ip link delete ${WG_IFACE} type wireguard
}
status() {
if [[ service_started ]]
then
wg
else
einfo "Service is not started."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment