@@ -15,13 +15,20 @@ FLASK_PORT="${FLASK_PORT:-5050}"
15
15
LOG_FILE=" /home/$( whoami) /logs/systemdashboard_flask.log"
16
16
USERNAME=" $( whoami) "
17
17
18
+ # Ensure log directory exists
19
+ LOG_DIR=" $( dirname " $LOG_FILE " ) "
20
+ mkdir -p " $LOG_DIR "
21
+
18
22
# Check for Miniconda3 and Anaconda3
19
23
CONDA_PATHS=(" /home/$USERNAME /miniconda3" " /home/$USERNAME /anaconda3" )
20
24
CONDA_FOUND=false
21
25
26
+ # Find which Conda is installed and set $CONDA_EXECUTABLE
22
27
for CONDA_PATH in " ${CONDA_PATHS[@]} " ; do
23
28
if [ -d " $CONDA_PATH " ]; then
24
29
CONDA_FOUND=true
30
+ CONDA_EXECUTABLE=" $CONDA_PATH /bin/conda"
31
+ CONDA_SETUP_SCRIPT=" $CONDA_PATH /etc/profile.d/conda.sh"
25
32
break
26
33
fi
27
34
done
@@ -31,9 +38,6 @@ if [ "$CONDA_FOUND" = false ]; then
31
38
exit 1
32
39
fi
33
40
34
- # Derive the path to the Conda setup script
35
- CONDA_SETUP_SCRIPT=" $CONDA_PATH /etc/profile.d/conda.sh"
36
-
37
41
# Check if Conda setup script exists
38
42
if [ ! -f " $CONDA_SETUP_SCRIPT " ]; then
39
43
log_message " Conda setup script not found at $CONDA_SETUP_SCRIPT ."
44
48
source " $CONDA_SETUP_SCRIPT "
45
49
46
50
# Define Conda environment name
47
- CONDA_ENV_NAME=" systemdashboard "
51
+ CONDA_ENV_NAME=" dashboard "
48
52
53
+ echo " Conda environment name: $CONDA_ENV_NAME "
54
+ echo $CONDA_EXECUTABLE
49
55
# 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
51
57
log_message " Conda environment '$CONDA_ENV_NAME ' not found. Creating it..."
52
58
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 "
57
63
else
58
64
log_message " Activating existing Conda environment '$CONDA_ENV_NAME '."
59
- conda activate " $CONDA_ENV_NAME "
60
65
fi
61
66
62
67
# 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
71
76
# git pull in FLASK_APP_PATH directory
72
77
current_dir=$( pwd)
73
78
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
75
84
cd " $current_dir "
76
85
77
86
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 " &
79
89
else
80
90
log_message " Flask app is already running."
81
91
fi
0 commit comments