Skip to content

Steps to Deploy Custom Build in DataServer

Perform the following steps to deploy custom build in DataServer.

Warning

Ensure these steps are executed in all DataServer pods within the Privacera Manager deployment

  1. Run the following command to access to the DataServer pod in your Privacera Manager deployment:

    Bash
    kubectl exec -it <POD> -n <NAMESPACE> -- /bin/bash
    

  2. Create a script file to deploy the custom build:

    Bash
    cd /workdir
    nano custom_build.sh
    

    • Add the following content to the script file:
      custom_build.sh
      #!/bin/bash
      
      # Define working directories
      TMP_DIR="/tmp/privacera-dataserver-custom-build"
      WORKDIR="/workdir/privacera-dataserver"
      BACKUP_DIR="/tmp/backup"
      PRIVACERA_DATASERVER_TAR="privacera-dataserver.tar.gz"
      DATASERVER_ENV_CUSTOM=dataserver-env-custom.sh
      
      # Define log file path
      LOG_FILE="$WORKDIR/logs/dataserver/custom_build_script.log"
      
      # Function for logging messages with timestamps
      log() {
          local msg="$1"
          local currentTime
          currentTime=$(date "+%Y-%m-%d %H:%M:%S")
          echo "${currentTime} : ${msg}" | tee -a "$LOG_FILE"
      }
      log "======================custom_build.sh execution started!!!======================"
      # Check if the URL argument is provided
      if [ -z "$1" ]; then
          log "PRIVACERA_DOWNLOAD_URL is null so exiting...!!!"
          exit 1
      fi
      
      # Assign the provided URL to a variable
      PRIVACERA_DOWNLOAD_URL=$1
      
      # Create necessary directories
      mkdir -p "$BACKUP_DIR"
      mkdir -p "$(dirname "$LOG_FILE")"
      
      OLD_JAR_FILE=$(ls "$WORKDIR/dist/privacera-dataserver-"* 2>/dev/null)  
      OLD_MD5_SUM=$(md5sum "$OLD_JAR_FILE" 2>/dev/null | awk '{print $1}')  
      log "MD5 checksum of the existing $OLD_JAR_FILE: ${OLD_MD5_SUM}"
      
      # Backup dist and lib directories
      if [ -d "$WORKDIR/dist" ] && [ -d "$WORKDIR/dist" ]; then
          mv "$WORKDIR/dist" "$WORKDIR/lib" "$BACKUP_DIR/"
          log "Moved dist and lib directory to $BACKUP_DIR"
      else
          log "Directory not found, skipping backup"
      fi
      
      # Create and navigate to the temporary build directory
      mkdir -p "$TMP_DIR"
      cd "$TMP_DIR" || exit
      
      log "Downloading $PRIVACERA_DATASERVER_TAR from: $PRIVACERA_DOWNLOAD_URL"
      wget "$PRIVACERA_DOWNLOAD_URL" -O $PRIVACERA_DATASERVER_TAR
      if [[ $? -ne 0 ]]; then
          log "Error: Failed to download the package."
          exit 1
      fi
      
      log "Extracting $PRIVACERA_DATASERVER_TAR"
      tar xfz $PRIVACERA_DATASERVER_TAR
      if [[ $? -ne 0 ]]; then
          log "Error: Failed to extract $PRIVACERA_DATASERVER_TAR."
          exit 1
      fi
      
      # Copy new dist and lib directories
      log "Copying new files to $WORKDIR..."
      cp -r privacera-dataserver/dist/ "$WORKDIR/dist/"
      cp -r privacera-dataserver/lib/ "$WORKDIR/lib/"
      
      # Navigate to the configuration directory
      cd "$WORKDIR/conf/" || exit
      
      NEW_JAR_FILE=$(ls "$WORKDIR/dist/privacera-dataserver-"* 2>/dev/null)  
      OLD_MD5_SUM=$(md5sum "$NEW_JAR_FILE" 2>/dev/null | awk '{print $1}')  
      log "MD5 checksum of the new $NEW_JAR_FILE: ${OLD_MD5_SUM}"
      
      log "Updating $DATASERVER_ENV_CUSTOM..."
      sed -E -i 's/DATASERVER_RUN_FOREGROUND=1/DATASERVER_RUN_FOREGROUND=0/' "$(readlink -f $WORKDIR/conf/$DATASERVER_ENV_CUSTOM)"
      grep "DATASERVER_RUN_FOREGROUND" "$WORKDIR/conf/$DATASERVER_ENV_CUSTOM" | tee -a "$LOG_FILE"
      
      # Create dont_exit file
      touch "$WORKDIR/conf/dont_exit"
      ls -l "$WORKDIR/conf/dont_exit" | tee -a "$LOG_FILE"
      
      log "Running Java processes:"
      jps | tee -a "$LOG_FILE"
      
      # Find and kill ProxyServer process
      PROXY_PID=$(jps | grep ProxyServer | awk '{print $1}')
      if [ -n "$PROXY_PID" ]; then
          log "Killing ProxyServer process with PID: $PROXY_PID"
          kill -9 "$PROXY_PID"
      else
          log "No ProxyServer process found"
      fi
      
      # Start the S3 proxy
      cd "$WORKDIR/scripts" || exit
      log "Starting Privacera S3 Proxy..."
      ./start_s3_proxy.sh 2>&1 | tee -a "$LOG_FILE"
      
      log "====================== custom_build_script execution completed!!! ======================"
      
  3. Set the script as executable:

    Bash
    chmod +x custom_build.sh
    

  4. Run the script to deploy the custom build:

    Bash
    ./custom_build.sh <PRIVACERA_DOWNLOAD_URL>
    

  5. Check the logs to verify that the custom build has been deployed successfully:

    Bash
    cat /workdir/privacera-dataserver/logs/dataserver/custom_build_script.log