From 7646ffbb289c2b60418d390cfdfbd65ef8c71267 Mon Sep 17 00:00:00 2001 From: keoma Date: Sun, 24 Feb 2019 21:41:06 +0100 Subject: [PATCH] fix #50 --- manifest.json | 4 ++-- scripts/_common.sh | 36 +----------------------------------- scripts/helpers | 39 --------------------------------------- scripts/install | 30 +++++++++++++++++++----------- scripts/remove | 29 ++++++++++++++++++++--------- scripts/upgrade | 45 +++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 83 insertions(+), 100 deletions(-) delete mode 100644 scripts/helpers diff --git a/manifest.json b/manifest.json index bbcbac3..d8ad69f 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name": "VPN Client", "id": "vpnclient", "packaging_format": 1, - "version": "1.3.1", + "version": "1.3.2", "description": { "en": "Tunnel the internet traffic through a VPN", "fr": "Fais passer le traffic internet à travers un VPN" @@ -14,7 +14,7 @@ }, "multi_instance": false, "requirements": { - "yunohost": ">= 2.7.0" + "yunohost": ">= 3.2.0" }, "services": [ "nginx", diff --git a/scripts/_common.sh b/scripts/_common.sh index a05ae5c..0f01b88 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -57,41 +57,6 @@ ynh_abort_if_up_to_date () { fi } -# Helper to start/stop/.. a systemd service from a yunohost context, -# *and* the systemd service itself needs to be able to run yunohost -# commands. -# -# Hence the need to release the lock during the operation -# -# usage : ynh_systemctl yolo restart -# -function ynh_systemctl() -{ - local ACTION="$1" - local SERVICE="$2" - local LOCKFILE="/var/run/moulinette_yunohost.lock" - - # Launch the action - systemctl "$ACTION" "$SERVICE" & - local SYSCTLACTION=$! - - # Save and release the lock... - cp $LOCKFILE $LOCKFILE.bkp.$$ - rm $LOCKFILE - - # Wait for the end of the action - wait $SYSCTLACTION - - # Make sure the lock is released... - while [ -f $LOCKFILE ] - do - sleep 0.1 - done - - # Restore the old lock - mv $LOCKFILE.bkp.$$ $LOCKFILE -} - # Read the value of a key in a ynh manifest file # # usage: ynh_read_manifest manifest key @@ -244,5 +209,6 @@ function vpnclient_deploy_files_and_services() install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.service /etc/systemd/system/ install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.timer /etc/systemd/system/ + # Reload systemd configuration systemctl daemon-reload } diff --git a/scripts/helpers b/scripts/helpers deleted file mode 100644 index 86c15fe..0000000 --- a/scripts/helpers +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -source /usr/share/yunohost/helpers - -# -# Helper to start/stop/.. a systemd service from a yunohost context, -# *and* the systemd service itself needs to be able to run yunohost -# commands. -# -# Hence the need to release the lock during the operation -# -# usage : ynh_systemctl yolo restart -# -function ynh_systemctl() -{ - local ACTION="$1" - local SERVICE="$2" - local LOCKFILE="/var/run/moulinette_yunohost.lock" - - # Launch the action - systemctl "$ACTION" "$SERVICE" & - local SYSCTLACTION=$! - - # Save and release the lock... - cp $LOCKFILE $LOCKFILE.bkp.$$ - rm $LOCKFILE - - # Wait for the end of the action - wait $SYSCTLACTION - - # Make sure the lock is released... - while [ -f $LOCKFILE ] - do - sleep 0.1 - done - - # Restore the old lock - mv $LOCKFILE.bkp.$$ $LOCKFILE -} diff --git a/scripts/install b/scripts/install index 5630a94..f7e7c80 100644 --- a/scripts/install +++ b/scripts/install @@ -1,19 +1,19 @@ #!/bin/bash -# VPN Client app for YunoHost +# VPN Client app for YunoHost # Copyright (C) 2015 Julien Vaubourg # Contribute at https://github.com/labriqueinternet/vpnclient_ynh -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . @@ -43,6 +43,9 @@ path_url=$(ynh_normalize_url_path "$2") app=$YNH_APP_INSTANCE_NAME final_path="/var/www/$app" +service_name="ynh-vpnclient" +service_checker_name=$service_name"-checker" + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -77,7 +80,7 @@ vpnclient_deploy_files_and_services "${domain}" "${app}" # Set default inits # The boot order of these services are important, so they are disabled by default -# and the ynh-vpnclient service handles them. +# and the vpnclient service handles them. systemctl disable openvpn systemctl stop openvpn @@ -86,12 +89,17 @@ systemctl restart php5-fpm systemctl reload nginx -systemctl enable ynh-vpnclient -yunohost service add ynh-vpnclient +# main service -ynh_systemctl start ynh-vpnclient-checker.service -systemctl enable ynh-vpnclient-checker.service -ynh_systemctl start ynh-vpnclient-checker.timer -systemctl enable ynh-vpnclient-checker.timer +yunohost service add $service_name --description "tunnels the internet traffic through a VPN" --need_lock +yunohost service enable $service_name + +# checker service + +yunohost service add $service_checker_name --description "makes sure that the VPN service is running" --need_lock +yunohost service start $service_checker_name +yunohost service enable $service_checker_name +systemctl start $service_checker_name.timer +systemctl enable $service_checker_name.timer yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index 074108f..054fe96 100644 --- a/scripts/remove +++ b/scripts/remove @@ -33,16 +33,24 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) +service_name="ynh-vpnclient" +service_checker_name=$service_name"-checker" + #================================================= -# The End -ynh_systemctl stop ynh-vpnclient-checker.service -systemctl disable ynh-vpnclient-checker.service -ynh_systemctl stop ynh-vpnclient-checker.timer && sleep 1 -systemctl disable ynh-vpnclient-checker.timer -ynh_systemctl stop ynh-vpnclient -systemctl disable ynh-vpnclient -yunohost service remove ynh-vpnclient -for FILE in $(ls /etc/systemd/system/ynh-vpnclient* /usr/local/bin/ynh-vpnclient* /tmp/.ynh-vpnclient-*) + +# Stop and remove yunohost services + +yunohost service stop $service_checker_name +yunohost service disable $service_checker_name +yunohost service remove $service_checker_name +systemctl stop $service_checker_name.timer && sleep 1 +systemctl disable $service_checker_name.timer + +yunohost service stop $service_name +yunohost service disable $service_name +yunohost service remove $service_name + +for FILE in $(ls /etc/systemd/system/$service_name* /usr/local/bin/ynh-vpnclient* /tmp/.ynh-vpnclient-*) do ynh_secure_remove "$FILE" done @@ -65,6 +73,9 @@ ynh_remove_app_dependencies # Remove sources ynh_secure_remove "/var/www/${app}" +# Reload systemd configuration +systemctl daemon-reload + # Restart services # (this must happen before deleting the user, otherwise the user is # being used by one of the php pool process) diff --git a/scripts/upgrade b/scripts/upgrade index 4faf2a7..91ff50b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,6 +21,9 @@ is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) server_name=$(ynh_app_setting_get $app server_name) +service_name="ynh-vpnclient" +service_checker_name=$service_name"-checker" + #================================================= # SPECIAL UPGRADE FOR VERSIONS < 1.2.0 #================================================= @@ -83,10 +86,44 @@ ynh_secure_remove ${tmpdir} # RELOAD RELEVANT SERVICES #================================================= -ynh_systemctl reload php5-fpm -ynh_systemctl reload nginx +systemctl reload php5-fpm +systemctl reload nginx -if systemctl is-active ynh-vpnclient >/dev/null; +### Make sure that the yunohost services have a description and need-lock enabled + +# main service + +yunohost service remove $service_name +yunohost service add $service_name --description "tunnels the internet traffic through a VPN" --need_lock + +# checker service + +yunohost service remove $service_checker_name +yunohost service add $service_checker_name --description "makes sure that the VPN service is running" --need_lock + +# Reload systemd configuration + +systemctl daemon-reload + +### Restart services + +# restart main service if needed + +if systemctl is-active $service_name >/dev/null; then - ynh_systemctl restart ynh-vpnclient + yunohost service restart $service_name +fi + +# restart checker service if needed + +if systemctl is-active $service_checker_name >/dev/null; +then + yunohost service restart $service_checker_name +fi + +# restart checker service timer + +if systemctl is-active $service_name.timer >/dev/null; +then + yunohost service restart $service_checker_name.timer fi