Browse Source

Fixes #5269 Several problems with postinstall script's function enforce_redis ()

Co-authored-by: Tarek Shehab <tsh@zammad.com>
Tarek Shehab 6 months ago
parent
commit
d265d57954
2 changed files with 46 additions and 13 deletions
  1. 5 1
      .pkgr.yml
  2. 41 12
      contrib/packager.io/functions

+ 5 - 1
.pkgr.yml

@@ -108,6 +108,10 @@ targets:
       - libImlib2-1
       - imlib2
       - shared-mime-info
+      # We need the fuser binary from the psmisc package to detect the running redis systemd service.
+      # Because on SUSE systems, this service is arbitrarily named (e.g.) redis@foobar.service
+      # So we cannot hardcode the service name as we do for other supported distros.
+      - psmisc
     build_dependencies:
       # Add packages required for build that are not in the official SLES repo.
       # Direct URLs must be used since we cannot add repos on packager.io
@@ -132,4 +136,4 @@ services:
   - redis
 before_install: contrib/packager.io/preinstall.sh
 after_install: contrib/packager.io/postinstall.sh
-buildpack: https://github.com/zammad/heroku-buildpack-multi.git#master
+buildpack: https://github.com/zammad/heroku-buildpack-multi.git#master

+ 41 - 12
contrib/packager.io/functions

@@ -229,9 +229,29 @@ function create_webserver_config () {
 }
 
 function enforce_redis () {
+  REDIS_URL=$(zammad config:get REDIS_URL)
   if [ -n "${REDIS_URL}" ]; then
-    echo "# Redis URL ${REDIS_URL} found."
-    return 0
+    echo "# REDIS_URL variable set to ${REDIS_URL}."
+    if ! echo ${REDIS_URL} | grep -E 'redis://([a-zA-Z0-9.-]+|[0-9]{1,3}(\.[0-9]{1,3}){3}):[0-9]+/?' > /dev/null; then
+	    echo "ERROR - Malformed REDIS_URL."
+	    echo -e "REDIS_URL must follow one of these formats:\nredis://<fqdn>:<port_number>\nredis://<ip_address>:<port_number>"
+	    exit 1
+    else
+      echo "# Performing connection check."
+      REDIS_URL_HOST=$(echo ${REDIS_URL} | cut -d'/' -f3 | cut -d':' -f1)
+      REDIS_URL_PORT=$(echo ${REDIS_URL} | cut -d'/' -f3 | cut -d':' -f2)
+      if echo 2> /dev/null > /dev/tcp/$REDIS_URL_HOST/$REDIS_URL_PORT; then
+        echo "# Connection check successful."
+        return 0
+      else
+        echo "# Connection check unsuccessful."
+        echo "ERROR - No redis server found at ${REDIS_URL}."
+        echo "Please install Redis following the instructions at https://redis.io/docs/getting-started/ or set the REDIS_URL environment variable with the following command."
+        echo -e "zammad config:set REDIS_URL=redis://your.redis.server:6379\n"
+        echo "Please fix these issues, then run the package installation again."
+        exit 1
+      fi
+    fi
   fi
 
   echo "# Enforcing Redis..."
@@ -239,6 +259,20 @@ function enforce_redis () {
   local REDIS_SERVICE_NAME=""
   if [ "${OS}" == "DEBIAN" ]; then
       REDIS_SERVICE_NAME="redis-server"
+  elif [ "${OS}" == "SUSE" ]; then
+      REDIS_PID=$(fuser 6379/tcp 2> /dev/null)
+      if [ -z "${REDIS_PID}" ]; then
+        echo -e "ERROR - SUSE Linux detected but no running redis-instance listening on port 6379 or REDIS_URL set.\n"
+        echo "SUSE Linux uses a systemd template for its redis package."
+        echo "If redis was installed via zypper, please make sure an instance of its template-service is running (e.g. redis@zammad.service) and it is listening on port 6379."
+        echo "Alternatively, you can set the REDIS_URL environment variable with the following command."
+        echo -e "zammad config:set REDIS_URL=redis://your.redis.server:6379\n"
+        echo "Please fix these issues, then run the package installation again."
+        exit 1
+      else
+        REDIS_SERVICE_NAME=$(ps -p $REDIS_PID -o unit=)
+        echo "# Redis service ${REDIS_SERVICE_NAME} detected."
+      fi
   else
       REDIS_SERVICE_NAME="redis"
   fi
@@ -248,20 +282,15 @@ function enforce_redis () {
     ${INIT_CMD} enable ${REDIS_SERVICE_NAME}
 
     echo "# Starting Redis server"
-    ${INIT_CMD} restart ${REDIS_SERVICE_NAME}
-    if [ $? -eq 0 ]; then
+    if ${INIT_CMD} restart ${REDIS_SERVICE_NAME}; then
       echo "# Redis server is running."
       return 0
+    else
+      echo -e "\nSomething went wrong. Please check any error output above and fix the issues."
+      echo "Then run the package installation again."
+      exit 1
     fi
   fi
-
-  echo "It seems no redis server runs locally."
-  echo "Please install Redis following the instructions at https://redis.io/docs/getting-started/ or set the REDIS_URL environment variable."
-  echo "e.g. export REDIS_URL=redis://your.redis.server:6379"
-  echo
-  echo "Please try again the Zammad package installation."
-
-  return 1
 }
 
 function setup_elasticsearch () {