diff --git a/dashboard.sh b/dashboard.sh index 9875d50..fcdb779 100755 --- a/dashboard.sh +++ b/dashboard.sh @@ -15,13 +15,20 @@ FLASK_PORT="${FLASK_PORT:-5050}" LOG_FILE="/home/$(whoami)/logs/systemdashboard_flask.log" USERNAME="$(whoami)" +# Ensure log directory exists +LOG_DIR="$(dirname "$LOG_FILE")" +mkdir -p "$LOG_DIR" + # Check for Miniconda3 and Anaconda3 CONDA_PATHS=("/home/$USERNAME/miniconda3" "/home/$USERNAME/anaconda3") CONDA_FOUND=false +# Find which Conda is installed and set $CONDA_EXECUTABLE for CONDA_PATH in "${CONDA_PATHS[@]}"; do if [ -d "$CONDA_PATH" ]; then CONDA_FOUND=true + CONDA_EXECUTABLE="$CONDA_PATH/bin/conda" + CONDA_SETUP_SCRIPT="$CONDA_PATH/etc/profile.d/conda.sh" break fi done @@ -31,9 +38,6 @@ if [ "$CONDA_FOUND" = false ]; then exit 1 fi -# Derive the path to the Conda setup script -CONDA_SETUP_SCRIPT="$CONDA_PATH/etc/profile.d/conda.sh" - # Check if Conda setup script exists if [ ! -f "$CONDA_SETUP_SCRIPT" ]; then log_message "Conda setup script not found at $CONDA_SETUP_SCRIPT." @@ -44,19 +48,20 @@ fi source "$CONDA_SETUP_SCRIPT" # Define Conda environment name -CONDA_ENV_NAME="systemdashboard" +CONDA_ENV_NAME="dashboard" +echo "Conda environment name: $CONDA_ENV_NAME" +echo $CONDA_EXECUTABLE # Check if the Conda environment exists and create it if not -if ! conda env list | grep -q "$CONDA_ENV_NAME"; then +if ! conda info --envs | awk '{print $1}' | grep -q "^$CONDA_ENV_NAME$"; then log_message "Conda environment '$CONDA_ENV_NAME' not found. Creating it..." conda create -n "$CONDA_ENV_NAME" python=3.10 -y - log_message "Activating Conda environment '$CONDA_ENV_NAME'." - conda activate "$CONDA_ENV_NAME" - log_message "Installing required packages." - pip install -r "$REQUIREMENTS_FILE" + + log_message "Activating Conda environment '$CONDA_ENV_NAME' and installing requirements." + # Use `conda run` to execute commands in the environment + conda run -n "$CONDA_ENV_NAME" pip install -r "$REQUIREMENTS_FILE" else log_message "Activating existing Conda environment '$CONDA_ENV_NAME'." - conda activate "$CONDA_ENV_NAME" fi # 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 # git pull in FLASK_APP_PATH directory current_dir=$(pwd) cd "$SCRIPT_DIR" - git stash && git pull + if ! git pull; then + log_message "Failed to pull updates from Git repository." + cd "$current_dir" + exit 1 + fi cd "$current_dir" log_message "Starting Flask app..." - flask run --host=0.0.0.0 --port="$FLASK_PORT" & + # Ensure environment activation and `flask` command + bash -c "source $CONDA_SETUP_SCRIPT && conda activate $CONDA_ENV_NAME && flask run --host=0.0.0.0 --port=$FLASK_PORT" &>> "$LOG_FILE" & else log_message "Flask app is already running." fi diff --git a/requirements.txt b/requirements.txt index ca16e84..8c187f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ Flask==2.3.3 psutil==5.9.5 gunicorn -speetest-cli flask-sqlalchemy -flask-login \ No newline at end of file +flask-login +flask-session \ No newline at end of file