keoma 6 years ago
parent
commit
7646ffbb28
6 changed files with 83 additions and 100 deletions
  1. 2 2
      manifest.json
  2. 1 35
      scripts/_common.sh
  3. 0 39
      scripts/helpers
  4. 19 11
      scripts/install
  5. 20 9
      scripts/remove
  6. 41 4
      scripts/upgrade

+ 2 - 2
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",

+ 1 - 35
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
 }

+ 0 - 39
scripts/helpers

@@ -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
-}

+ 19 - 11
scripts/install

@@ -1,19 +1,19 @@
 #!/bin/bash
 
-# VPN Client app for YunoHost 
+# VPN Client app for YunoHost
 # Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
 # 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 <http://www.gnu.org/licenses/>.
 
@@ -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
+
+yunohost service add $service_name --description "tunnels the internet traffic through a VPN" --need_lock
+yunohost service enable $service_name
+
+# checker 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_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

+ 20 - 9
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)

+ 41 - 4
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
+
+### 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
+    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 ynh-vpnclient >/dev/null;
+if systemctl is-active $service_name.timer >/dev/null;
 then
-    ynh_systemctl restart ynh-vpnclient
+    yunohost service restart $service_checker_name.timer
 fi