rollback local postgresql

This commit is contained in:
jxxghp
2025-08-19 08:30:07 +08:00
parent b79ccfafed
commit d48c6b98e8
4 changed files with 1 additions and 185 deletions

View File

@@ -28,9 +28,6 @@ RUN apt-get update -y \
rsync \
ffmpeg \
nano \
postgresql-client \
postgresql \
postgresql-contrib \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& \
if [ "$(uname -m)" = "x86_64" ]; \
@@ -77,7 +74,6 @@ RUN cp -f /app/docker/nginx.common.conf /etc/nginx/common.conf \
&& echo 'fs.inotify.max_user_watches=5242880' >> /etc/sysctl.conf \
&& echo 'fs.inotify.max_user_instances=5242880' >> /etc/sysctl.conf \
&& locale-gen zh_CN.UTF-8 \
&& for cmd in /usr/lib/postgresql/*/bin/*; do ln -sf "$cmd" /usr/local/bin/; done \
&& FRONTEND_VERSION=$(sed -n "s/^FRONTEND_VERSION\s*=\s*'\([^']*\)'/\1/p" /app/version.py) \
&& curl -sL "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${FRONTEND_VERSION}/dist.zip" | busybox unzip -d / - \
&& mv /dist /public \

View File

@@ -214,6 +214,7 @@ cd /app || exit
# 更改 moviepilot userid 和 groupid
groupmod -o -g "${PGID}" moviepilot
usermod -o -u "${PUID}" moviepilot
# 更改文件权限
chown -R moviepilot:moviepilot \
"${HOME}" \
@@ -231,93 +232,6 @@ else
gosu moviepilot:moviepilot playwright install chromium
fi
# 启动PostgreSQL服务
if [ "${DB_TYPE:-sqlite}" = "postgresql" ]; then
INFO "→ 启动PostgreSQL服务..."
# 查找PostgreSQL bin目录
POSTGRESQL_BIN_DIR=$(find /usr/lib/postgresql -name "bin" -type d 2>/dev/null | head -1)
if [ -n "${POSTGRESQL_BIN_DIR}" ]; then
INFO "找到PostgreSQL bin目录: ${POSTGRESQL_BIN_DIR}"
else
ERROR "未找到PostgreSQL bin目录"
exit 1
fi
# 设置PATH环境变量加入PostgreSQL命令路径
export PATH="${POSTGRESQL_BIN_DIR}:${PATH}"
INFO "设置PATH环境变量: ${PATH}"
# 使用配置目录下的postgresql子目录作为数据目录
POSTGRESQL_DATA_DIR="${CONFIG_DIR}/postgresql"
POSTGRESQL_LOG_DIR="${CONFIG_DIR}/logs/postgresql"
INFO "数据目录: ${POSTGRESQL_DATA_DIR}"
INFO "日志目录: ${POSTGRESQL_LOG_DIR}"
# 初始化PostgreSQL数据目录
if [ ! -f "${POSTGRESQL_DATA_DIR}/PG_VERSION" ]; then
INFO "初始化PostgreSQL数据目录..."
# 确保目录存在
mkdir -p "${POSTGRESQL_DATA_DIR}" "${POSTGRESQL_LOG_DIR}"
chown -R moviepilot:moviepilot "${POSTGRESQL_DATA_DIR}" "${POSTGRESQL_LOG_DIR}"
INFO "执行 initdb 命令..."
gosu moviepilot:moviepilot initdb -D "${POSTGRESQL_DATA_DIR}"
# 配置PostgreSQL
INFO "复制PostgreSQL配置文件..."
cp /app/docker/pg_hba.conf "${POSTGRESQL_DATA_DIR}/pg_hba.conf"
# 使用envsubst处理postgresql.conf模板
export POSTGRESQL_LOG_DIR="${POSTGRESQL_LOG_DIR}"
envsubst '${DB_POSTGRESQL_PORT}${POSTGRESQL_LOG_DIR}' < /app/docker/postgresql.conf.template > "${POSTGRESQL_DATA_DIR}/postgresql.conf"
# 设置配置文件权限
chown moviepilot:moviepilot "${POSTGRESQL_DATA_DIR}/pg_hba.conf" "${POSTGRESQL_DATA_DIR}/postgresql.conf"
chmod 600 "${POSTGRESQL_DATA_DIR}/pg_hba.conf" "${POSTGRESQL_DATA_DIR}/postgresql.conf"
else
INFO "PostgreSQL数据目录已存在跳过初始化..."
fi
# 启动PostgreSQL服务
if ! gosu moviepilot:moviepilot pg_ctl -D "${POSTGRESQL_DATA_DIR}" -l "${POSTGRESQL_LOG_DIR}/postgresql.log" start; then
ERROR "PostgreSQL 服务启动失败!"
ERROR "请检查日志文件: ${POSTGRESQL_LOG_DIR}/postgresql.log"
if [ -f "${POSTGRESQL_LOG_DIR}/postgresql.log" ]; then
ERROR "PostgreSQL 日志内容:"
tail -20 "${POSTGRESQL_LOG_DIR}/postgresql.log"
else
ERROR "PostgreSQL 日志文件不存在,可能是权限问题或目录不存在"
fi
exit 1
fi
# 等待PostgreSQL启动
INFO "等待PostgreSQL服务启动..."
local wait_count=0
until gosu moviepilot:moviepilot pg_isready -h localhost -p "${DB_POSTGRESQL_PORT:-5432}"; do
sleep 1
wait_count=$((wait_count + 1))
if [ $wait_count -gt 30 ]; then
ERROR "PostgreSQL 服务启动超时,请检查日志文件: ${POSTGRESQL_LOG_DIR}/postgresql.log"
if [ -f "${POSTGRESQL_LOG_DIR}/postgresql.log" ]; then
ERROR "PostgreSQL 日志内容:"
tail -20 "${POSTGRESQL_LOG_DIR}/postgresql.log"
fi
exit 1
fi
done
# 创建数据库和用户
INFO "创建PostgreSQL数据库和用户..."
gosu moviepilot:moviepilot psql -h localhost -p "${DB_POSTGRESQL_PORT:-5432}" -U postgres -c "CREATE USER ${DB_POSTGRESQL_USERNAME:-moviepilot} WITH PASSWORD '${DB_POSTGRESQL_PASSWORD:-moviepilot}';" 2>/dev/null || true
gosu moviepilot:moviepilot psql -h localhost -p "${DB_POSTGRESQL_PORT:-5432}" -U postgres -c "CREATE DATABASE ${DB_POSTGRESQL_DATABASE:-moviepilot} OWNER ${DB_POSTGRESQL_USERNAME:-moviepilot};" 2>/dev/null || true
gosu moviepilot:moviepilot psql -h localhost -p "${DB_POSTGRESQL_PORT:-5432}" -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_POSTGRESQL_DATABASE:-moviepilot} TO ${DB_POSTGRESQL_USERNAME:-moviepilot};" 2>/dev/null || true
INFO "PostgreSQL服务启动完成"
fi
# 证书管理
source /app/docker/cert.sh

View File

@@ -1,29 +0,0 @@
# PostgreSQL Client Authentication Configuration File
# ===========================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
# 允许所有IPv4连接用于Docker容器内部通信
host all all 0.0.0.0/0 md5
# 允许所有IPv6连接
host all all ::/0 md5

View File

@@ -1,65 +0,0 @@
# PostgreSQL configuration file template
# This file will be processed by envsubst to replace environment variables
# Connection and Authentication
listen_addresses = '*'
port = ${DB_POSTGRESQL_PORT}
max_connections = 100
# Memory Configuration
shared_buffers = 128MB
effective_cache_size = 256MB
work_mem = 4MB
maintenance_work_mem = 64MB
# Logging Configuration
log_destination = 'stderr'
logging_collector = on
log_directory = '${POSTGRESQL_LOG_DIR}'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_rotation_age = 1d
log_rotation_size = 100MB
log_min_messages = warning
log_min_error_statement = error
log_min_duration_statement = 1000
# Query Tuning
random_page_cost = 1.1
effective_io_concurrency = 200
# WAL Configuration
wal_level = replica
max_wal_size = 1GB
min_wal_size = 80MB
checkpoint_completion_target = 0.9
wal_buffers = 16MB
# Background Writer
bgwriter_delay = 200ms
bgwriter_lru_maxpages = 100
bgwriter_lru_multiplier = 2.0
# Autovacuum
autovacuum = on
autovacuum_max_workers = 3
autovacuum_naptime = 1min
autovacuum_vacuum_threshold = 50
autovacuum_analyze_threshold = 50
# Client Connection Defaults
datestyle = 'iso, mdy'
timezone = 'UTC'
lc_messages = 'C'
lc_monetary = 'C'
lc_numeric = 'C'
lc_time = 'C'
default_text_search_config = 'pg_catalog.english'
# Locale and Formatting
datestyle = 'iso, mdy'
timezone = 'UTC'
lc_messages = 'C'
lc_monetary = 'C'
lc_numeric = 'C'
lc_time = 'C'
default_text_search_config = 'pg_catalog.english'