mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
Update websockify-related tasks
This commit is contained in:
parent
d0af3a9567
commit
7ab74fb2e4
5 changed files with 43 additions and 30 deletions
|
@ -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-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-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 -d --network=proxstar --name=proxstar-rq --env-file=HACKING/.env --entrypoint ./start_worker.sh proxstar
|
||||||
podman run --rm -d --network=proxstar --name=proxstar -p 8000:8000 --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='["python3", "wsgi.py"]' proxstar
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
podman stop proxstar
|
podman kill proxstar
|
||||||
podman stop proxstar-rq
|
podman kill proxstar-rq
|
||||||
podman stop proxstar-rq-scheduler
|
podman kill proxstar-rq-scheduler
|
||||||
podman stop proxstar-redis
|
podman stop proxstar-redis
|
||||||
podman stop proxstar-postgres
|
podman stop proxstar-postgres
|
||||||
|
|
|
@ -125,6 +125,7 @@ if 'process_expiring_vms' not in scheduler:
|
||||||
logging.info('adding process expiring VMs task to scheduler')
|
logging.info('adding process expiring VMs task to scheduler')
|
||||||
scheduler.cron('0 5 * * *', id='process_expiring_vms', func=process_expiring_vms_task)
|
scheduler.cron('0 5 * * *', id='process_expiring_vms', func=process_expiring_vms_task)
|
||||||
|
|
||||||
|
# FIXME (willnilges): is this operating in the right container?
|
||||||
if 'cleanup_vnc' not in scheduler:
|
if 'cleanup_vnc' not in scheduler:
|
||||||
logging.info('adding cleanup VNC task to scheduler')
|
logging.info('adding cleanup VNC task to scheduler')
|
||||||
scheduler.schedule(
|
scheduler.schedule(
|
||||||
|
@ -134,7 +135,6 @@ if 'cleanup_vnc' not in scheduler:
|
||||||
interval=3600,
|
interval=3600,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_rq_dashboard_auth(blueprint):
|
def add_rq_dashboard_auth(blueprint):
|
||||||
@blueprint.before_request
|
@blueprint.before_request
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
|
@ -575,29 +575,34 @@ def allowed_users(user):
|
||||||
@app.route('/console/cleanup', methods=['POST'])
|
@app.route('/console/cleanup', methods=['POST'])
|
||||||
def cleanup_vnc():
|
def cleanup_vnc():
|
||||||
if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']:
|
if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']:
|
||||||
for target in get_vnc_targets():
|
with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets:
|
||||||
tunnel = next(
|
targets.truncate()
|
||||||
(tunnel for tunnel in ssh_tunnels if tunnel.local_bind_port == int(target['port'])),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
if tunnel:
|
|
||||||
if not next(
|
|
||||||
(
|
|
||||||
conn
|
|
||||||
for conn in psutil.net_connections()
|
|
||||||
if conn.laddr[1] == int(target['port']) and conn.status == 'ESTABLISHED'
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
):
|
|
||||||
try:
|
|
||||||
tunnel.stop()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
ssh_tunnels.remove(tunnel)
|
|
||||||
delete_vnc_target(target['port'])
|
|
||||||
return '', 200
|
return '', 200
|
||||||
else:
|
|
||||||
return '', 403
|
return '', 403
|
||||||
|
# if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']:
|
||||||
|
# for target in get_vnc_targets():
|
||||||
|
# tunnel = next(
|
||||||
|
# (tunnel for tunnel in ssh_tunnels if tunnel.local_bind_port == int(target['port'])),
|
||||||
|
# None,
|
||||||
|
# )
|
||||||
|
# if tunnel:
|
||||||
|
# if not next(
|
||||||
|
# (
|
||||||
|
# conn
|
||||||
|
# for conn in psutil.net_connections()
|
||||||
|
# if conn.laddr[1] == int(target['port']) and conn.status == 'ESTABLISHED'
|
||||||
|
# ),
|
||||||
|
# None,
|
||||||
|
# ):
|
||||||
|
# try:
|
||||||
|
# tunnel.stop()
|
||||||
|
# except:
|
||||||
|
# pass
|
||||||
|
# ssh_tunnels.remove(tunnel)
|
||||||
|
# delete_vnc_target(target['port'])
|
||||||
|
# return '', 200
|
||||||
|
# else:
|
||||||
|
# return '', 403
|
||||||
|
|
||||||
|
|
||||||
@app.route('/template/<string:template_id>/disk')
|
@app.route('/template/<string:template_id>/disk')
|
||||||
|
|
|
@ -227,8 +227,14 @@ def setup_template_task(template_id, name, user, ssh_key, cores, memory):
|
||||||
|
|
||||||
|
|
||||||
def cleanup_vnc_task():
|
def cleanup_vnc_task():
|
||||||
|
"""Removes all open VNC sessions. This runs in the RQ worker, and so
|
||||||
|
needs to be routed properly via the Proxstar API
|
||||||
|
TODO (willnilges): Use API, track the task IDs, and kill only the finished
|
||||||
|
ones every couple of minutes
|
||||||
|
https://github.com/ComputerScienceHouse/proxstar/issues/153
|
||||||
|
"""
|
||||||
requests.post(
|
requests.post(
|
||||||
'https://{}/console/cleanup'.format(app.config['SERVER_NAME']),
|
f'https://{app.config["VNC_HOST"]}/console/cleanup',
|
||||||
data={'token': app.config['VNC_CLEANUP_TOKEN']},
|
data={'token': app.config['VNC_CLEANUP_TOKEN']},
|
||||||
verify=False,
|
verify=False,
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,16 +32,18 @@ def get_vnc_targets():
|
||||||
target_dict = {}
|
target_dict = {}
|
||||||
values = line.strip().split(':')
|
values = line.strip().split(':')
|
||||||
target_dict['token'] = values[0]
|
target_dict['token'] = values[0]
|
||||||
target_dict['host'] = values[1] + values[2]
|
target_dict['host'] = f'{values[1].strip()}:{values[2]}'
|
||||||
targets.append(target_dict)
|
targets.append(target_dict)
|
||||||
target_file.close()
|
target_file.close()
|
||||||
return targets
|
return targets
|
||||||
|
|
||||||
def add_vnc_target(node, port):
|
def add_vnc_target(node, port):
|
||||||
# TODO (willnilges): This doesn't throw an error if the target file is wrong.
|
# TODO (willnilges): This doesn't throw an error if the target file is wrong.
|
||||||
|
# TODO (willnilges): This will duplicate targets
|
||||||
targets = get_vnc_targets()
|
targets = get_vnc_targets()
|
||||||
target = next((target for target in targets if target['host'] == f'{node}:{port}'), None)
|
target = next((target for target in targets if target['host'] == f'{node}:{port}'), None)
|
||||||
if target:
|
if target:
|
||||||
|
print('Host is already in the targets file')
|
||||||
return target['token']
|
return target['token']
|
||||||
else:
|
else:
|
||||||
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'a')
|
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'a')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue