incubator-answer icon indicating copy to clipboard operation
incubator-answer copied to clipboard

Error 50x on redeployment

Open overdev-l opened this issue 1 year ago • 11 comments

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

I am using docker to deploy answers and using mysql for data, but I didn't save the config, which causes me to need to configure it again when I redeploy it, and connecting to the previous mysql access why is it 50x?

Expected behavior

Access is normal

Screenshots

image

Platform

  • Device: [e.g. Desktop, Mobile]
  • OS: [e.g. macOS]
  • Browser and version: [e.g. Chrome, Safari]
  • Version: [e.g. v1.2.0]

overdev-l avatar Dec 18 '24 09:12 overdev-l

but I didn't save the config

@overdev-l If you did not save the config file, you could go back to http://host:port/install to continue the installation. If you are prompted that a configuration file already exists, you need to delete the config file first before reinstalling. If you are deploying with docker, you can try deleting the mounted volume(answer-data).

LinkinStars avatar Dec 18 '24 09:12 LinkinStars

but I didn't save the config

@overdev-l If you did not save the config file, you could go back to http://host:port/install to continue the installation. If you are prompted that a configuration file already exists, you need to delete the config file first before reinstalling. If you are deploying with docker, you can try deleting the mounted volume(answer-data).

Yes I tried to revisit install for config generation, the connected database is the original, and after the setup is complete the visit returns 50x

overdev-l avatar Dec 18 '24 12:12 overdev-l

@overdev-l Got it. Please check if there is any data left in the database from the previous installation, if there is any data left it may cause a conflict. If not, please help check the docker logs to see if there are any other errors that may have caused the installation to fail. Thanks.

LinkinStars avatar Dec 18 '24 13:12 LinkinStars

@overdev-l Got it. Please check if there is any data left in the database from the previous installation, if there is any data left it may cause a conflict. If not, please help check the docker logs to see if there are any other errors that may have caused the installation to fail. Thanks.

How do I decipher which data is left over from the install, I've checked docker logs and there are no anomalies

overdev-l avatar Dec 18 '24 13:12 overdev-l

@overdev-l There are only two data.

  1. Confirm that the docker volume still exists.docker volume ls. If the answer-data exist, you need to remove it. docker volume rm answer-data
  2. Confirm that the database still has any tables. If any tables exist, you need to delete it.

LinkinStars avatar Dec 18 '24 14:12 LinkinStars

@overdev-l There are only two data.

  1. Confirm that the docker volume still exists.docker volume ls. If the answer-data exist, you need to remove it. docker volume rm answer-data
  2. Confirm that the database still has any tables. If any tables exist, you need to delete it.

I want to save the Q&A data in the datasheet, so is it ok if I just delete the answer-data?

overdev-l avatar Dec 19 '24 01:12 overdev-l

There are two options here:

  1. If the previous configuration file already exists, there is an option not to reinstall it. Instead, modify the contents of the configuration file directly, especially the MySQL connection part.
# find the answer-data and modify the conf/config.yaml
$ docker volume inspect answer-data
  1. The second option is to export the original MySQL data, delete all the original data, including answer-data, and import the data(over write) after reinstallation.

LinkinStars avatar Dec 19 '24 04:12 LinkinStars

There are two options here:

  1. If the previous configuration file already exists, there is an option not to reinstall it. Instead, modify the contents of the configuration file directly, especially the MySQL connection part.
# find the answer-data and modify the conf/config.yaml
$ docker volume inspect answer-data
  1. The second option is to export the original MySQL data, delete all the original data, including answer-data, and import the data(over write) after reinstallation.

Thank you very much!

overdev-l avatar Dec 20 '24 06:12 overdev-l

A more permanent solution I found to prevent 50x errors on redeployment is to add a healthcheck to your docker-compose to ensure the database is loaded first, as described in #472. Here is mine:

services:
  answer:
    image: apache/answer:latest
    container_name: answer
    ports:
      - "9080:80"
    volumes:
      - root_answer-data:/data
    environment:
      DB_TYPE: mysql
      DB_HOST: db:3306
      DB_USERNAME: answer_user
      DB_PASSWORD: strong_password
      DB_NAME: answer_db
      AUTO_INSTALL: true
      ADMIN_EMAIL: [email protected]
      ADMIN_NAME: msait
      ADMIN_PASSWORD: strong_password
      CONTACT_EMAIL: [email protected]
      LANGUAGE: en-US
      SITE_NAME: Answers
      SITE_URL: https://answer.msa.com
    depends_on:
      db:
        condition: service_healthy
    restart: always

  db:
    image: mysql:latest
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: strong_password
      MYSQL_DATABASE: answer_db
      MYSQL_USER: answer_user
      MYSQL_PASSWORD: strong_password
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-pstrong_password"]
      timeout: 20s
      retries: 10
    volumes:
      - root_db-data:/var/lib/mysql
    restart: always

volumes:
  root_answer-data:
    external: true
  root_db-data:
    external: true

nabekhan avatar Jan 12 '25 07:01 nabekhan

Is there any other solution than whole backup and restore of data because i have a large data present in mySQL

@nabekhan I have mySQL deployed separately and is also being used for other services , any solution for that

adnan-qasim avatar Apr 11 '25 09:04 adnan-qasim

Here is a more stable solution: waiting for the init SQL file (app.sql) been successfully imported into the MySQL instance, then start the Anwser server.

services:
  app:
    image: apache/answer:1.7.1
    ports:
      - '9080:80'
    restart: on-failure
    volumes:
      - ./config.yaml:/data/conf/config.yaml
    depends_on:
      mysql:
        condition: service_healthy

  mysql:
    image: mysql:8.0
    restart: on-failure
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=app
      - MYSQL_USER=user
      - MYSQL_PASSWORD=changeme!
    volumes:
      - ./app.sql:/docker-entrypoint-initdb.d/app.sql
      - mysql_data:/var/lib/mysql
    healthcheck:
      # check if `app.sql` is already imported by checking if the table `x_users` exists.
      test: [ "CMD-SHELL", "mysql -u user -pchangeme! -D app -e 'SELECT 1 FROM x_users LIMIT 1;'" ]
      interval: 16s
      timeout: 16s
      retries: 16
      start_period: 32s

volumes:
  mysql_data:

WangYihang avatar Jan 29 '26 04:01 WangYihang