From 283acd26c44430b19ffe15c9860fc25f8c8d5730 Mon Sep 17 00:00:00 2001 From: Ryan Westfall Date: Tue, 21 Oct 2025 21:02:17 -0500 Subject: [PATCH] adding the service files and and a script to gather them --- copy_systemd_files.py | 21 +++++++++++++++++++++ systemd/beta_dta_wsgi.service | 18 ++++++++++++++++++ systemd/beta_dta_wsgi.socket | 8 ++++++++ systemd/company.service | 18 ++++++++++++++++++ systemd/company.socket | 8 ++++++++ systemd/daphne.service | 19 +++++++++++++++++++ systemd/gunicorn.service | 17 +++++++++++++++++ systemd/gunicorn.socket | 8 ++++++++ systemd/prod_dta_wsgi.service | 18 ++++++++++++++++++ systemd/prod_dta_wsgi.socket | 8 ++++++++ systemd/scha.service | 18 ++++++++++++++++++ systemd/scha.socket | 8 ++++++++ 12 files changed, 169 insertions(+) create mode 100644 copy_systemd_files.py create mode 100644 systemd/beta_dta_wsgi.service create mode 100644 systemd/beta_dta_wsgi.socket create mode 100644 systemd/company.service create mode 100644 systemd/company.socket create mode 100644 systemd/daphne.service create mode 100644 systemd/gunicorn.service create mode 100644 systemd/gunicorn.socket create mode 100644 systemd/prod_dta_wsgi.service create mode 100644 systemd/prod_dta_wsgi.socket create mode 100644 systemd/scha.service create mode 100644 systemd/scha.socket diff --git a/copy_systemd_files.py b/copy_systemd_files.py new file mode 100644 index 0000000..224a5a4 --- /dev/null +++ b/copy_systemd_files.py @@ -0,0 +1,21 @@ +import os +import shutil + +if __name__ == "__main__": + source_dir = r'/etc/systemd/system' + info_file = 'restart_services.sh' + items = os.listdir(source_dir) + print(items) + with open(info_file, 'r') as file: + for line in file: + filename = line.strip().split()[-1] + print(filename) + if filename != 'nginx': + socket_file = os.path.join(source_dir,f'{filename}.socket') + service_file = os.path.join(source_dir,f'{filename}.service') + if os.path.isfile(socket_file): + shutil.copyfile(socket_file, f'./systemd/{filename}.socket') + if os.path.isfile(service_file): + shutil.copyfile(service_file,f'./systemd/{filename}.service') + + diff --git a/systemd/beta_dta_wsgi.service b/systemd/beta_dta_wsgi.service new file mode 100644 index 0000000..cd7cd66 --- /dev/null +++ b/systemd/beta_dta_wsgi.service @@ -0,0 +1,18 @@ +[Unit] +Description=Beta Ditch The Agent WSGI daemon +Requires=beta_dta_wsgi.socket +After=network.target + +[Service] +User=westfarn +Group=www-data +WorkingDirectory=/home/westfarn/Documents/django_live_sites/beta_dta_backend/dta_service +ExecStart=/home/westfarn/Documents/django_live_sites/beta_dta_backend/venv/bin/gunicorn \ + --access-logfile - \ + --workers 3 \ + --bind unix:/run/beta_dta_wsgi.sock \ + dta_service.wsgi:application + + +[Install] +WantedBy=multi-user.target diff --git a/systemd/beta_dta_wsgi.socket b/systemd/beta_dta_wsgi.socket new file mode 100644 index 0000000..8b970cf --- /dev/null +++ b/systemd/beta_dta_wsgi.socket @@ -0,0 +1,8 @@ +[Unit] +Description=Beta Ditch The Agent WSGI Socket + +[Socket] +ListenStream=/run/beta_dta_wsgi.sock + +[Install] +WantedBy=sockets.target diff --git a/systemd/company.service b/systemd/company.service new file mode 100644 index 0000000..802c21a --- /dev/null +++ b/systemd/company.service @@ -0,0 +1,18 @@ +[Unit] +Description=Company Site daemon +Requires=company.socket +After=network.target + +[Service] +User=westfarn +Group=www-data +WorkingDirectory=/home/westfarn/Documents/django_live_sites/Company_Site/company_site +ExecStart=/home/westfarn/Documents/django_live_sites/Company_Site/venv/bin/gunicorn \ + --access-logfile - \ + --workers 3 \ + --bind unix:/run/company.sock \ + company_site.wsgi:application + + +[Install] +WantedBy=multi-user.target diff --git a/systemd/company.socket b/systemd/company.socket new file mode 100644 index 0000000..e3160f3 --- /dev/null +++ b/systemd/company.socket @@ -0,0 +1,8 @@ +[Unit] +Description=Company Site Socket + +[Socket] +ListenStream=/run/company.sock + +[Install] +WantedBy=sockets.target diff --git a/systemd/daphne.service b/systemd/daphne.service new file mode 100644 index 0000000..51cfea5 --- /dev/null +++ b/systemd/daphne.service @@ -0,0 +1,19 @@ +[Unit] +Description=Websocket Daphne Service +After=network.target + +[Service] +Type=simple +User=westfarn +Group=www-data +WorkingDirectory=/home/westfarn/Documents/django_live_sites/Chat_Bot_Backend/llm_be +ExecStart=/home/westfarn/Documents/django_live_sites/Chat_Bot_Backend/venv/bin/python /home/westfarn/Documents/django_live_sites/Chat_Bot_Backend/venv/bin/daphne -b 0.0.0.0 -p 8001 -v 0 llm_be.asgi:application +Restart=always +StartLimitBurst=2 + +#StartLimitInterval=600 +# Restart, but not more than once every 30s (for testing purposes) +StartLimitInterval=30 + +[Install] +WantedBy=multi-user.target diff --git a/systemd/gunicorn.service b/systemd/gunicorn.service new file mode 100644 index 0000000..d3a629d --- /dev/null +++ b/systemd/gunicorn.service @@ -0,0 +1,17 @@ +[Unit] +Description=gunicorn daemon +Requires=gunicorn.socket +After=network.target + +[Service] +User=westfarn +Group=www-data +WorkingDirectory=/home/westfarn/Documents/django_live_sites/Chat_Bot_Backend/llm_be +ExecStart=/home/westfarn/Documents/django_live_sites/Chat_Bot_Backend/venv/bin/gunicorn \ + --access-logfile - \ + --workers 3 \ + --bind unix:/run/gunicorn.sock \ + llm_be.wsgi:application + +[Install] +WantedBy=multi-user.target diff --git a/systemd/gunicorn.socket b/systemd/gunicorn.socket new file mode 100644 index 0000000..9283699 --- /dev/null +++ b/systemd/gunicorn.socket @@ -0,0 +1,8 @@ +[Unit] +Description=gunicorn socket + +[Socket] +ListenStream=/run/gunicorn.sock + +[Install] +WantedBy=sockets.target diff --git a/systemd/prod_dta_wsgi.service b/systemd/prod_dta_wsgi.service new file mode 100644 index 0000000..37cfa7f --- /dev/null +++ b/systemd/prod_dta_wsgi.service @@ -0,0 +1,18 @@ +[Unit] +Description=Prod Ditch The Agent WSGI daemon +Requires=prod_dta_wsgi.socket +After=network.target + +[Service] +User=westfarn +Group=www-data +WorkingDirectory=/home/westfarn/Documents/django_live_sites/prod_dta_backend/dta_service +ExecStart=/home/westfarn/Documents/django_live_sites/prod_dta_backend/venv/bin/gunicorn \ + --access-logfile - \ + --workers 3 \ + --bind unix:/run/prod_dta_wsgi.sock \ + dta_service.wsgi:application + + +[Install] +WantedBy=multi-user.target diff --git a/systemd/prod_dta_wsgi.socket b/systemd/prod_dta_wsgi.socket new file mode 100644 index 0000000..bd837b4 --- /dev/null +++ b/systemd/prod_dta_wsgi.socket @@ -0,0 +1,8 @@ +[Unit] +Description=Prod Ditch The Agent WSGI Socket + +[Socket] +ListenStream=/run/prod_dta_wsgi.sock + +[Install] +WantedBy=sockets.target diff --git a/systemd/scha.service b/systemd/scha.service new file mode 100644 index 0000000..0409ded --- /dev/null +++ b/systemd/scha.service @@ -0,0 +1,18 @@ +[Unit] +Description=SCHA Site daemon +Requires=scha.socket +After=network.target + +[Service] +User=westfarn +Group=www-data +WorkingDirectory=/home/westfarn/Documents/django_live_sites/SCHA/SCHA +ExecStart=/home/westfarn/Documents/django_live_sites/SCHA/venv/bin/gunicorn \ + --access-logfile - \ + --workers 3 \ + --bind unix:/run/scha.sock \ + scha.wsgi:application + + +[Install] +WantedBy=multi-user.target diff --git a/systemd/scha.socket b/systemd/scha.socket new file mode 100644 index 0000000..52f1844 --- /dev/null +++ b/systemd/scha.socket @@ -0,0 +1,8 @@ +[Unit] +Description=SCHA Site Socket + +[Socket] +ListenStream=/run/scha.sock + +[Install] +WantedBy=sockets.target