From 50c3346c26f5e1da2d955b97c4638e3c0dea57d4 Mon Sep 17 00:00:00 2001 From: Julien Vaubourg Date: Wed, 30 Aug 2017 14:27:56 +0200 Subject: [PATCH] Use systemctl helper to avoid deadlocks with ynh 2.7 and check path avaibility with no deprecated method --- scripts/helpers | 39 +++++++++++++++++++++++++++++++++++++++ scripts/install | 12 +++++------- scripts/remove | 8 +++++--- scripts/upgrade | 3 ++- 4 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 scripts/helpers diff --git a/scripts/helpers b/scripts/helpers new file mode 100644 index 0000000..f91730f --- /dev/null +++ b/scripts/helpers @@ -0,0 +1,39 @@ +#!/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 + sudo 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 c38e26b..b7747be 100644 --- a/scripts/install +++ b/scripts/install @@ -25,14 +25,12 @@ domain=${1} url_path=${2} if ! $upgrade; then + source ./helpers source ./prerequisites fi # Check domain/path availability -sudo yunohost app checkurl ${domain}${url_path} -a vpnclient -if [ ! $? -eq 0 ]; then - exit 1 -fi +ynh_webpath_register vpnclient $domain $url_path || exit 1 # Install packages packages='php5-fpm sipcalc dnsutils openvpn curl' @@ -131,13 +129,13 @@ sudo systemctl reload nginx sudo systemctl enable ynh-vpnclient sudo yunohost service add ynh-vpnclient -sudo systemctl start ynh-vpnclient-checker.service +ynh_systemctl start ynh-vpnclient-checker.service sudo systemctl enable ynh-vpnclient-checker.service -sudo systemctl start ynh-vpnclient-checker.timer +ynh_systemctl start ynh-vpnclient-checker.timer sudo systemctl enable ynh-vpnclient-checker.timer if ! $upgrade; then - sudo systemctl start ynh-vpnclient + ynh_systemctl start ynh-vpnclient # Check configuration consistency diff --git a/scripts/remove b/scripts/remove index 4b707d5..1d92f61 100644 --- a/scripts/remove +++ b/scripts/remove @@ -17,15 +17,17 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +source ./helpers + # Retrieve arguments domain=$(sudo yunohost app setting vpnclient domain) # The End -sudo systemctl stop ynh-vpnclient-checker.service +ynh_systemctl stop ynh-vpnclient-checker.service sudo systemctl disable ynh-vpnclient-checker.service -sudo systemctl stop ynh-vpnclient-checker.timer && sleep 1 +ynh_systemctl stop ynh-vpnclient-checker.timer && sleep 1 sudo systemctl disable ynh-vpnclient-checker.timer -sudo systemctl stop ynh-vpnclient +ynh_systemctl stop ynh-vpnclient sudo systemctl disable ynh-vpnclient sudo yunohost service remove ynh-vpnclient sudo rm -f /etc/systemd/system/ynh-vpnclient* /usr/local/bin/ynh-vpnclient* diff --git a/scripts/upgrade b/scripts/upgrade index d42eccb..6d4dd7b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ ynh_setting() { sudo grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$// } +source ./helpers source ./prerequisites domain=$(ynh_setting vpnclient domain) @@ -41,6 +42,6 @@ if [ -z "$(ynh_setting vpnclient dns0)" ]; then sudo yunohost app setting vpnclient dns1 -v 2001:913::8 fi -sudo systemctl start ynh-vpnclient +ynh_systemctl start ynh-vpnclient exit 0