Parcourir la source

Add vpnclient checker timer and upgrade backups, to enable Bram to sleep better

Julien Vaubourg il y a 8 ans
Parent
commit
453fababef

+ 8 - 0
conf/ynh-vpnclient-checker.service

@@ -0,0 +1,8 @@
+[Unit]
+Description=YunoHost VPN Client Checker.
+Requires=ynh-vpnclient.service
+After=ynh-vpnclient.service
+
+[Service]
+Type=simple
+ExecStart=/usr/local/bin/ynh-vpnclient-checker.sh

+ 7 - 0
conf/ynh-vpnclient-checker.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+if ! ip link show tun0 &> /dev/null; then
+  systemctl restart ynh-vpnclient &> /dev/null
+fi
+
+exit 0

+ 8 - 0
conf/ynh-vpnclient-checker.timer

@@ -0,0 +1,8 @@
+[Unit]
+Description=Run VPN Client Checker every 5 minutes.
+
+[Timer]
+OnUnitActiveSec=5min
+ 
+[Install]
+WantedBy=timers.target

+ 8 - 0
scripts/install

@@ -112,6 +112,11 @@ sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/vpnadmin/config.php
 sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient /usr/local/bin/
 sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient.service /etc/systemd/system/
 
+# Copy checker timer
+sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient-checker.sh /usr/local/bin/
+sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.service /etc/systemd/system/
+sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.timer /etc/systemd/system/
+
 # Set default inits
 # The boot order of these services are important, so they are disabled by default
 # and the ynh-vpnclient service handles them.
@@ -126,6 +131,9 @@ sudo systemctl reload nginx
 sudo systemctl enable ynh-vpnclient
 sudo yunohost service add ynh-vpnclient
 
+sudo systemctl start ynh-vpnclient-checker.timer
+sudo systemctl enable ynh-vpnclient-checker.timer
+
 if ! $upgrade; then
   sudo systemctl start ynh-vpnclient
 

+ 2 - 2
scripts/remove

@@ -21,10 +21,11 @@
 domain=$(sudo yunohost app setting vpnclient domain)
 
 # The End
+sudo systemctl disable ynh-vpnclient-checker.timer && sleep 1
 sudo systemctl stop ynh-vpnclient
 sudo systemctl disable ynh-vpnclient
 sudo yunohost service remove ynh-vpnclient
-sudo rm -f /etc/systemd/system/ynh-vpnclient.service /usr/local/bin/ynh-vpnclient
+sudo rm -f /etc/systemd/system/ynh-vpnclient* /usr/local/bin/ynh-vpnclient*
 sudo rm -f /tmp/.ynh-vpnclient-*
 
 # Remove confs
@@ -33,7 +34,6 @@ sudo rm -f /etc/nginx/conf.d/${domain}.d/vpnadmin.conf
 sudo rm -f /etc/php5/fpm/pool.d/vpnadmin.conf
 sudo rm -f /etc/yunohost/hooks.d/90-vpnclient.tpl
 sudo rm -f /etc/systemd/system/openvpn@.service
-sudo rm -f /usr/local/bin/ynh-vpnclient-loadcubefile.sh
 
 # Remove certificates
 sudo rm -rf /etc/openvpn/keys/

+ 11 - 10
scripts/upgrade

@@ -9,28 +9,29 @@ ynh_setting() {
 
 source ./prerequisites
 
+cachedir=/var/cache/labriqueinternet/
 domain=$(ynh_setting vpnclient domain)
 path=$(ynh_setting vpnclient path)
 server_name=$(ynh_setting vpnclient server_name)
 
-tmpdir=$(mktemp -dp /tmp/ vpnclient-upgrade-XXXXX)
-sudo cp -a /etc/yunohost/apps/vpnclient/settings.yml "${tmpdir}/"
-sudo cp -a /etc/openvpn/keys/ "${tmpdir}/"
+sudo mkdir -m 0700 -p "${cachedir}/vpnclient/"
+backupdir=$(mktemp -dp ${cachedir}/vpnclient/ upgrade_$(date +%Y-%m-%d-%H%M%S)_XXXXX)
+
+sudo tar czf "${backupdir}/etc_openvpn.tgz" /etc/openvpn/
+sudo cp -a /etc/yunohost/apps/vpnclient/settings.yml "${backupdir}/"
+sudo cp -a /etc/openvpn/keys/ "${backupdir}/"
 
 if [ ! -e /etc/openvpn/client.conf.tpl.restore ] || ! cmp -s /etc/openvpn/client.conf.tpl{,.restore}; then
-  sudo cp -a /etc/openvpn/client.conf.tpl "${tmpdir}/"
+  sudo cp -a /etc/openvpn/client.conf.tpl "${backupdir}/"
 fi
 
 export VPNCLIENT_UPGRADE=1
-echo "Current path: $PWD"
 sudo bash /etc/yunohost/apps/vpnclient/scripts/remove &> /dev/null
-echo "Current path: $PWD"
 bash ./install "${domain}" "${path}" "${server_name}"
 
-sudo cp -a "${tmpdir}/settings.yml" /etc/yunohost/apps/vpnclient/
-sudo cp -a "${tmpdir}/keys/"* /etc/openvpn/keys/ 2> /dev/null
-sudo cp -a "${tmpdir}/client.conf.tpl" /etc/openvpn/ 2> /dev/null
-sudo rm -r "${tmpdir}/"
+sudo cp -a "${backupdir}/settings.yml" /etc/yunohost/apps/vpnclient/
+sudo cp -a "${backupdir}/keys/"* /etc/openvpn/keys/ 2> /dev/null
+sudo cp -a "${backupdir}/client.conf.tpl" /etc/openvpn/ 2> /dev/null
 
 # Changes