Rework and cleanup systemd service handling (#294)

* Don't hardcode server.conf in systemd service

* Rework and cleanup service handling
This commit is contained in:
Stanislas 2018-09-18 14:55:00 +02:00 committed by GitHub
parent 1cd80a5cc7
commit 136a46874e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -781,37 +781,23 @@ verb 3" >> /etc/openvpn/server.conf
fi fi
fi fi
# And finally, restart OpenVPN # Finally, restart and enable OpenVPN
if [[ "$OS" = 'debian' ]]; then if [[ "$OS" = 'fedora' ]]; then
# Little hack to check for systemd # Workaround to fix OpenVPN service on OpenVZ
if pgrep systemd-journal; then sed -i 's|LimitNPROC|#LimitNPROC|' /usr/lib/systemd/system/openvpn-server@.service
#Workaround to fix OpenVPN service on OpenVZ # Another workaround to keep using /etc/openvpn/
sed -i 's|LimitNPROC|#LimitNPROC|' /lib/systemd/system/openvpn\@.service sed -i 's|/etc/openvpn/server|/etc/openvpn|' /usr/lib/systemd/system/openvpn-server@.service
sed -i 's|/etc/openvpn/server|/etc/openvpn|' /lib/systemd/system/openvpn\@.service systemctl daemon-reload
sed -i 's|%i.conf|server.conf|' /lib/systemd/system/openvpn\@.service systemctl restart openvpn-server@server
systemctl daemon-reload systemctl enable openvpn-server@server
systemctl restart openvpn
systemctl enable openvpn
else
/etc/init.d/openvpn restart
fi
else else
if pgrep systemd-journal; then # Workaround to fix OpenVPN service on OpenVZ
if [[ "$OS" = 'fedora' ]]; then sed -i 's|LimitNPROC|#LimitNPROC|' /lib/systemd/system/openvpn\@.service
# Workaround to avoid rewriting the entire script for Fedora # Another workaround to keep using /etc/openvpn/
sed -i 's|/etc/openvpn/server|/etc/openvpn|' /usr/lib/systemd/system/openvpn-server@.service sed -i 's|/etc/openvpn/server|/etc/openvpn|' /lib/systemd/system/openvpn\@.service
sed -i 's|%i.conf|server.conf|' /usr/lib/systemd/system/openvpn-server@.service systemctl daemon-reload
systemctl daemon-reload systemctl restart openvpn@server
systemctl restart openvpn-server@openvpn.service systemctl enable openvpn@server
systemctl enable openvpn-server@openvpn.service
else
systemctl restart openvpn@server.service
systemctl enable openvpn@server.service
fi
else
service openvpn restart
chkconfig openvpn on
fi
fi fi
# If the server is behind a NAT, use the correct IP address # If the server is behind a NAT, use the correct IP address