Merge pull request #29 from labriqueinternet/tests_upgrades

Add kind of backups when upgrading, and add a timer to be sure to have vpnclient started
This commit is contained in:
Julien Vaubourg 2016-08-14 23:45:10 +02:00 committed by GitHub
commit 0ce8634736
7 changed files with 47 additions and 3 deletions

View File

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

View File

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

View File

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

View File

@ -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 0755 ../conf/ynh-vpnclient /usr/local/bin/
sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient.service /etc/systemd/system/ 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 # Set default inits
# The boot order of these services are important, so they are disabled by default # The boot order of these services are important, so they are disabled by default
# and the ynh-vpnclient service handles them. # and the ynh-vpnclient service handles them.
@ -126,6 +131,11 @@ sudo systemctl reload nginx
sudo systemctl enable ynh-vpnclient sudo systemctl enable ynh-vpnclient
sudo yunohost service add ynh-vpnclient sudo yunohost service add ynh-vpnclient
sudo systemctl start ynh-vpnclient-checker.service
sudo systemctl enable ynh-vpnclient-checker.service
sudo systemctl start ynh-vpnclient-checker.timer
sudo systemctl enable ynh-vpnclient-checker.timer
if ! $upgrade; then if ! $upgrade; then
sudo systemctl start ynh-vpnclient sudo systemctl start ynh-vpnclient

View File

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

View File

@ -13,6 +13,9 @@ domain=$(ynh_setting vpnclient domain)
path=$(ynh_setting vpnclient path) path=$(ynh_setting vpnclient path)
server_name=$(ynh_setting vpnclient server_name) server_name=$(ynh_setting vpnclient server_name)
sudo mkdir -m 0700 -p /var/cache/labriqueinternet/vpnclient/
sudo tar czf "/var/cache/labriqueinternet/vpnclient/rollback_$(date +%Y-%m-%d-%H%M%S).tgz" /etc/openvpn/ /etc/yunohost/apps/vpnclient/ &> /dev/null
tmpdir=$(mktemp -dp /tmp/ vpnclient-upgrade-XXXXX) tmpdir=$(mktemp -dp /tmp/ vpnclient-upgrade-XXXXX)
sudo cp -a /etc/yunohost/apps/vpnclient/settings.yml "${tmpdir}/" sudo cp -a /etc/yunohost/apps/vpnclient/settings.yml "${tmpdir}/"
sudo cp -a /etc/openvpn/keys/ "${tmpdir}/" sudo cp -a /etc/openvpn/keys/ "${tmpdir}/"
@ -25,8 +28,9 @@ export VPNCLIENT_UPGRADE=1
sudo bash /etc/yunohost/apps/vpnclient/scripts/remove &> /dev/null sudo bash /etc/yunohost/apps/vpnclient/scripts/remove &> /dev/null
bash ./install "${domain}" "${path}" "${server_name}" bash ./install "${domain}" "${path}" "${server_name}"
sudo rmdir /etc/openvpn/keys/
sudo cp -a "${tmpdir}/keys/" /etc/openvpn/keys/
sudo cp -a "${tmpdir}/settings.yml" /etc/yunohost/apps/vpnclient/ 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 cp -a "${tmpdir}/client.conf.tpl" /etc/openvpn/ 2> /dev/null
sudo rm -r "${tmpdir}/" sudo rm -r "${tmpdir}/"

View File

@ -31,10 +31,12 @@ function ynh_setting_set($setting, $value) {
} }
function stop_service() { function stop_service() {
touch('/tmp/.ynh-vpnclient-stopped');
exec('sudo systemctl stop ynh-vpnclient'); exec('sudo systemctl stop ynh-vpnclient');
} }
function start_service() { function start_service() {
unlink('/tmp/.ynh-vpnclient-stopped');
exec('sudo systemctl start ynh-vpnclient', $output, $retcode); exec('sudo systemctl start ynh-vpnclient', $output, $retcode);
return $retcode; return $retcode;