Last active
April 6, 2020 15:31
-
-
Save TBK/0c40903abe32b4e0ac79be48998803df to your computer and use it in GitHub Desktop.
WireGuard openrc-run service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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