Last active
August 29, 2015 14:22
-
-
Save Mic92/3f25e1b99997e845e148 to your computer and use it in GitHub Desktop.
Restart openvpn connection after systemd suspend
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
#!/bin/sh | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
if ! which systemctl >/dev/null; then | |
echo "No systemctl found, systemd is required for this files" 1>&2 | |
exit 1 | |
fi | |
echo "install /etc/systemd/system/openvpn-sleep.service" | |
mkdir -p "/etc/systemd/system/" | |
cat > /etc/systemd/system/openvpn-sleep.service <<EOF | |
[Unit] | |
Description=Suspend openvpn | |
Before=sleep.target | |
StopWhenUnneeded=yes | |
[Service] | |
Type=oneshot | |
RemainAfterExit=yes | |
ExecStart=/usr/bin/true | |
ExecStop=/usr/bin/bash -c "while sleep 0.1; do ping6 -W1 -c3 2001:4860:4860::8888 || ping -W1 -c3 8.8.8.8 && break; done && pkill -USR1 openvpn" | |
[Install] | |
WantedBy=sleep.target | |
EOF | |
systemctl daemon-reload | |
systemctl enable openvpn-sleep.service | |
echo "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment