From 8c3f1174825cc1d0001b3bb86acce567666b8d44 Mon Sep 17 00:00:00 2001 From: Devin Dice Date: Fri, 20 Jan 2023 20:46:17 -0500 Subject: [PATCH] No desktop option --- rootfs/workspace/configuration/configure.py | 32 +++++++++ .../workspace/configuration/nginx_default.j2 | 54 +++++++++++++++ .../configuration/supervisord.conf.j2 | 67 +++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100755 rootfs/workspace/configuration/configure.py create mode 100644 rootfs/workspace/configuration/nginx_default.j2 create mode 100644 rootfs/workspace/configuration/supervisord.conf.j2 diff --git a/rootfs/workspace/configuration/configure.py b/rootfs/workspace/configuration/configure.py new file mode 100755 index 0000000..f2c85f4 --- /dev/null +++ b/rootfs/workspace/configuration/configure.py @@ -0,0 +1,32 @@ +#!/usr/local/bin/python +from jinja2 import Environment, FileSystemLoader +from os import mkdir, path +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument("--desktop", help="Accepts 'enabled' or 'disabled'") +args = parser.parse_args() + +# Default Nginx +environment = Environment(loader=FileSystemLoader("./")) +template = environment.get_template("nginx_default.j2") +filename = f"../../etc/nginx/sites-enabled/default" +content = template.render( + desktop=args.desktop, +) +with open(filename, mode="w", encoding="utf-8") as message: + message.write(content) + print(f"... wrote {filename}") + + +# Supervisor Conf +environment = Environment(loader=FileSystemLoader("./")) +template = environment.get_template("supervisord.conf.j2") +filename = f"../../etc/supervisor/conf.d/supervisord.conf" + +content = template.render( + desktop=args.desktop, +) +with open(filename, mode="w", encoding="utf-8") as message: + message.write(content) + print(f"... wrote {filename}") \ No newline at end of file diff --git a/rootfs/workspace/configuration/nginx_default.j2 b/rootfs/workspace/configuration/nginx_default.j2 new file mode 100644 index 0000000..8d931f8 --- /dev/null +++ b/rootfs/workspace/configuration/nginx_default.j2 @@ -0,0 +1,54 @@ +server { + listen 6080 default_server; + {% if desktop != "enabled" %} + root /usr/local/lib/web/disabled/; + index index.html index.htm; + {% else %} + #_SSL_PORT_#listen 443 ssl default_server; + #_SSL_PORT_#listen [::]:443 ssl default_server ipv6only=on; + #_SSL_PORT_#ssl_certificate /etc/nginx/ssl/nginx.crt; + #_SSL_PORT_#ssl_certificate_key /etc/nginx/ssl/nginx.key; + + #_HTTP_PASSWORD_#auth_basic "Private Property"; + #_HTTP_PASSWORD_#auth_basic_user_file /etc/nginx/.htpasswd; + + root /usr/local/lib/web/frontend/; + index index.html index.htm; + + #_RELATIVE_URL_ROOT_location /_RELATIVE_URL_ROOT_/ { + #_RELATIVE_URL_ROOT_ rewrite /_RELATIVE_URL_ROOT_/(.*) /$1 break; + #_RELATIVE_URL_ROOT_ root /usr/local/lib/web/frontend/; + #_RELATIVE_URL_ROOT_} + + location ~ .*/(api/.*|websockify) { + try_files $uri @api$http_upgrade; + } + + location / { + rewrite /approot/(.*) /$1 break; + root /usr/local/lib/web/frontend/; + } + + location @apiwebsocket { + #_RELATIVE_URL_ROOT_rewrite /_RELATIVE_URL_ROOT_/(.*) $1 break; + proxy_connect_timeout 7d; + proxy_send_timeout 7d; + proxy_read_timeout 7d; + proxy_buffering off; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_pass http://127.0.0.1:6081; + } + + location @api { + #_RELATIVE_URL_ROOT_rewrite /_RELATIVE_URL_ROOT_/(.*) $1 break; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Host $host; + max_ranges 0; + proxy_pass http://127.0.0.1:6079; + } + {% endif %} +} \ No newline at end of file diff --git a/rootfs/workspace/configuration/supervisord.conf.j2 b/rootfs/workspace/configuration/supervisord.conf.j2 new file mode 100644 index 0000000..1dd6f93 --- /dev/null +++ b/rootfs/workspace/configuration/supervisord.conf.j2 @@ -0,0 +1,67 @@ +[supervisord] +redirect_stderr=true +stopsignal=QUIT +autorestart=true +directory=/root + +[program:nginx] +priority=10 +command=nginx -c /etc/nginx/nginx.conf -g 'daemon off;' + +{% if desktop == "enabled" %} +[program:web] +priority=10 +directory=/usr/local/lib/web/backend +command=/usr/local/lib/web/backend/run.py +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 + +[group:x] +programs=xfce4,xvfb,x11vnc,novnc,cloud9,desktop +{% else %} +[group:x] +programs=cloud9 +{% endif %} + +[program:xfce4] +priority=15 +directory=%HOME% +command=/usr/bin/startxfce4 +user=%USER% +environment=DISPLAY=":1",HOME="%HOME%",USER="%USER%" + +[program:xvfb] +priority=10 +command=/usr/local/bin/xvfb.sh +stopsignal=KILL + +[program:x11vnc] +priority=20 +command=bash -c 'x11vnc -display :1 -xkb -forever -shared -repeat -capslock || rm /tmp/.X11-unix/X1 /tmp/.X1-lockfb' + +[program:novnc] +priority=25 +directory=/usr/local/lib/web/frontend/static/novnc +command=bash /usr/local/lib/web/frontend/static/novnc/utils/launch.sh --listen 6081 +stopasgroup=true + +[program:cloud9] +priority=25 +directory=/cloud9/c9sdk +user=%USER% +command=bash -c 'while ps aux | grep user-install.sh | grep -v grep 2>&1> /dev/null; do sleep 1; done; node server.js -l 0.0.0.0 -p 9999 -a : -w /workspace' + +[program:desktop] +priority=30 +directory=/home/%USER%/.dynamic-background/active +user=%USER% +command=bash /usr/share/backgrounds/dynamic.sh + +[program:desktop] +priority=25 +directory=/cloud9/c9sdk +user=%USER% +command=bash -c 'while ps aux | grep user-install.sh | grep -v grep 2>&1> /dev/null; do sleep 1; done; node server.js -l 0.0.0.0 -p 9999 -a : -w /workspace' +