Skip to content

Commit 99af8cd

Browse files
committed
refactor: code restructure
1. split frontend and backend 2. simplify supervisor configuration 3. align backend log format with supervisor 4. set nginx worker to 1 5. delete static web pages
1 parent f5da5d1 commit 99af8cd

21 files changed

+14
-292
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RUN chmod +x /bin/tini
3838
RUN mkdir -p /usr/local/ffmpeg \
3939
&& curl -sSL https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz | tar xJvf - -C /usr/local/ffmpeg/ --strip 1
4040

41-
ADD image/usr/local/lib/web/requirements.txt /tmp/
41+
ADD image/usr/local/lib/web/backend/requirements.txt /tmp/
4242
RUN pip install setuptools wheel && pip install -r /tmp/requirements.txt
4343
ADD image /
4444

image/etc/supervisor/conf.d/supervisord.conf

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ directory=/root
77
[program:nginx]
88
priority=10
99
command=nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
10-
stdout_logfile=/var/log/nginx.log
1110

1211
[program:web]
1312
priority=10
14-
directory=/usr/local/lib/web
15-
command=/usr/local/lib/web/run.py
16-
stdout_logfile=/var/log/web.log
13+
directory=/usr/local/lib/web/backend
14+
command=/usr/local/lib/web/backend/run.py
15+
stdout_logfile=/dev/fd/1
16+
stdout_logfile_maxbytes=0
1717

1818
[group:x]
1919
programs=xvfb,wm,lxpanel,pcmanfm,x11vnc,novnc
@@ -22,38 +22,32 @@ programs=xvfb,wm,lxpanel,pcmanfm,x11vnc,novnc
2222
priority=10
2323
command=/usr/local/bin/xvfb.sh
2424
stopsignal=KILL
25-
stdout_logfile=/var/log/xvfb.log
2625

2726
[program:wm]
2827
priority=15
2928
command=/usr/bin/openbox
3029
environment=DISPLAY=":1",HOME="/root",USER="root"
31-
stdout_logfile=/var/log/openbox.log
3230

3331
[program:lxpanel]
3432
priority=15
3533
directory=%HOME%
3634
command=/usr/bin/lxpanel --profile LXDE
3735
user=%USER%
3836
environment=DISPLAY=":1",HOME="%HOME%",USER="%USER%"
39-
stdout_logfile=/var/log/lxpanel.log
4037

4138
[program:pcmanfm]
4239
priority=15
4340
directory=%HOME%
4441
command=/usr/bin/pcmanfm --desktop --profile LXDE
4542
user=%USER%
4643
environment=DISPLAY=":1",HOME="%HOME%",USER="%USER%"
47-
stdout_logfile=/var/log/pcmanfm.log
4844

4945
[program:x11vnc]
5046
priority=20
5147
command=x11vnc -display :1 -xkb -forever -shared -repeat
52-
stdout_logfile=/var/log/x11vnc.log
5348

5449
[program:novnc]
5550
priority=25
5651
directory=/usr/local/lib/novnc/
5752
command=/usr/local/lib/novnc/utils/launch.sh --listen 6081
58-
stdout_logfile=/var/log/novnc.log
5953
stopasgroup=true

image/startup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ mkdir -p $HOME/.config/pcmanfm/LXDE/
3232
ln -sf /usr/local/share/doro-lxde-wallpapers/desktop-items-0.conf $HOME/.config/pcmanfm/LXDE/
3333
chown -R $USER:$USER $HOME
3434

35+
# nginx
36+
sed -i 's#worker_processes .*#worker_processes 1;#' /etc/nginx/nginx.conf
37+
3538
# clearup
3639
PASSWORD=
3740

image/usr/local/lib/web/log/config.py renamed to image/usr/local/lib/web/backend/log/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ def format(self, record):
3535

3636

3737
class LoggingConfiguration(object):
38-
COLOR_FORMAT = "[%(asctime)s" + \
39-
"][%(threadName)-22s][%(levelname)s] %(message)s " + \
38+
COLOR_FORMAT = "%(asctime)s" + \
39+
" %(levelname)s %(message)s " + \
4040
"(" + BOLD_SEQ + "%(filename)s" + RESET_SEQ + ":%(lineno)d)"
41-
NO_COLOR_FORMAT = "[%(asctime)s][%(threadName)-22s][%(levelname)s] " + \
41+
NO_COLOR_FORMAT = "%(asctime)s %(levelname)s " + \
4242
"%(message)s " + \
4343
"(%(filename)s:%(lineno)d)"
44-
FILE_FORMAT = "[%(asctime)s][%(threadName)-22s][%(levelname)s] " + \
44+
FILE_FORMAT = "%(asctime)s %(levelname)s " + \
4545
"%(message)s "
4646

4747
@classmethod

image/usr/local/lib/web/run.py renamed to image/usr/local/lib/web/backend/run.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,19 @@ def run_server():
7373
import socket
7474

7575
os.environ['CONFIG'] = CONFIG
76-
from lightop import app
76+
from vnc import app
7777

7878
# websocket conflict: WebSocketHandler
7979
if DEBUG or STAGING:
8080
# from werkzeug.debug import DebuggedApplication
8181
app.debug = True
8282
# app = DebuggedApplication(app, evalex=True)
8383

84-
print('Fork monitor programs')
8584
pgid = os.getpgid(0)
86-
procs = []
87-
procs.extend([subprocess.Popen(program, close_fds=True, shell=True)
88-
for program in PROGRAMS])
8985
signal.signal(signal.SIGTERM, lambda *args: killpg(pgid))
9086
signal.signal(signal.SIGHUP, lambda *args: killpg(pgid))
9187
signal.signal(signal.SIGINT, lambda *args: killpg(pgid))
9288

93-
print('Running on port ' + str(PORT))
9489
try:
9590
app.run(host='', port=PORT)
9691
except socket.error as e:
@@ -101,7 +96,6 @@ def run_server():
10196
CONFIG = 'config.Development' if DEBUG else 'config.Production'
10297
CONFIG = 'config.Staging' if STAGING else CONFIG
10398
PORT = 6079
104-
PROGRAMS = tuple()
10599
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
106100

107101
if DEBUG or STAGING:

image/usr/local/lib/web/lightop/__init__.py renamed to image/usr/local/lib/web/backend/vnc/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111

1212
# Flask app
13-
app = Flask(
14-
__name__,
15-
static_folder='static', static_url_path='',
16-
instance_relative_config=True
17-
)
13+
app = Flask('novnc2')
1814
CONFIG = os.environ.get('CONFIG') or 'config.Development'
1915
app.config.from_object('config.Default')
2016
app.config.from_object(CONFIG)
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)