Skip to content

fix(init): strip trailing newline when writing DB_CONNECTION to s6 env file#75

Open
Timikana wants to merge 1 commit into
linuxserver:mainfrom
Timikana:fix/laravel-env-from-docker-env
Open

fix(init): strip trailing newline when writing DB_CONNECTION to s6 env file#75
Timikana wants to merge 1 commit into
linuxserver:mainfrom
Timikana:fix/laravel-env-from-docker-env

Conversation

@Timikana
Copy link
Copy Markdown

Summary

The init script writes DB_CONNECTION to /run/s6/container_environment/DB_CONNECTION using echo, which appends a trailing newline. s6-overlay then propagates this trailing newline into the env var seen by PHP-FPM workers. Laravel caches config via artisan optimize during init, so the cached database.default becomes "sqlite\n".

At request time, any code path that resolves a DB connection (login, eloquent queries, sessions stored in DB, etc.) throws:

InvalidArgumentException: Database connection [sqlite
] not configured.

(Note the literal newline inside the brackets in the message.)

Reproduction

  1. Run the image with default env (no /config/.env provided, sqlite default):
    services:
      speedtest-tracker:
        image: lscr.io/linuxserver/speedtest-tracker:latest
        environment:
          APP_KEY: "base64:..."
          APP_URL: http://localhost:8765
        ports:
          - "8765:80"
  2. Visit /admin/login, enter credentials, submit.
  3. With APP_DEBUG=true the error page shows:
    • Exception: InvalidArgumentException
    • Message: Database connection [sqlite\n] not configured.
    • Stack frame at vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:226

Fix

Replace echo "sqlite" > /run/s6/container_environment/DB_CONNECTION with printf "%s" "sqlite" > ... so the file contains exactly sqlite (no trailing newline).

Verification

After applying:

  • config("database.default") returns the 6-byte string sqlite (verified with od -c).
  • Login flow completes; subsequent requests reach the dashboard with HTTP 200.
  • All other code paths (queues, sessions, eloquent) work normally.

The change is one line and only affects the sqlite branch of the existing conditional. The mysql/pgsql branches were not affected.

…ntainer env

The init script used "echo" to write the DB_CONNECTION value to
/run/s6/container_environment/DB_CONNECTION. Since echo appends a
newline, the file contains "sqlite\n" instead of "sqlite".

s6-overlay reads this file as the env value for child processes,
including PHP-FPM. Laravel config caching ("artisan optimize")
then captures DB_CONNECTION="sqlite\n" and persists it.

At request time Laravel attempts to resolve a connection named
"sqlite\n", which does not exist in config("database.connections"),
and throws:

  InvalidArgumentException: Database connection [sqlite
  ] not configured.

Replacing echo with printf "%s" produces a clean value (no trailing
newline) and resolves the issue.

Reproduces with:
  docker compose up -d using DB_CONNECTION sqlite (default)
  Login attempt at /admin/login -> 500
  Stack trace shows DatabaseManager throwing on "[sqlite\n]"
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this pull request! Be sure to follow the pull request template!

@LinuxServer-CI
Copy link
Copy Markdown
Contributor

I am a bot, here are the test results for this PR:
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v1.14.0-pkg-32c77614-dev-ae3110cfb1388401193019497236a63372573755-pr-75/index.html
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v1.14.0-pkg-32c77614-dev-ae3110cfb1388401193019497236a63372573755-pr-75/shellcheck-result.xml

Tag Passed
amd64-v1.14.0-pkg-32c77614-dev-ae3110cfb1388401193019497236a63372573755-pr-75
arm64v8-v1.14.0-pkg-32c77614-dev-ae3110cfb1388401193019497236a63372573755-pr-75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants