cleanup dispatcharr
This commit is contained in:
parent
93befbb713
commit
be4c31bb2e
@ -13,38 +13,17 @@ setting_up_container
|
|||||||
network_check
|
network_check
|
||||||
update_os
|
update_os
|
||||||
|
|
||||||
|
# msg_info "Creating ${APP_USER} user"
|
||||||
APPLICATION="Dispatcharr"
|
# groupadd -f $APP_GROUP
|
||||||
APP_NAME="dispatcharr"
|
# useradd -M -s /usr/sbin/nologin -g $APP_GROUP $APP_USER || true
|
||||||
APP_USER="dispatcharr"
|
# msg_ok "Created ${APP_USER} user"
|
||||||
APP_GROUP="dispatcharr"
|
|
||||||
APP_DIR="/opt/dispatcharr"
|
|
||||||
GUNICORN_RUNTIME_DIR="dispatcharr"
|
|
||||||
GUNICORN_PORT="5656"
|
|
||||||
NGINX_HTTP_PORT="9191"
|
|
||||||
WEBSOCKET_PORT="8001"
|
|
||||||
|
|
||||||
msg_info "Creating ${APP_USER} user"
|
|
||||||
groupadd -f $APP_GROUP
|
|
||||||
useradd -M -s /usr/sbin/nologin -g $APP_GROUP $APP_USER || true
|
|
||||||
msg_ok "Created ${APP_USER} user"
|
|
||||||
|
|
||||||
setup_uv
|
|
||||||
NODE_VERSION="22" setup_nodejs
|
|
||||||
PG_VERSION="16" setup_postgresql
|
|
||||||
|
|
||||||
msg_info "Installing Dependencies"
|
msg_info "Installing Dependencies"
|
||||||
$STD apt-get install -y \
|
$STD apt-get install -y \
|
||||||
git \
|
|
||||||
curl \
|
|
||||||
wget \
|
|
||||||
build-essential \
|
build-essential \
|
||||||
gcc \
|
gcc \
|
||||||
libpcre3-dev \
|
libpcre3-dev \
|
||||||
libpq-dev \
|
libpq-dev \
|
||||||
python3-dev \
|
|
||||||
python3-venv \
|
|
||||||
python3-pip \
|
|
||||||
nginx \
|
nginx \
|
||||||
redis-server \
|
redis-server \
|
||||||
ffmpeg \
|
ffmpeg \
|
||||||
@ -52,74 +31,61 @@ $STD apt-get install -y \
|
|||||||
streamlink
|
streamlink
|
||||||
msg_ok "Installed Dependencies"
|
msg_ok "Installed Dependencies"
|
||||||
|
|
||||||
msg_info "Configuring PostgreSQL"
|
setup_uv
|
||||||
|
NODE_VERSION="22" setup_nodejs
|
||||||
POSTGRES_PASSWORD=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13)
|
PG_VERSION="16" setup_postgresql
|
||||||
|
|
||||||
|
msg_info "Set up PostgreSQL Database"
|
||||||
|
DB_NAME=dispatcharr_db
|
||||||
|
DB_USER=dispatcharr_usr
|
||||||
|
DB_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)"
|
||||||
|
DB_URL="postgresql://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME}"
|
||||||
|
$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
|
||||||
|
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;"
|
||||||
|
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';"
|
||||||
|
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';"
|
||||||
|
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC';"
|
||||||
{
|
{
|
||||||
echo "POSTGRES_DB=dispatcharr"
|
echo "Dispatcharr-Credentials"
|
||||||
echo "POSTGRES_USER=dispatch"
|
echo "Dispatcharr Database Name: $DB_NAME"
|
||||||
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD"
|
echo "Dispatcharr Database User: $DB_USER"
|
||||||
echo "POSTGRES_HOST=localhost"
|
echo "Dispatcharr Database Password: $DB_PASS"
|
||||||
} >> ~/.$APP_NAME.creds
|
} >>~/dispatcharr.creds
|
||||||
|
msg_ok "Set up PostgreSQL Database"
|
||||||
|
|
||||||
source ~/.$APP_NAME.creds
|
|
||||||
|
|
||||||
su - postgres -c "psql -tc \"SELECT 1 FROM pg_roles WHERE rolname='${POSTGRES_USER}'\"" | grep -q 1 || \
|
|
||||||
su - postgres -c "psql -c \"CREATE USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}';\""
|
|
||||||
|
|
||||||
su - postgres -c "psql -tc \"SELECT 1 FROM pg_database WHERE datname='${POSTGRES_DB}'\"" | grep -q 1 || \
|
|
||||||
su - postgres -c "psql -c \"CREATE DATABASE ${POSTGRES_DB} OWNER ${POSTGRES_USER};\""
|
|
||||||
|
|
||||||
su - postgres -c "psql -d ${POSTGRES_DB} -c \"ALTER SCHEMA public OWNER TO ${POSTGRES_USER};\""
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
msg_ok "Configured PostgreSQL"
|
|
||||||
|
|
||||||
msg_info "Fetching latest Dispatcharr release version"
|
|
||||||
LATEST_VERSION=$(curl -fsSL https://api.github.com/repos/Dispatcharr/Dispatcharr/releases/latest | grep '"tag_name":' | cut -d '"' -f4)
|
|
||||||
|
|
||||||
if [[ -z "$LATEST_VERSION" ]]; then
|
|
||||||
msg_error "Failed to fetch latest release version from GitHub."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
msg_info "Downloading Dispatcharr $LATEST_VERSION"
|
|
||||||
fetch_and_deploy_gh_release "dispatcharr" "Dispatcharr/Dispatcharr"
|
fetch_and_deploy_gh_release "dispatcharr" "Dispatcharr/Dispatcharr"
|
||||||
echo "$LATEST_VERSION" > "/opt/${APPLICATION}_version.txt"
|
|
||||||
mkdir -p /data/{db,epgs,logos,m3us,recordings,uploads}
|
|
||||||
mkdir -p /etc/$APP_NAME
|
|
||||||
cp ~/.$APP_NAME.creds /etc/$APP_NAME/$APP_NAME.env
|
|
||||||
chown -R "$APP_USER:$APP_GROUP" {/etc/$APP_NAME,$APP_DIR,/data}
|
|
||||||
|
|
||||||
|
mkdir -p /data/{db,epgs,logos,m3us,recordings,uploads}
|
||||||
|
mkdir -p /etc/dispatcharr
|
||||||
|
cp ~/.dispatcharr.creds /etc/dispatcharr/dispatcharr.env
|
||||||
|
chown -R "$APP_USER:$APP_GROUP" {/etc/dispatcharr,/opt/dispatcharr,/data}
|
||||||
|
|
||||||
sed -i 's/program\[\x27channel_id\x27\]/program["channel_id"]/g' "${APP_DIR}/apps/output/views.py"
|
sed -i 's/program\[\x27channel_id\x27\]/program["channel_id"]/g' "${APP_DIR}/apps/output/views.py"
|
||||||
|
|
||||||
msg_ok "Downloaded Dispatcharr $LATEST_VERSION"
|
msg_ok "Downloaded Dispatcharr $LATEST_VERSION"
|
||||||
|
|
||||||
msg_info "Install Python Requirements"
|
msg_info "Install Python Requirements"
|
||||||
cd $APP_DIR
|
cd /opt/dispatcharr
|
||||||
python3 -m venv env
|
python3 -m venv env
|
||||||
source env/bin/activate
|
source env/bin/activate
|
||||||
|
|
||||||
$STD pip install --upgrade pip
|
$STD pip install --upgrade pip
|
||||||
$STD pip install -r requirements.txt
|
$STD pip install -r requirements.txt
|
||||||
$STD pip install gunicorn
|
$STD pip install gunicorn
|
||||||
ln -sf /usr/bin/ffmpeg $APP_DIR/env/bin/ffmpeg
|
ln -sf /usr/bin/ffmpeg /opt/dispatcharr/env/bin/ffmpeg
|
||||||
msg_ok "Python Requirements Installed"
|
msg_ok "Python Requirements Installed"
|
||||||
|
|
||||||
msg_info "Building Frontend"
|
msg_info "Building Frontend"
|
||||||
cd $APP_DIR/frontend
|
cd /opt/dispatcharr/frontend
|
||||||
$STD npm install --legacy-peer-deps
|
$STD npm install --legacy-peer-deps
|
||||||
$STD npm run build
|
$STD npm run build
|
||||||
msg_ok "Built Frontend"
|
msg_ok "Built Frontend"
|
||||||
|
|
||||||
msg_info "Running Django Migrations"
|
msg_info "Running Django Migrations"
|
||||||
cd $APP_DIR
|
cd /opt/dispatcharr
|
||||||
source env/bin/activate
|
source env/bin/activate
|
||||||
set -o allexport
|
set -o allexport
|
||||||
source /etc/$APP_NAME/$APP_NAME.env
|
source /etc/dispatcharr/dispatcharr.env
|
||||||
set +o allexport
|
set +o allexport
|
||||||
|
|
||||||
$STD python manage.py migrate --noinput
|
$STD python manage.py migrate --noinput
|
||||||
@ -129,27 +95,27 @@ msg_ok "Migrations Complete"
|
|||||||
msg_info "Configuring Nginx"
|
msg_info "Configuring Nginx"
|
||||||
cat <<EOF >/etc/nginx/sites-available/dispatcharr.conf
|
cat <<EOF >/etc/nginx/sites-available/dispatcharr.conf
|
||||||
server {
|
server {
|
||||||
listen $NGINX_HTTP_PORT;
|
listen 9191;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
include proxy_params;
|
include proxy_params;
|
||||||
proxy_pass http://127.0.0.1:$GUNICORN_PORT;
|
proxy_pass http://127.0.0.1:5656;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /static/ {
|
location /static/ {
|
||||||
alias $APP_DIR/static/;
|
alias /opt/dispatcharr/static/;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /assets/ {
|
location /assets/ {
|
||||||
alias $APP_DIR/frontend/dist/assets/;
|
alias /opt/dispatcharr/frontend/dist/assets/;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /media/ {
|
location /media/ {
|
||||||
alias $APP_DIR/media/;
|
alias /opt/dispatcharr/media/;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /ws/ {
|
location /ws/ {
|
||||||
proxy_pass http://127.0.0.1:$WEBSOCKET_PORT;
|
proxy_pass http://127.0.0.1:8001;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade \$http_upgrade;
|
proxy_set_header Upgrade \$http_upgrade;
|
||||||
proxy_set_header Connection "Upgrade";
|
proxy_set_header Connection "Upgrade";
|
||||||
@ -173,18 +139,16 @@ Description=Gunicorn for Dispatcharr
|
|||||||
After=network.target postgresql.service redis-server.service
|
After=network.target postgresql.service redis-server.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=$APP_USER
|
WorkingDirectory=/opt/dispatcharr
|
||||||
Group=$APP_GROUP
|
RuntimeDirectory=dispatcharr
|
||||||
WorkingDirectory=$APP_DIR
|
|
||||||
RuntimeDirectory=$GUNICORN_RUNTIME_DIR
|
|
||||||
RuntimeDirectoryMode=0775
|
RuntimeDirectoryMode=0775
|
||||||
Environment="PATH=$APP_DIR/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
|
Environment="PATH=/opt/dispatcharr/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
|
||||||
EnvironmentFile=/etc/$APP_NAME/$APP_NAME.env
|
EnvironmentFile=/etc/dispatcharr/dispatcharr.env
|
||||||
ExecStart=$APP_DIR/env/bin/gunicorn \\
|
ExecStart=/opt/dispatcharr/env/bin/gunicorn \\
|
||||||
--workers=4 \\
|
--workers=4 \\
|
||||||
--worker-class=gevent \\
|
--worker-class=gevent \\
|
||||||
--timeout=300 \\
|
--timeout=300 \\
|
||||||
--bind 0.0.0.0:$GUNICORN_PORT \
|
--bind 0.0.0.0:5656 \
|
||||||
dispatcharr.wsgi:application
|
dispatcharr.wsgi:application
|
||||||
Restart=always
|
Restart=always
|
||||||
KillMode=mixed
|
KillMode=mixed
|
||||||
@ -200,13 +164,11 @@ After=network.target redis-server.service
|
|||||||
Requires=dispatcharr.service
|
Requires=dispatcharr.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=$APP_USER
|
WorkingDirectory=/opt/dispatcharr
|
||||||
Group=$APP_GROUP
|
Environment="PATH=/opt/dispatcharr/env/bin"
|
||||||
WorkingDirectory=$APP_DIR
|
EnvironmentFile=/etc/dispatcharr/dispatcharr.env
|
||||||
Environment="PATH=$APP_DIR/env/bin"
|
|
||||||
EnvironmentFile=/etc/$APP_NAME/$APP_NAME.env
|
|
||||||
Environment="CELERY_BROKER_URL=redis://localhost:6379/0"
|
Environment="CELERY_BROKER_URL=redis://localhost:6379/0"
|
||||||
ExecStart=$APP_DIR/env/bin/celery -A dispatcharr worker -l info -c 4
|
ExecStart=/opt/dispatcharr/env/bin/celery -A dispatcharr worker -l info -c 4
|
||||||
Restart=always
|
Restart=always
|
||||||
KillMode=mixed
|
KillMode=mixed
|
||||||
|
|
||||||
@ -221,13 +183,11 @@ After=network.target redis-server.service
|
|||||||
Requires=dispatcharr.service
|
Requires=dispatcharr.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=$APP_USER
|
WorkingDirectory=/opt/dispatcharr
|
||||||
Group=$APP_GROUP
|
Environment="PATH=/opt/dispatcharr/env/bin"
|
||||||
WorkingDirectory=$APP_DIR
|
EnvironmentFile=/etc/dispatcharr/dispatcharr.env
|
||||||
Environment="PATH=$APP_DIR/env/bin"
|
|
||||||
EnvironmentFile=/etc/$APP_NAME/$APP_NAME.env
|
|
||||||
Environment="CELERY_BROKER_URL=redis://localhost:6379/0"
|
Environment="CELERY_BROKER_URL=redis://localhost:6379/0"
|
||||||
ExecStart=$APP_DIR/env/bin/celery -A dispatcharr beat -l info
|
ExecStart=/opt/dispatcharr/env/bin/celery -A dispatcharr beat -l info
|
||||||
Restart=always
|
Restart=always
|
||||||
KillMode=mixed
|
KillMode=mixed
|
||||||
|
|
||||||
@ -242,30 +202,19 @@ After=network.target
|
|||||||
Requires=dispatcharr.service
|
Requires=dispatcharr.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=$APP_USER
|
WorkingDirectory=/opt/dispatcharr
|
||||||
Group=$APP_GROUP
|
Environment="PATH=/opt/dispatcharr/env/bin"
|
||||||
WorkingDirectory=$APP_DIR
|
EnvironmentFile=/etc/dispatcharr/dispatcharr.env
|
||||||
Environment="PATH=$APP_DIR/env/bin"
|
ExecStart=/opt/dispatcharr/env/bin/daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application
|
||||||
EnvironmentFile=/etc/$APP_NAME/$APP_NAME.env
|
|
||||||
ExecStart=$APP_DIR/env/bin/daphne -b 0.0.0.0 -p $WEBSOCKET_PORT dispatcharr.asgi:application
|
|
||||||
Restart=always
|
Restart=always
|
||||||
KillMode=mixed
|
KillMode=mixed
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
systemctl enable -q --now dispatcharr dispatcharr-celery dispatcharr-celerybeat dispatcharr-daphne
|
||||||
msg_ok "Created systemd services"
|
|
||||||
|
|
||||||
|
|
||||||
msg_info "Starting Dispatcharr Services"
|
|
||||||
systemctl daemon-reexec
|
|
||||||
systemctl daemon-reload
|
|
||||||
systemctl enable dispatcharr dispatcharr-celery dispatcharr-celerybeat dispatcharr-daphne
|
|
||||||
systemctl restart dispatcharr dispatcharr-celery dispatcharr-celerybeat dispatcharr-daphne
|
|
||||||
msg_ok "Started Dispatcharr Services"
|
msg_ok "Started Dispatcharr Services"
|
||||||
|
|
||||||
|
|
||||||
motd_ssh
|
motd_ssh
|
||||||
customize
|
customize
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user