pixelfed / support

Issue tracker for installations of Pixelfed, before a bug is identified.
https://docs.pixelfed.org/running-pixelfed/troubleshooting.html
8 stars 3 forks source link

DB Connection Refused #91

Open reavessm opened 4 years ago

reavessm commented 4 years ago

I had this working, but then I ran a git pull and docker-compose pull, and now I can't get the DB back up.

After running

docker-compose up -d
docker-compose exec app php artisan key:generate
docker-compose restart app
docker-compose exec app php artisan config:cache
docker-compose exec app php artisan migrate

I received the following error:

Application key set successfully.
Restarting pixelfedd_app_1 ... done
Configuration cache cleared!
Configuration cached successfully!

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = pixelfed and table_name = migrations and table_type = 'BASE TABLE')

  at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
   665 |        // If an exception occurs when attempting to run a query, we'll format the error
   666 |        // message to include the bindings with SQL, which will make this exception a
    667|        // lot more helpful to the developer instead of just the database's errors.
    668|        catch (Exception e) {
>  669|            throw new QueryException(
    670|                $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [2002] Connection refused")
      /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31

  2   PDOException::("SQLSTATE[HY000] [2002] Connection refused")
      /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27

  3   PDO::__construct()
      /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27

  4   Doctrine\DBAL\Driver\PDOConnection::__construct()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:67

  5   Illuminate\Database\Connectors\Connector::createPdoConnection()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:100

  6   Illuminate\Database\Connectors\Connector::tryAgainIfCausedByLostConnection()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:50

  7   Illuminate\Database\Connectors\Connector::createConnection()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24

  8   Illuminate\Database\Connectors\MySqlConnector::connect()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182

  9   Illuminate\Database\Connectors\ConnectionFactory::Illuminate\Database\Connectors\{closure}()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:924

  10  call_user_func()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:924

  11  Illuminate\Database\Connection::getPdo()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:959

  12  Illuminate\Database\Connection::getReadPdo()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:404

  13  Illuminate\Database\Connection::getPdoForSelect()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:330

  14  Illuminate\Database\Connection::Illuminate\Database\{closure}()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:662

  15  Illuminate\Database\Connection::runQueryCallback()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:743

  16  Illuminate\Database\Connection::tryAgainIfCausedByLostConnection()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:723

  17  Illuminate\Database\Connection::handleQueryException()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:632

  18  Illuminate\Database\Connection::run()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:338

  19  Illuminate\Database\Connection::select()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php:18

  20  Illuminate\Database\Schema\MySqlBuilder::hasTable()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:169

  21  Illuminate\Database\Migrations\DatabaseMigrationRepository::repositoryExists()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:590

  22  Illuminate\Database\Migrations\Migrator::repositoryExists()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:91

  23  Illuminate\Database\Console\Migrations\MigrateCommand::prepareDatabase()
      /var/www/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:63

  24  Illuminate\Database\Console\Migrations\MigrateCommand::handle()
      /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32

  25  call_user_func_array()
      /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32

  26  Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
      /var/www/vendor/laravel/framework/src/Illuminate/Container/Util.php:36

  27  Illuminate\Container\Util::unwrapIfClosure()
      /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:90

  28  Illuminate\Container\BoundMethod::callBoundMethod()
      /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:34

  29  Illuminate\Container\BoundMethod::call()
      /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php:590

  30  Illuminate\Container\Container::call()
      /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php:134

  31  Illuminate\Console\Command::execute()
      /var/www/vendor/symfony/console/Command/Command.php:255

  32  Symfony\Component\Console\Command\Command::run()
      /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php:121

  33  Illuminate\Console\Command::run()
      /var/www/vendor/symfony/console/Application.php:1001

  34  Symfony\Component\Console\Application::doRunCommand()
      /var/www/vendor/symfony/console/Application.php:271

  35  Symfony\Component\Console\Application::doRun()
      /var/www/vendor/symfony/console/Application.php:147

  36  Symfony\Component\Console\Application::run()
      /var/www/vendor/laravel/framework/src/Illuminate/Console/Application.php:93

  37  Illuminate\Console\Application::run()
      /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:131

  38  Illuminate\Foundation\Console\Kernel::handle()
      /var/www/artisan:37

Here is my relevant configs

APP_NAME="pixelfed.domain.com"
APP_ENV=production
APP_KEY=base64:/IJe24iostEqVHxwu94VyPWaEi+zJlEgfRjC4H8Vc7M=
APP_DEBUG=false

APP_URL=https://pixelfed.domain.com
APP_DOMAIN="pixelfed.domain.com"
ADMIN_DOMAIN="pixelfed.domain.com"
SESSION_DOMAIN="pixelfed.domain.com"
TRUST_PROXIES="*"

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=pixelfed
DB_USERNAME=pixelfed
DB_PASSWORD=superStrongPasswordIPromise

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_DRIVER=redis

REDIS_SCHEME=tcp
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=log
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="pixelfed@example.com"
MAIL_FROM_NAME="Pixelfed"

OPEN_REGISTRATION=true
ENFORCE_EMAIL_VERIFICATION=true
PF_MAX_USERS=1000

MAX_PHOTO_SIZE=15000
MAX_CAPTION_LENGTH=150
MAX_ALBUM_LENGTH=4

ACTIVITY_PUB=true
AP_REMOTE_FOLLOW=true
AP_INBOX=true
PF_COSTAR_ENABLED=true

# Background jobs
HORIZON_EMBED=false
---
version: '3'

# In order to set configuration, please use a .env file in
# your compose project directory (the same directory as your
# docker-compose.yml), and set database options, application
# name, key, and other settings there.
# A list of available settings is available in .env.example
#
# The services should scale properly across a swarm cluster
# if the volumes are properly shared between cluster members.

services:

## App and Worker
  app:
    # Comment to use dockerhub image
    build:
      context: .
      dockerfile: contrib/docker/Dockerfile.apache
    image: pixelfed
    restart: unless-stopped
    ## If you have a traefik running, uncomment this to expose Pixelfed
    # labels:
    #   - traefik.enable=true
    #   - traefik.frontend.rule=Host:your.url
    #   - traefik.port=80
    ## If you have a standard reverse proxy, uncommit this to expose Pixelfed
    ports:
      - "9106:80"
    env_file:
      - ./.env.docker
    volumes:
      - "app-storage:/var/www/storage"
      - "app-bootstrap:/var/www/bootstrap"
      - "./.env.docker:/var/www/.env"
    networks:
      - external
      - internal
    depends_on:
      - db
      - redis

  worker:
    build:
      context: .
      dockerfile: contrib/docker/Dockerfile.apache
    image: pixelfed
    restart: unless-stopped
    env_file:
      - ./.env.docker
    volumes:
      - "app-storage:/var/www/storage"
      - "app-bootstrap:/var/www/bootstrap"
    networks:
      - internal
      - external  # Required for ActivityPub
    command: gosu www-data php artisan horizon
    depends_on:
      - db
      - redis

## DB and Cache
  db:
    image: mysql #mysql:8.0
    restart: unless-stopped
    networks:
      - internal
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_DATABASE=pixelfed
      - MYSQL_USER=${DB_USERNAME}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_RANDOM_ROOT_PASSWORD=true
    volumes:
      - "db-data:/var/lib/mysql"

  redis:
    image: redis:5-alpine
    restart: unless-stopped
    volumes:
      - "redis-data:/data"
    networks:
      - internal

volumes:
  redis-data:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/path/to/redis-data'
  db-data:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/path/to/db-data'
  app-storage:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/pay/to/app-data'
  app-bootstrap:  
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/pay/to/app-bootstrap'

networks:
  internal:
    internal: true
  external:
    driver: bridge
reavessm commented 4 years ago

FWIW, I get the same errors with running migrate:fresh

reavessm commented 4 years ago

According to this post, a similar error could be fixed by disabling redis, but that did not fix my issue. I even upgraded to redis:6-alpine but to no avail. I also tried mariadb and pgsql db connection but I get the same errors.

reavessm commented 4 years ago

Any update?