Skip to content

Commit ef05db8

Browse files
chore: Update Conda environment name and install requirements
1 parent 4134dda commit ef05db8

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

dashboard.sh

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ FLASK_PORT="${FLASK_PORT:-5050}"
1515
LOG_FILE="/home/$(whoami)/logs/systemdashboard_flask.log"
1616
USERNAME="$(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
1923
CONDA_PATHS=("/home/$USERNAME/miniconda3" "/home/$USERNAME/anaconda3")
2024
CONDA_FOUND=false
2125

26+
# Find which Conda is installed and set $CONDA_EXECUTABLE
2227
for 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
2734
done
@@ -31,9 +38,6 @@ if [ "$CONDA_FOUND" = false ]; then
3138
exit 1
3239
fi
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
3842
if [ ! -f "$CONDA_SETUP_SCRIPT" ]; then
3943
log_message "Conda setup script not found at $CONDA_SETUP_SCRIPT."
@@ -44,19 +48,20 @@ fi
4448
source "$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"
5763
else
5864
log_message "Activating existing Conda environment '$CONDA_ENV_NAME'."
59-
conda activate "$CONDA_ENV_NAME"
6065
fi
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" &
7989
else
8090
log_message "Flask app is already running."
8191
fi

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Flask==2.3.3
22
psutil==5.9.5
33
gunicorn
4-
speetest-cli
54
flask-sqlalchemy
6-
flask-login
5+
flask-login
6+
flask-session

0 commit comments

Comments
 (0)