Proyecto LCX Dispatcharr multicuenta
Base Image Build / prepare (push) Has been cancelled
Build and Push Multi-Arch Docker Image / build-and-push (push) Has been cancelled
Frontend Tests / test (push) Has been cancelled
Base Image Build / docker (amd64, ubuntu-24.04) (push) Has been cancelled
Base Image Build / docker (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Base Image Build / create-manifest (push) Has been cancelled
Base Image Build / prepare (push) Has been cancelled
Build and Push Multi-Arch Docker Image / build-and-push (push) Has been cancelled
Frontend Tests / test (push) Has been cancelled
Base Image Build / docker (amd64, ubuntu-24.04) (push) Has been cancelled
Base Image Build / docker (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Base Image Build / create-manifest (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import sys
|
||||
import psycopg2
|
||||
from psycopg2 import sql
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Drop the entire database (schema and data) and recreate it. (PostgreSQL only)"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
db_settings = settings.DATABASES['default']
|
||||
db_name = db_settings['NAME']
|
||||
user = db_settings['USER']
|
||||
password = db_settings['PASSWORD']
|
||||
host = db_settings.get('HOST', 'localhost')
|
||||
port = db_settings.get('PORT', 5432)
|
||||
|
||||
# Read TLS parameters from Django OPTIONS (populated when POSTGRES_SSL=true)
|
||||
db_options = db_settings.get('OPTIONS', {})
|
||||
ssl_kwargs = {}
|
||||
for key in ('sslmode', 'sslrootcert', 'sslcert', 'sslkey'):
|
||||
if key in db_options:
|
||||
ssl_kwargs[key] = db_options[key]
|
||||
|
||||
self.stdout.write(self.style.WARNING(
|
||||
f"WARNING: This will irreversibly drop the entire database '{db_name}'!"
|
||||
))
|
||||
confirm = input("Type 'yes' to proceed: ")
|
||||
if confirm.lower() != 'yes':
|
||||
self.stdout.write("Aborted. No changes made.")
|
||||
return
|
||||
|
||||
# Close Django's current connection to the target DB
|
||||
connection.close()
|
||||
|
||||
# For PostgreSQL, we need to connect to a different database (e.g. the maintenance database "postgres")
|
||||
maintenance_db = 'postgres'
|
||||
try:
|
||||
self.stdout.write("Connecting to maintenance database...")
|
||||
conn = psycopg2.connect(dbname=maintenance_db, user=user, password=password, host=host, port=port, **ssl_kwargs)
|
||||
conn.autocommit = True
|
||||
cur = conn.cursor()
|
||||
self.stdout.write(f"Dropping database '{db_name}'...")
|
||||
cur.execute(sql.SQL("DROP DATABASE IF EXISTS {}").format(sql.Identifier(db_name)))
|
||||
self.stdout.write(f"Creating database '{db_name}'...")
|
||||
cur.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(db_name)))
|
||||
cur.close()
|
||||
conn.close()
|
||||
self.stdout.write(self.style.SUCCESS(f"Database '{db_name}' has been dropped and recreated."))
|
||||
self.stdout.write("Now run 'python manage.py migrate' to reapply your migrations.")
|
||||
except Exception as e:
|
||||
self.stderr.write(self.style.ERROR(f"Error dropping/creating database: {e}"))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,27 @@
|
||||
# core/management/commands/kill_processes.py
|
||||
|
||||
import psutil
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Kills all processes with 'ffmpeg' or 'streamlink' in their name or command line."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
kill_count = 0
|
||||
|
||||
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
||||
try:
|
||||
name = proc.info.get('name') or ''
|
||||
cmdline = ' '.join(proc.info.get('cmdline') or [])
|
||||
lower_name = name.lower()
|
||||
lower_cmdline = cmdline.lower()
|
||||
|
||||
if ('ffmpeg' in lower_name or 'ffmpeg' in lower_cmdline or
|
||||
'streamlink' in lower_name or 'streamlink' in lower_cmdline):
|
||||
self.stdout.write(f"Killing PID {proc.pid}: {name} {cmdline}")
|
||||
proc.kill()
|
||||
kill_count += 1
|
||||
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
||||
continue
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(f"Killed {kill_count} processes."))
|
||||
@@ -0,0 +1,13 @@
|
||||
# your_app/management/commands/update_column.py
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from core.models import CoreSettings, NETWORK_ACCESS_KEY
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Reset network access settings"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
setting = CoreSettings.objects.get(key=NETWORK_ACCESS_KEY)
|
||||
setting.value = {}
|
||||
setting.save()
|
||||
Reference in New Issue
Block a user