From 440f1a10d7ca7b3528442103c0a055d7d104f6f6 Mon Sep 17 00:00:00 2001 From: kaku Date: Thu, 23 May 2024 15:32:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app_control.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 app_control.sh diff --git a/.gitignore b/.gitignore index 9f7550b..d59972f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ .venv +conf/app.ini \ No newline at end of file diff --git a/app_control.sh b/app_control.sh new file mode 100644 index 0000000..0e1fc94 --- /dev/null +++ b/app_control.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +VENV_DIR=".venv" +PYTHON_APP="main.py" + +start_app() { + source "$VENV_DIR/bin/activate" + nohup python3 $PYTHON_APP > output.log 2>&1 & + echo -e "\033[32m Application started! \033[0m" +} + +stop_app() { + pid=$(ps aux | grep $PYTHON_APP | grep -v grep | awk '{print $2}') + if [ -n "$pid" ]; then + kill $pid + echo -e "\033[32m Application ended! \033[0m" + else + echo -e "\033[31m Application not runing! \033[0m" + fi +} + +check_app_status() { + pid=$(ps aux | grep $PYTHON_APP | grep -v grep | awk '{print $2}') + if [ -n "$pid" ]; then + echo -e "PID:" $pid + echo -e "\033[32m Application runing! \033[0m" + else + echo -e "\033[31m Application not runing! \033[0m" + fi +} + +case "$1" in + start) + start_app + ;; + stop) + stop_app + ;; + status) + check_app_status + ;; + *) + echo -e "\033[33m Usage: $0 {start|stop|status}\033[0m" + exit 1 + ;; +esac