Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .bin/bkup/clear_all_services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Determine the environment (e.g., from an env var)
ENVIRONMENT=${ENVIRONMENT:-development}

# Source the appropriate .env file based on the environment
if [ "$ENVIRONMENT" == "development" ]; then
source .env
else
source .env.development
fi

# Function to check if a string is a valid numeric port
is_numeric_port() {
[[ $1 =~ ^[0-9]+$ ]]
}

# Function to clear a single port
clear_port() {
local PORT=$1

# Find the process ID using lsof
PID=$(lsof -i :$PORT -t)

if [ -z "$PID" ]; then
echo "No process found running on port $PORT."
else
echo "Killing process $PID running on port $PORT..."
kill $PID
if [ $? -eq 0 ]; then
echo "Process $PID has been successfully terminated."
else
echo "Failed to terminate process $PID."
fi
fi
}

# Read the .env file and extract ports with debugging output
while IFS='=' read -r key value; do
# Check if the line is a valid environment variable
if [[ "$key" == PORT* || "$key" == *_PORT ]]; then
echo "Found port variable: $key=$value"
# Check if the value is a numeric port
if is_numeric_port "$value"; then
clear_port "$value"
else
echo "Skipping non-numeric port value: $key=$value"
fi
fi
done < .env

# Optionally, you can also clear specific ports mentioned in .env.example
while IFS='=' read -r key value; do
# Check if the line is a valid environment variable
if [[ "$key" == PORT* || "$key" == *_PORT ]]; then
echo "Found port variable: $key=$value"
# Check if the value is a numeric port
if is_numeric_port "$value"; then
clear_port "$value"
else
echo "Skipping non-numeric port value: $key=$value"
fi
fi
done < .env.example
63 changes: 63 additions & 0 deletions .bin/bkup/start_gunicorn copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# Navigate to the root of the project
cd "$(dirname "$0")"/..

# Print all environment variables
echo "Environment variables:"
printenv

# Ensure all required packages are installed
echo "Installing missing dependencies..."
pip install -r ./requirements.txt &> ./.tmp/install_output.log
npm install &> ./.tmp/npm_install_output.log

# Start the Node.js server in the background and store its PID
echo "Starting Node.js server..."
npx tsc -w &> ./.tmp/node_output.log &
node app/static/templates/server/server.js
NODE_JS_PID=$!

# Wait for 2 seconds to ensure the Node.js server has started
sleep 2

# Check if the Node.js process is running
if ps -p $NODE_JS_PID > /dev/null; then
echo "Node.js server PID: $NODE_JS_PID"
else
echo "Failed to start Node.js server."
cat ./.tmp/node_output.log # Print the log file contents in case of failure
exit 1
fi

# Tail the Node.js output for real-time logs (optional, but useful)
echo "Node.js server is running. Checking logs..."
tail -f ./.tmp/node_output.log &

# Activate your virtual environment (if not already activated)
source ./.venv/bin/activate

# Check if the virtual environment is correctly set up
echo "Checking virtual environment..."
python3 --version # Verify Python version
pip list | grep Flask # Verify Flask installation
npm --version # Verify Node.js installation
if [ $? -ne 0 ]; then
echo "Flask or Node.js are not installed. Please install dependencies using 'pip install -r requirements.txt' and 'npm install'"
deactivate
exit 1
fi

# Read port from environment variable, default to 8000 if not set
PORT=${FLASK_PORT:-4000}
echo "Starting Gunicorn server on port $PORT with gevent workers..."
nohup gunicorn --worker-class gevent --workers 3 --bind 0.0.0.0:$PORT 'app.run_app:app' > .tmp/gunicorn_output.log 2>&1 &

echo "Gunicorn server started on port $PORT."

# Deactivate the virtual environment
deactivate

# Tail the Gunicorn output for real-time logs (optional, but useful)
echo "Gunicorn server is running. Checking logs..."
tail -f ./.tmp/gunicorn_output.log &
53 changes: 53 additions & 0 deletions .bin/bkup/start_gunicorn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Navigate to the root of the project
cd "$(dirname "$0")"/..

# Ensure all required packages are installed
echo "Checking if required packages are installed..."

# Install dependencies
pip install -r ./requirements.txt &> /dev/null
if [ $? -ne 0 ]; then
echo "One or more dependencies are missing. Please install them using 'pip install -r requirements.txt'"
pip install --upgrade pip
pip install -r requirements.txt
exit 1
fi

# Check if the virtual environment is activated
if [ ! -d ".venv" ]; then
echo "Virtual environment not found. Creating it using 'python3 -m venv .venv'..."
python3 -m venv .venv
fi

echo "Activating virtual environment..."
source ./.venv/bin/activate &> /dev/null
if [ $? -ne 0 ]; then
echo "Failed to activate virtual environment. Please ensure it is correctly set up."
exit 1
fi

# Check if gunicorn is installed
pip show gunicorn &> /dev/null
if [ $? -ne 0 ]; then
echo "gunicorn is not installed. Installing it..."
pip install gunicorn
fi

# Read port from environment variable, default to 8000 if not set
PORT=${FLASK_PORT:-8000}
echo "Starting Gunicorn server on port $PORT with gevent workers..."
nohup gunicorn --worker-class gevent --workers 3 --bind 0.0.0.0:$PORT 'app.run_app:app' > .tmp/gunicorn_output.log 2>&1 &

echo "Gunicorn server started on port $PORT."

# Deactivate the virtual environment
deactivate

# --worker-class gevent: This tells Gunicorn to use the gevent worker class,
# which is more suitable for high-concurrency applications and
# can handle many requests using fewer resources.

# --workers 3: Specifies the number of worker processes. You can adjust this based on your server's CPU cores
# and available memory.
91 changes: 91 additions & 0 deletions .bin/bkup/start_services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash


# Activate your virtual environment (if not already activated)
source ./.venv/bin/activate

# Check if the virtual environment is correctly set up
echo "Checking virtual environment..."
python3 --version # Verify Python version
pip list | grep Flask # Verify Flask installation
npm --version # Verify Node.js installation
if [ $? -ne 0 ]; then
echo "Flask or Node.js are not installed. Please install dependencies using 'pip install -r requirements.txt' and 'npm install'"
# stop the node server
deactivate
exit 1
fi

# Ensure all required packages are installed
echo "Installing missing dependencies..."
pip install -r ./requirements.txt &> ./.tmp/install_output.log

# Start the Node.js server
echo "Starting Node.js server..."
npm cache clean --force &> ./.tmp/node_output.log &
npm install &> ./.tmp/node_output.log &
node ./app/index.js &> ./.tmp/node_output.log &
npm run watch-css &> ./.tmp/node_output.log &
NODE_JS_PID=$!


# Set the FLASK_APP environment variable to point to your app.py file and specify the port
export FLASK_APP=./app/run_app.py
export FLASK_RUN_PORT=${FLASK_RUN_PORT} # Specify the desired port here

# Start the Flask application in the background and store its PID
echo "Starting Flask server on port $FLASK_RUN_PORT..."
flask run &> ./.tmp/flask_output.log &
FLASK_PID=$!

# Wait for 2 seconds to ensure the Flask server has started
sleep 2

# Check if the Flask process is running
if ps -p $FLASK_PID > /dev/null; then
echo "Flask server PID: $FLASK_PID"
else
echo "Failed to start Flask server."
cat ./.tmp/flask_output.log # Print the log file contents in case of failure
deactivate
exit 1
fi

# Tail the Flask output for real-time logs (optional, but useful)
echo "Flask server is running. Checking logs..."
tail -f ./.tmp/flask_output.log &

# Run any additional Python scripts (e.g., Voice_v2.py) and capture their output
echo "Running additional services..."
python3.11 ./app/run_app.py &> ./.tmp/voice_output.log &

# Optionally, wait for a few more seconds before exiting
sleep 5

# Kill the Flask process if it's still running after `Voice_v2.py` finishes
if [ -n "$FLASK_PID" ]; then
echo "Waiting for Flask server to finish..."
sleep 10 # Give some time for cleanup
kill $FLASK_PID || true # Kill the process, ignore errors if it's already gone
echo "Killed Flask server with PID: $FLASK_PID"
fi

# Check if the Node.js server is running
if [ -n "$NODE_JS_PID" ]; then
if ps -p $NODE_JS_PID > /dev/null; then
echo "Node.js server PID: $NODE_JS_PID"
else
echo "Failed to start Node.js server."
cat ./.tmp/node_output.log # Print the log file contents in case of failure
fi
else
echo "$NODE_JS_PID is not set. Node.js server was not started or PID capture failed."
fi

# Wait for a few more seconds before exiting
# sleep 100

echo "All services started successfully."

# Deactivate the virtual environment and exit
deactivate
Loading