linuxserver / docker-bookstack

A Docker container for the BookStack documentation wiki
GNU General Public License v3.0
747 stars 108 forks source link

No database waiting time. #159

Closed mariushosting closed 1 year ago

mariushosting commented 1 year ago

Is there an existing issue for this?

Current Behavior

The current bookstack image have no database waiting time. So you need to restart the container to be able to connect to the database.

Expected Behavior

No response

Steps To Reproduce

The current bookstack image have no database waiting time. So you need to restart the container to be able to connect to the database.

Environment

- OS:
- How docker service was installed:

CPU architecture

x86-64

Docker creation

version: "3.9"
services:
  bookstack:
    image: ghcr.io/linuxserver/bookstack
    container_name: Bookstack
    healthcheck:
      test: curl -f http://localhost:80/ || exit 1
    environment:
      - TZ=Europe/Bucharest
      - PUID=1026
      - PGID=100 
      - APP_URL=http://YourNASIP:6875
      - DB_HOST=bookstack_db
      - DB_USER=bookstack
      - DB_PASS=yourdbpass
      - DB_DATABASE=bookstackapp
    volumes:
      - /volume1/docker/bookstack:/config
    ports:
      - 6875:80
    restart: on-failure:5
    depends_on:
      - bookstack_db
  bookstack_db:
    image: mysql
    container_name: Bookstack-DB
    healthcheck:
      test: out=$$(mysqladmin ping -h localhost -P 3306 -u root --password=yourdbpass 2>&1); echo $$out | grep 'mysqld is alive' || { echo $$out; exit 1; }
    environment:
      - TZ=Europe/Bucharest
      - MYSQL_ROOT_PASSWORD=yourdbpass
      - MYSQL_DATABASE=bookstackapp
      - MYSQL_USER=bookstack
      - MYSQL_PASSWORD=yourdbpass
    volumes:
      - /volume1/docker/bookstackdb:/var/lib/mysql:rw
    restart: always

Container logs

Waiting for DB to be available
   Illuminate\Database\QueryException 
  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = bookstackapp and table_name = migrations and table_type = 'BASE TABLE')
  at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }
      +36 vendor frames 
  37  /app/www/artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
[custom-init] No custom files found, skipping...
[ls.io-init] done.
github-actions[bot] commented 1 year ago

Thanks for opening your first issue here! Be sure to follow the bug or feature issue templates!

ssddanbrown commented 1 year ago

I have not used a super-recent version of the image, but from memory it would wait, and I could bring everything up at once. Looks like this would be the relevant part of the script.

Do you have positive confirmation that this is timing based? Just asking since the log error provided is not clear in that. Does everyone come up fine when you specifically start the database first?

mariushosting commented 1 year ago

I have not used a super-recent version of the image, but from memory it would wait, and I could bring everything up at once. Looks like this would be the relevant part of the script.

Do you have positive confirmation that this is timing based? Just asking since the log error provided is not clear in that. Does everyone come up fine when you specifically start the database first?

The linuxserver bookstack image immediately tries to connect to the database before the database starts and this cause the issue. I just switch to the solidnerd bookstack image to solve the issue. Solidnerd have a db waiting time set before connecting to the database.

aptalca commented 1 year ago

You responded to and quoted a post that links to the piece of code that waits for the database and has an echo line Waiting for DB to be available. Really?

Anyway. . .

It would be nice to see a full timestamped log to see if it waited and how long, as it printed that it was waiting.

ssddanbrown commented 1 year ago

Okay. For what it's worth, I just tested a fresh compose setup, using the latest images and using the compose setup provided in the readme here, and it all comes up fine.

I then did a further test by only raising the bookstack container via docker-compose up --no-deps bookstack. The startup script would wait here:

bookstack       | Waiting for DB to be available
bookstack       | nc: bad address 'bookstack_db'
bookstack       | nc: bad address 'bookstack_db'

Then I'd start the DB container after a few seconds and it would then continue once the DB was up. So all looks functional on my side. (Ubuntu 22.10 / Ubuntu 22.10 / docker-compose version 1.29.2).

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

homerr commented 1 year ago

Confirmed db wait is present and working, closing issue