Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config re-sync instead of full wireguard restart #316

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart wg-quick@wg0.service
ExecStart=/bin/bash /DIR-TO-RESTART-FILE/restart-wg.sh

[Install]
RequiredBy=wgui.path
Expand Down
27 changes: 27 additions & 0 deletions restart-wg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

config="/etc/wireguard/wg0.conf"
old_config="/etc/wireguard/wg0.conf.old"

if [ ! -f $old_config ]; then
awk '/Interface/,/# ID:/' $config | head -n -1 | tail -n +2 > $old_config
echo "No old config found, restarting wireguard (wg-quick)"
wg-quick down wg0
systemctl restart wg-quick@wg0.service
exit 0
fi

difference=$(diff <(awk '/Interface/,/# ID:/' $config | head -n -1 | tail -n +2) <(cat $old_config))

if [ -n "$difference" ]; then
awk '/Interface/,/# ID:/' $config | head -n -1 | tail -n +2 > $old_config
echo "Changes to interface detected, restarting wireguard (wg-quick)"
wg-quick down wg0
systemctl restart wg-quick@wg0.service
exit 0
else
awk '/Interface/,/# ID:/' $config | head -n -1 | tail -n +2 > $old_config
echo "No changes to interface detected, restarting wireguard (wg syncconf)"
wg syncconf wg0 <(wg-quick strip wg0)
exit 0
fi