Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
/tmp/pids/*
!/tmp/pids/.keep

# Ignore the Postgres bind mount created by the compose db service. It is
# root-owned, so a rebuild after first boot cannot read the build context.
/data

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
Expand Down
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ POSTGRES_DB=streamvault
# Host port to expose the app on (container always listens on 80).
PORT=3000

# ── Background jobs ─────────────────────────────────────────────
# Jobs run in the `worker` compose service, so the web container leaves
# SOLID_QUEUE_IN_PUMA unset. Set it to true only for a single-container
# deployment where Puma should run the supervisor itself.
SOLID_QUEUE_IN_PUMA=
# Worker processes; each one runs three threads (see config/queue.yml).
JOB_PROCESSES=1

# ── TLS ──────────────────────────────────────────────────────────
# Both default to true, which is correct when a TLS-terminating proxy
# sits in front of the app. Set both to false only when it is reached
# directly over plain HTTP on a trusted network (LAN, tailnet, VPN).
FORCE_SSL=true
Comment thread
vitobotta marked this conversation as resolved.
Resolved
Comment thread
vitobotta marked this conversation as resolved.
Resolved
ASSUME_SSL=true

# ── External APIs ────────────────────────────────────────────────
# Torrentio API base URL. Default is the public instance, but it may
# be blocked by Cloudflare. Consider running a self-hosted proxy
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ The database lives in `./data` and survives rebuilds. Containers restart on cras
| `STREAM_PROVIDER` | `torrentio`, `comet`, or `auto` | `torrentio` |
| `TMDB_READ_ACCESS_TOKEN` | Recommendations | empty |
| `SUBDL_API_KEY` | External subtitle fallback | empty |
| `FORCE_SSL` | Redirect to HTTPS and mark cookies Secure; `false` for plain HTTP on a trusted network | `true` |
| `ASSUME_SSL` | Trust `X-Forwarded-Proto` from a TLS-terminating proxy; `false` when Rails is reached directly | `true` |
| `SOLID_QUEUE_IN_PUMA` | Run jobs inside the web process instead of the `worker` service | unset |
| `JOB_PROCESSES` | Worker processes started by the `worker` service; each runs three threads | `1` |

The full list, provider modes, Cloudflare proxy setups, and reverse proxy notes are in [docs/CONFIGURATION.md](docs/CONFIGURATION.md).

Expand All @@ -220,12 +224,13 @@ The full list, provider modes, Cloudflare proxy setups, and reverse proxy notes
| Playback buffers during transcoding | CPU saturation in the web logs. Try a 1080p H.264 source before 4K, HEVC, or AV1 |
| A resumed stream is CPU-heavy | Expected: a non-zero seek may re-encode to keep audio and video aligned |
| Sign-in does not persist behind a proxy | HTTPS on the public URL, and the proxy must forward the original scheme and host |
| Jobs never run, or recommendations stay stale | The `worker` service is up (`docker compose ps`, `docker compose logs -f worker`); the web container does not execute jobs unless `SOLID_QUEUE_IN_PUMA` is set |

Logs and health:

```bash
docker compose ps
docker compose logs --tail=200 -f web
docker compose logs --tail=200 -f web worker
curl -I http://localhost:${PORT:-3000}/up
```

Expand Down
7 changes: 5 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
# Assume all access to the app is happening through a SSL-terminating
# reverse proxy (Caddy / kamal-proxy), so request.ssl? reflects the
# upstream scheme even though Rails sees plain HTTP on the socket.
config.assume_ssl = true
# Set ASSUME_SSL=false when Rails is reached directly instead.
config.assume_ssl = ActiveModel::Type::Boolean.new.cast(ENV.fetch("ASSUME_SSL", "true")) != false

# Force all access over SSL, set HSTS, and mark cookies secure. The
# app carries session cookies and RealDebrid API keys in requests, so
# transport encryption is required end-to-end.
config.force_ssl = true
# Set FORCE_SSL=false to serve plain HTTP on a trusted network (a LAN,
# a tailnet, or the container's published port) with no TLS terminator.
config.force_ssl = ActiveModel::Type::Boolean.new.cast(ENV.fetch("FORCE_SSL", "true")) != false

# Skip http-to-https redirect for the default health check endpoint.
config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
Expand Down
28 changes: 28 additions & 0 deletions config/initializers/hls_session_cleanup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# HLS sessions are created, transcoded and served by the web container: their
# rows carry PIDs and tmp/hls paths that exist nowhere else. Running the
# cleanup from the worker would delete the rows while leaving every segment
# on the web disk, and could signal an unrelated process that reused the PID.
#
# With SOLID_QUEUE_IN_PUMA the scheduler already lives in Puma, so the thread
# below only starts when a separate worker owns job execution.
if Rails.env.production? &&
ActiveModel::Type::Boolean.new.cast(ENV["SOLID_QUEUE_IN_PUMA"].presence || "false") != true &&
Comment thread
vitobotta marked this conversation as resolved.
Resolved
ENV["HLS_CLEANUP_IN_WEB"] != "false"
Rails.application.config.after_initialize do
next unless defined?(Rails::Server)
Comment thread
vitobotta marked this conversation as resolved.
Resolved

Rails.logger.info("[HlsSessionCleanup] starting web-side HLS cleanup loop")
Thread.new do
loop do
begin
Rails.application.executor.wrap { HlsSessionManager.cleanup_expired }
rescue StandardError => e
Rails.logger.warn("[HlsSessionCleanup] #{e.class}: #{e.message}")
end
sleep 300
end
end
end
end
6 changes: 5 additions & 1 deletion config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
plugin :tmp_restart

# Run the Solid Queue supervisor inside of Puma for single-server deployments.
plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"]
# Opt in by setting the variable; every string is truthy, so the value is also
# compared against falsey spellings to let a two-container deployment turn the
# supervisor off while a separate worker owns job execution.
solid_queue_in_puma = ENV["SOLID_QUEUE_IN_PUMA"].to_s.strip.downcase
plugin :solid_queue if solid_queue_in_puma.present? && !%w[0 false no off].include?(solid_queue_in_puma)

# Specify the PID file. Defaults to tmp/pids/server.pid in development.
# In other environments, only set the PID file if requested.
Expand Down
2 changes: 1 addition & 1 deletion config/queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default: &default
workers:
- queues: "*"
threads: 3
processes: <%= ENV.fetch("JOB_CONCURRENCY", 1) %>
processes: <%= ENV.fetch("JOB_PROCESSES", 1) %>
polling_interval: 0.1

development:
Expand Down
10 changes: 4 additions & 6 deletions config/recurring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ production:
clear_solid_queue_finished_jobs:
command: "SolidQueue::Job.clear_finished_in_batches(sleep_between_batches: 0.3)"
schedule: every hour at minute 12
# Stop inactive/over-age HLS sessions and remove stale untracked
# segment directories. Active playlist and segment requests refresh
# session activity, while an absolute lifetime still bounds storage.
cleanup_hls_sessions:
command: "HlsSessionManager.cleanup_expired"
schedule: every 5 minutes
# HLS cleanup deliberately does not live here: it stops processes by PID
# and deletes tmp/hls directories that only exist in the web container, so
# it runs from the web process instead. See
# config/initializers/hls_session_cleanup.rb.
25 changes: 24 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,30 @@ services:
environment:
RAILS_ENV: production
DATABASE_URL: postgres://${POSTGRES_USER:-streamvault}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-streamvault}
SOLID_QUEUE_IN_PUMA: "true"
# Background jobs run in the `worker` service below, so the web
# container must not start its own Solid Queue supervisor.
SOLID_QUEUE_IN_PUMA: "false"
# Both default to true, which is right behind a TLS-terminating proxy.
# Set both to false in .env to serve plain HTTP on a trusted network.
FORCE_SSL: "${FORCE_SSL:-true}"
ASSUME_SSL: "${ASSUME_SSL:-true}"
depends_on:
db:
condition: service_healthy
restart: unless-stopped

# Runs the Solid Queue supervisor, dispatcher and workers. The image's
# default command is the web server, so the command override is required.
worker:
build:
context: .
env_file: .env
environment:
RAILS_ENV: production
DATABASE_URL: postgres://${POSTGRES_USER:-streamvault}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-streamvault}
# Worker processes; each one runs three threads (config/queue.yml).
JOB_PROCESSES: "${JOB_PROCESSES:-1}"
command: [ "bundle", "exec", "bin/jobs" ]
Comment thread
vitobotta marked this conversation as resolved.
Resolved
depends_on:
db:
condition: service_healthy
Expand Down