dell / patches

Apache License 2.0
3 stars 2 forks source link

backend and Ngins errors on ingest of new repo. Patches website down. #30

Open bryanh1969 opened 6 months ago

bryanh1969 commented 6 months ago

patches-backend_error.log patches-backend_standard.log patches-frontend_error.log patches-frontend_standard.log patches-httpd_error.log patches-httpd_standard.log patches-nginx_error.log patches-nginx_standard.log patches-psql_error.log patches-psql_standard.log

grantcurell commented 6 months ago

Check logs - your permissions are wrong:

WARNING: SERVER_CERT or SERVER_KEY environment variable is missing. Generating self-signed certificate and key...
node:internal/fs/watchers:255
    throw error;
    ^

Error: EACCES: permission denied, watch '/patches/xml/1242024'
    at FSWatcher.<computed> (node:internal/fs/watchers:247:19)
    at Object.watch (node:fs:2418:34)
    at /home/node/app/server/util.js:406:12
    at FSReqCallback.oncomplete (node:fs:211:5) {
  errno: -13,
  syscall: 'watch',
  code: 'EACCES',
  path: '/patches/xml/1242024',
  filename: '/patches/xml/1242024'
}

Node.js v18.18.2
WARNING: SERVER_CERT or SERVER_KEY environment variable is missing. Generating self-signed certificate and key...
node:internal/fs/watchers:255
    throw error;
    ^

Error: EACCES: permission denied, watch '/patches/xml/1242024'
    at FSWatcher.<computed> (node:internal/fs/watchers:247:19)
    at Object.watch (node:fs:2418:34)
    at /home/node/app/server/util.js:406:12
    at FSReqCallback.oncomplete (node:fs:211:5) {
  errno: -13,
  syscall: 'watch',
  code: 'EACCES',
  path: '/patches/xml/1242024',
  filename: '/patches/xml/1242024'
}

Node.js v18.18.2
grantcurell commented 6 months ago

This is the relevant code from patches.sh:

  import-repository)

    while true; do
      patches_read "Enter the location of the repository you would like to import. This should be a directory containing a catalog file and associated repository files."
      import_directory=${RETURN_VALUE}

      patches_echo "Setting directory permissions and ownership for ${import_directory}. \`chmod -R 775 ${import_directory}\`. This will fail if your user does not have the ability to run chmod against this directory."
      chmod -R 775 ${import_directory}
      chown "$(whoami)": -R ${import_directory}

      if validate_directory "$import_directory"; then
        if [[ -n $(find "$import_directory" -maxdepth 1 -type f -name "*.xml") ]]; then
          patches_echo "Directory validation complete..."
          break
        else
          patches_echo "There are no XML files found in the directory ${import_directory}. The catalog XML must be present - are you sure you got the path correct? Exiting." --error >&2  # Redirect error message to stderr
          exit 1
        fi
      else
        patches_echo "The specified location is not valid. Please try again." --error
      fi
    done

    if check_images; then
      if ! ask_yes_no "Patches will import $import_directory. When it does this it will remove the original directory to conserve space after the import. Patches will also be stopped during the import and then started afterwards. This should only take a few seconds to complete. Would you like to continue?"; then
        patches_echo "Terminating." --error
        exit 1
      fi
      patches_stop
      mv "$import_directory" "${TOP_DIR}/repos/xml"
      patches_start
    else
      mv "$import_directory" "${TOP_DIR}/repos/xml"
      if ask_yes_no "It looks like the Patches images are not yet configured. Do you want to run setup now?"; then
        patches_setup
      else
        patches_echo "Exiting."
        exit 0
      fi
    fi

    ;;

the directory permissions should be 775. Are they something different? If so, did you use import-repository and did it finish running? It should be that chmod line that checks against this.

bryanh1969 commented 6 months ago

I did....and I saw that.
I think the path is wrong. the path there is /patches/xml/1242024' The path should be /opt/patches/repos/xml/.

Where do I change that?

grantcurell commented 6 months ago

I did....and I saw that. I think the path is wrong. the path there is /patches/xml/1242024' The path should be /opt/patches/repos/xml/.

Where do I change that?

/patches/xml/1242024 is a mount inside the container not on your host. That path looks correct. You can check it by exec'ing into the container if you want:

From Debugging the Backend

cd /opt/patches
TOP_DIR=./
SCRIPT_DIR=./podman-build/
CERT_DIRECTORY=./server_certs/
podman rm -f -t 0 patches-backend && \
podman run \
  --name patches-backend \
  --env-file ${TOP_DIR}/.patches-backend \
  --volume ${TOP_DIR}/server/data:/home/node/app/data:Z \
  --volume ${TOP_DIR}/server/config.js:/home/node/app/server/config.js:Z \
  --volume ${TOP_DIR}/server/routes:/home/node/app/server/routes:Z \
  --volume ${TOP_DIR}/server/logger.js:/home/node/app/server/logger.js:Z \
  --volume ${TOP_DIR}/server/db.js:/home/node/app/server/db.js:Z \
  --volume ${TOP_DIR}/server/index.js:/home/node/app/server/index.js:Z \
  --volume ${TOP_DIR}/server/knexfile.js:/home/node/app/server/knexfile.js:Z \
  --volume ${TOP_DIR}/server/rebuild_database.js:/home/node/app/server/rebuild_database.js:Z \
  --volume ${TOP_DIR}/server/util.js:/home/node/app/server/util.js:Z \
  --volume ${TOP_DIR}/server/seeds/:/home/node/app/server/seeds:Z \
  --volume ${TOP_DIR}/package.json:/home/node/app/package.json:Z \
  --volume ${TOP_DIR}/${CERT_DIRECTORY}:/patches/${CERT_DIRECTORY}:z \
  --volume ${SCRIPT_DIR}/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d:Z \
  --volume ${TOP_DIR}/migrations:/home/node/app/migrations:Z \
  --volume ${TOP_DIR}/repos/xml:/patches/xml:z \
  --volume ${TOP_DIR}/repos/xml/parsed:/patches/xml/parsed:z \
  --publish "9229:9229" \
  --network host-bridge-net \
  -it \
  localhost/dell/patches-base:latest \
  /bin/bash

Note the line --volume ${TOP_DIR}/repos/xml:/patches/xml:z \. This is where the volume mount occurs.

The source cause of that though is the folder on the host /opt/patches/repos/xml/1242024 probably has the wrong permissions.

bryanh1969 commented 6 months ago

i used import-repository

bryanh1969 commented 6 months ago

[devuser@localhost ~]$ cd /opt/patches/repos/xml/ [devuser@localhost xml]$ ls -lah total 172K drwxrwxr-x. 5 devuser devuser 49 Jan 24 07:36 . drwxrwxr-x. 3 devuser devuser 17 Dec 22 14:40 .. drwxrwxr-x. 1681 devuser devuser 56K Jan 2 12:00 122024 drwxrwxr-x. 1775 devuser devuser 60K Jan 24 07:30 1242024 drwxrwxr-x. 2 devuser devuser 164 Jan 5 15:13 parsed

grantcurell commented 6 months ago

It has to be the entire path. Maybe something is wrong with repos or xml. If those are normal try debugging as mentioned above - exec into the container and try touching a file in the folder.

grantcurell commented 6 months ago

Try reading the file with cat and see if it works. If it doesn't you know you have a read probably and can focus in on that permission. Make sure everything starting at /opt/patches down is owned by devuser. Maybe ownership changed somewhere on one of the folders in the chain /opt/patches/repos/xml chain

bryanh1969 commented 6 months ago

reading the file with cat work swimmingly.

for some reason the backend just does not want to start even with a re setup

grantcurell commented 6 months ago

Try /home/node/app/node_modules/knex/bin/cli.js migrate:rollback --knexfile /home/node/app/server/knexfile.js && node /home/node/app/node_modules/knex/bin/cli.js migrate:latest --knexfile /home/node/app/server/knexfile.js && node --inspect-brk=0.0.0.0:9229 server/index.js in the container

See: https://github.com/dell/patches/blob/main/DEBUGGING.md#debugging-the-backend

That manually runs the backend. See what the output is.

grantcurell commented 6 months ago

reading the file with cat work swimmingly.

for some reason the backend just does not want to start even with a re setup

Also, just to confirm, reading the file with cat in the container works swimmingly? It's in the container that matters.