@@ -15,13 +15,20 @@ FLASK_PORT="${FLASK_PORT:-5050}"
1515LOG_FILE=" /home/$( whoami) /logs/systemdashboard_flask.log"
1616USERNAME=" $( whoami) "
1717
18+ # Ensure log directory exists
19+ LOG_DIR=" $( dirname " $LOG_FILE " ) "
20+ mkdir -p " $LOG_DIR "
21+
1822# Check for Miniconda3 and Anaconda3
1923CONDA_PATHS=(" /home/$USERNAME /miniconda3" " /home/$USERNAME /anaconda3" )
2024CONDA_FOUND=false
2125
26+ # Find which Conda is installed and set $CONDA_EXECUTABLE
2227for CONDA_PATH in " ${CONDA_PATHS[@]} " ; do
2328 if [ -d " $CONDA_PATH " ]; then
2429 CONDA_FOUND=true
30+ CONDA_EXECUTABLE=" $CONDA_PATH /bin/conda"
31+ CONDA_SETUP_SCRIPT=" $CONDA_PATH /etc/profile.d/conda.sh"
2532 break
2633 fi
2734done
@@ -31,9 +38,6 @@ if [ "$CONDA_FOUND" = false ]; then
3138 exit 1
3239fi
3340
34- # Derive the path to the Conda setup script
35- CONDA_SETUP_SCRIPT=" $CONDA_PATH /etc/profile.d/conda.sh"
36-
3741# Check if Conda setup script exists
3842if [ ! -f " $CONDA_SETUP_SCRIPT " ]; then
3943 log_message " Conda setup script not found at $CONDA_SETUP_SCRIPT ."
4448source " $CONDA_SETUP_SCRIPT "
4549
4650# Define Conda environment name
47- CONDA_ENV_NAME=" systemdashboard "
51+ CONDA_ENV_NAME=" dashboard "
4852
53+ echo " Conda environment name: $CONDA_ENV_NAME "
54+ echo $CONDA_EXECUTABLE
4955# Check if the Conda environment exists and create it if not
50- if ! conda env list | grep -q " $CONDA_ENV_NAME " ; then
56+ if ! conda info --envs | awk ' {print $1} ' | grep -q " ^ $CONDA_ENV_NAME $ " ; then
5157 log_message " Conda environment '$CONDA_ENV_NAME ' not found. Creating it..."
5258 conda create -n " $CONDA_ENV_NAME " python=3.10 -y
53- log_message " Activating Conda environment ' $CONDA_ENV_NAME '. "
54- conda activate " $CONDA_ENV_NAME "
55- log_message " Installing required packages. "
56- pip install -r " $REQUIREMENTS_FILE "
59+
60+ log_message " Activating Conda environment ' $CONDA_ENV_NAME ' and installing requirements. "
61+ # Use `conda run` to execute commands in the environment
62+ conda run -n " $CONDA_ENV_NAME " pip install -r " $REQUIREMENTS_FILE "
5763else
5864 log_message " Activating existing Conda environment '$CONDA_ENV_NAME '."
59- conda activate " $CONDA_ENV_NAME "
6065fi
6166
6267# Continue with the rest of your script
@@ -71,11 +76,16 @@ if ! pgrep -f "flask run --host=0.0.0.0 --port=$FLASK_PORT" > /dev/null; then
7176 # git pull in FLASK_APP_PATH directory
7277 current_dir=$( pwd)
7378 cd " $SCRIPT_DIR "
74- git stash && git pull
79+ if ! git pull; then
80+ log_message " Failed to pull updates from Git repository."
81+ cd " $current_dir "
82+ exit 1
83+ fi
7584 cd " $current_dir "
7685
7786 log_message " Starting Flask app..."
78- flask run --host=0.0.0.0 --port=" $FLASK_PORT " &
87+ # Ensure environment activation and `flask` command
88+ bash -c " source $CONDA_SETUP_SCRIPT && conda activate $CONDA_ENV_NAME && flask run --host=0.0.0.0 --port=$FLASK_PORT " & >> " $LOG_FILE " &
7989else
8090 log_message " Flask app is already running."
8191fi
0 commit comments