diff --git a/.gitignore b/.gitignore index 8104ed3..6ec7b5e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ src/wg-dashboard.ini src/static/pic.xd *.conf private_key.txt -public_key.txt \ No newline at end of file +public_key.txt +venv/** +log/** +*~ \ No newline at end of file diff --git a/README.md b/README.md index 333bd4b..a2577bf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@
-

Please provide your OS name and version if you can run the dashboard on it perfectly in #31, since I only tested on Ubuntu. Thank you!

-
+> Hi! I'm planning the next major update for this project, please let me know if you have any suggestions or feature requests ;) You can create an issue with the "Feature request" template. Cheers! +### Help Wanted + +> If anyone know a better way to distribute releases of python application other than GitHub, please let me know in #103! + +> Please provide your OS name and version if you can run the dashboard on it perfectly in #31, since I only tested on Ubuntu. Thank you! + +

WGDashboard

@@ -13,6 +19,7 @@

+ wakatime

Monitoring WireGuard is not convinient, need to login into server and type wg show. That's why this platform is being created, to view all configurations and manage them in a easier way.

Note: This project is not affiliate to the official WireGuard Project ;)

diff --git a/src/wg-dashboard.service b/src/wg-dashboard.service index 9a596df..44b5c43 100644 --- a/src/wg-dashboard.service +++ b/src/wg-dashboard.service @@ -1,11 +1,14 @@ [Unit] -After=netword.service +After=syslog.target network-online.target +ConditionPathIsDirectory=/etc/wireguard [Service] -WorkingDirectory= -ExecStart=/usr/bin/python3 dashboard.py +Environment="VIRTUAL_ENV={{VIRTUAL_ENV}}" +WorkingDirectory={{APP_ROOT}} +ExecStart={{VIRTUAL_ENV}}/bin/python3 {{APP_ROOT}}dashboard.py +PrivateTmp=yes Restart=always [Install] -WantedBy=default.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/src/wgd.sh b/src/wgd.sh index 39442c2..2b29a88 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -29,6 +29,17 @@ help () { printf "=================================================================================\n" } +_check_and_set_venv(){ + # deb/ubuntu users: might need a 'apt install python3.8-venv' + # set up the local environment + APP_ROOT=`pwd` + VIRTUAL_ENV="${APP_ROOT%/*}/venv" + if [ ! -d $VIRTUAL_ENV ]; then + python3 -m venv $VIRTUAL_ENV + fi + . ${VIRTUAL_ENV}/activate +} + install_wgd(){ # Check Python3 version version_pass=$(python3 -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 7) else print("0");') @@ -42,9 +53,24 @@ install_wgd(){ then mkdir "log" fi printf "| Installing latest Python dependencies |\n" + + # set up the local environment + _check_and_set_venv + python3 -m pip install -r requirements.txt > /dev/null 2>&1 printf "| WGDashboard installed successfully! |\n" - printf "| Starting Dashboard |\n" + + printf "| Preparing the systemctl unit file |\n" + sed -i "s#{{APP_ROOT}}#${APP_ROOT}#" wg-dashboard.service + sed -i "s#{{VIRTUAL_ENV}}#${VIRTUAL_ENV}#" wg-dashboard.service + cat wg-dashboard.service | sudo SYSTEMD_EDITOR=tee systemctl edit --force --full wg-dashboard.service + systemctl daemon-reload + printf "| Consider 'systemctl enable wg-dashboard' |\n" + printf " and 'systemctl start wg-dashboard'\n" + printf " use '${0} stop' before starting with systemctl\n" + echo + + printf "| Now starting Dashboard in background |\n" start_wgd } @@ -108,6 +134,7 @@ gunicorn_stop () { } start_wgd () { + _check_and_set_venv if [[ $environment == 'production' ]]; then gunicorn_start else @@ -132,6 +159,7 @@ stop_wgd() { } start_wgd_debug() { + _check_and_set_venv printf "%s\n" "$dashes" printf "| Starting WGDashboard in the foreground. |\n" python3 "$app_name" @@ -150,6 +178,7 @@ update_wgd() { git stash > /dev/null 2>&1 git pull https://github.com/donaldzou/wireguard-dashboard.git $new_ver --force > /dev/null 2>&1 printf "| Installing latest Python dependencies |\n" + _check_and_set_venv python3 -m pip install -r requirements.txt > /dev/null 2>&1 printf "| Update Successfully! |\n" start_wgd @@ -208,4 +237,3 @@ if [ "$#" != 1 ]; help fi fi -