From 94a0d5a0a47232f6c1cfbea6332cba1f265f7440 Mon Sep 17 00:00:00 2001
From: Galonza Peter
Date: Mon, 25 Oct 2021 00:24:49 +0300
Subject: [PATCH] refactored
---
src/wgd.sh | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/src/wgd.sh b/src/wgd.sh
index 2e034537..0e705798 100755
--- a/src/wgd.sh
+++ b/src/wgd.sh
@@ -57,21 +57,29 @@ check_wgd_status(){
fi
}
+gunicorn_start () {
+ 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')
+ if [[ $USER == root ]]; then
+ export PATH=$PATH:/usr/local/bin:$HOME/.local/bin
+ fi
+ 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"
+}
+
+gunicorn_stop () {
+ kill $(cat ./gunicorn.pid)
+}
+
start_wgd () {
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')
- if [[ $USER == root ]]; then
- export PATH=$PATH:/usr/local/bin:$HOME/.local/bin
- fi
- 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"
+ gunicorn_start
else
printf "%s\n" "$dashes"
printf "| Starting WGDashboard in the background. |\n"
@@ -87,7 +95,7 @@ start_wgd () {
stop_wgd() {
if [[ $environment == 'production' ]]; then
- kill $(cat ./gunicorn.pid)
+ gunicorn_stop
else
kill "$(ps aux | grep "[p]ython3 $app_name" | awk '{print $2}')"
fi