From f0f9ac92e61d6adde88c752596f0d0ca7bc4d0af Mon Sep 17 00:00:00 2001
From: Galonza Peter
Date: Mon, 18 Oct 2021 02:24:09 +0300
Subject: [PATCH] added gunicorn start
---
src/dashboard.py | 22 ++++++++++++++--------
src/gunicorn.conf.py | 6 ++++++
src/wgd.sh | 30 ++++++++++++++++++++++--------
src/wsgi.py | 6 ------
4 files changed, 42 insertions(+), 22 deletions(-)
create mode 100644 src/gunicorn.conf.py
delete mode 100644 src/wsgi.py
diff --git a/src/dashboard.py b/src/dashboard.py
index c073e35..691ebb5 100644
--- a/src/dashboard.py
+++ b/src/dashboard.py
@@ -1161,8 +1161,12 @@ def check_update():
else:
return "true"
-def run_wsgi():
+"""
+Configure DashBoard before start web-server
+"""
+def run_dashboard():
init_dashboard()
+ update = check_update()
global config
config = configparser.ConfigParser(strict=False)
config.read('wg-dashboard.ini')
@@ -1175,13 +1179,15 @@ def run_wsgi():
config.clear()
return app
-if __name__ == "__main__":
- init_dashboard()
- update = check_update()
- config = configparser.ConfigParser(strict=False)
- config.read('wg-dashboard.ini')
+"""
+Get host and port for web-server
+"""
+def get_host_bind():
app_ip = config.get("Server", "app_ip")
app_port = config.get("Server", "app_port")
- wg_conf_path = config.get("Server", "wg_conf_path")
- config.clear()
+
+ return app_ip, app_port
+
+if __name__ == "__main__":
+ run_dashboard()
app.run(host=app_ip, debug=False, port=app_port)
\ No newline at end of file
diff --git a/src/gunicorn.conf.py b/src/gunicorn.conf.py
new file mode 100644
index 0000000..5ff8f4d
--- /dev/null
+++ b/src/gunicorn.conf.py
@@ -0,0 +1,6 @@
+import dashboard
+
+app_host, app_port = dashboard.get_host_bind()
+bind = f"{app_host}:{app_port}"
+daemon = True
+pidfile = './gunicorn.pid'
diff --git a/src/wgd.sh b/src/wgd.sh
index 3676947..bba0828 100755
--- a/src/wgd.sh
+++ b/src/wgd.sh
@@ -2,6 +2,7 @@
app_name="dashboard.py"
app_official_name="WGDashboard"
+environment=$(if [[ $ENVIRONMENT ]] ; then echo $ENVIRONMENT else echo 'develop')
dashes='------------------------------------------------------------'
equals='============================================================'
help () {
@@ -50,15 +51,28 @@ check_wgd_status(){
}
start_wgd () {
- printf "%s\n" "$dashes"
- printf "| Starting WGDashboard in the background. |\n"
- if [ ! -d "log" ]
- then mkdir "log"
+ if [[ $environment == 'production']]; then
+ printf "%s\n" "$dashes"
+ printf "| Starting WGDashboard in the background. |\n"
+ if [ ! -d "log" ]
+ then mkdir "log"
+ fi
+ d=$(date '+%Y%m%d%H%M%S')
+ /usr/local/bin/gunicorn --access-logfile log/access_"$d".log \
+ --error-logfile log/error_"$d".log 'dashboard.run_dashboard()'
+ printf "| Log files is under log/ |\n"
+ printf "%s\n" "$dashes"
+ else
+ printf "%s\n" "$dashes"
+ printf "| Starting WGDashboard in the background. |\n"
+ if [ ! -d "log" ]
+ then mkdir "log"
+ fi
+ d=$(date '+%Y%m%d%H%M%S')
+ python3 "$app_name" > log/"$d".txt 2>&1 &
+ printf "| Log files is under log/ |\n"
+ printf "%s\n" "$dashes"
fi
- d=$(date '+%Y%m%d%H%M%S')
- python3 "$app_name" > log/"$d".txt 2>&1 &
- printf "| Log files is under log/ |\n"
- printf "%s\n" "$dashes"
}
stop_wgd() {
diff --git a/src/wsgi.py b/src/wsgi.py
deleted file mode 100644
index 97c15b1..0000000
--- a/src/wsgi.py
+++ /dev/null
@@ -1,6 +0,0 @@
-import dashboard
-
-
-if __name__ in "__main__":
- dashboard.run_wsgi()
- dashboard.app.run()