Browse Source

Use systemctl helper to avoid deadlocks with ynh 2.7 and check path avaibility with no deprecated method

Julien Vaubourg 7 years ago
parent
commit
50c3346c26
4 changed files with 51 additions and 11 deletions
  1. 39 0
      scripts/helpers
  2. 5 7
      scripts/install
  3. 5 3
      scripts/remove
  4. 2 1
      scripts/upgrade

+ 39 - 0
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
+}

+ 5 - 7
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
   

+ 5 - 3
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 <http://www.gnu.org/licenses/>.
 
+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*

+ 2 - 1
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