Fixes, use gunicorn, launch websockify

This hosts a smattering of fixes, acutally uses gunicorn properly(?),
launches websockify correctly, and introduces MORE DEAD CODE!

TODO: Fix the scheduling system
This commit is contained in:
Will Nilges 2022-07-11 00:35:28 -04:00
parent 7555232926
commit 4ec51ea611
7 changed files with 27 additions and 17 deletions

View file

@ -8,4 +8,4 @@ COPY .git ./.git
COPY *.py .
COPY proxstar ./proxstar
RUN touch proxmox_ssh_key targets && chmod a+w proxmox_ssh_key targets # This is some OKD shit.
ENTRYPOINT ddtrace-run python3 wsgi.py
ENTRYPOINT ddtrace-run gunicorn proxstar:app --bind=0.0.0.0:8080

View file

@ -3,4 +3,4 @@ podman run --rm -d --network=proxstar --name=proxstar-redis redis:alpine
podman run --rm -d --network=proxstar --name=proxstar-postgres -e POSTGRES_PASSWORD=changeme -v ./HACKING/proxstar-postgres/volume:/var/lib/postgresql/data:Z proxstar-postgres
podman run --rm -d --network=proxstar --name=proxstar-rq-scheduler --env-file=HACKING/.env --entrypoint ./start_scheduler.sh proxstar
podman run --rm -d --network=proxstar --name=proxstar-rq --env-file=HACKING/.env --entrypoint ./start_worker.sh proxstar
podman run --rm -it --network=proxstar --name=proxstar -p 8000:8000 -p 8081:8081 --env-file=HACKING/.env --entrypoint='["python3", "wsgi.py"]' proxstar
podman run --rm -it --network=proxstar --name=proxstar -p 8000:8000 -p 8081:8081 --env-file=HACKING/.env --entrypoint='["gunicorn", "proxstar:app", "--bind=0.0.0.0:8000"]' proxstar

View file

View file

@ -2,7 +2,6 @@ import os
import subprocess
from flask import Flask
app = Flask(__name__)
if os.path.exists(os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config_local.py")):
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config_local.py")
@ -34,5 +33,5 @@ def start_websockify(websockify_path, target_file):
def on_starting(server):
print("Starting Websockify...")
print("Booting Websockify server in daemon mode...")
start_websockify(app.config['WEBSOCKIFY_PATH'], app.config['WEBSOCKIFY_TARGET_FILE'])

View file

@ -6,7 +6,7 @@ import logging
import subprocess
import psutil
import psycopg2
from gunicorn_conf import start_websockify
# from gunicorn_conf import start_websockify
import rq_dashboard
from rq import Queue
from redis import Redis
@ -73,9 +73,9 @@ app.config['GIT_REVISION'] = (
)
# Probably cursed.
if 'localhost' in app.config['SERVER_NAME']:
print('Server name is localhost. Starting websockify...')
start_websockify(app.config['WEBSOCKIFY_PATH'], app.config['WEBSOCKIFY_TARGET_FILE'])
# if 'localhost' in app.config['SERVER_NAME']:
# print('Server name is localhost. Starting websockify...')
# start_websockify(app.config['WEBSOCKIFY_PATH'], app.config['WEBSOCKIFY_TARGET_FILE'])
# Sentry setup
sentry_sdk.init(
@ -598,6 +598,7 @@ def cleanup_vnc():
with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets:
targets.truncate()
return '', 200
print("Got bad cleanup request")
return '', 403
# if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']:
# for target in get_vnc_targets():

View file

@ -233,8 +233,17 @@ def cleanup_vnc_task():
ones every couple of minutes
https://github.com/ComputerScienceHouse/proxstar/issues/153
"""
requests.post(
f'https://{app.config["VNC_HOST"]}/console/cleanup',
data={'token': app.config['VNC_CLEANUP_TOKEN']},
verify=False,
)
print('Clearing vnc targets')
with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets:
targets.truncate()
# FIXME (willnilges): This is straight-up not working, no matter what I try.
# The whole scheduling system needs a lotta work.
try:
requests.post(
f'https://proxstar.csh.rit.edu/console/cleanup',
data={'token': app.config['VNC_CLEANUP_TOKEN']},
verify=False,
)
except Exception as e:
print(e)

View file

@ -14,11 +14,12 @@ from proxstar.util import gen_password
def stop_websockify():
result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False)
if result.stdout:
pid = result.stdout.strip()
subprocess.run(['kill', pid], stdout=subprocess.PIPE, check=False)
time.sleep(3)
pids = result.stdout.splitlines()
for pid in pids:
subprocess.run(['kill', pid], stdout=subprocess.PIPE, check=False)
time.sleep(1)
if subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False).stdout:
time.sleep(10)
time.sleep(5)
if subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False).stdout:
logging.info("websockify didn't stop, killing forcefully")
subprocess.run(['kill', '-9', pid], stdout=subprocess.PIPE, check=False)