-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·41 lines (33 loc) · 1.25 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·41 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Navigate to the project directory
cd "$(dirname "$0")"
# Ensure logs directory exists
mkdir -p logs
# Graceful shutdown function
cleanup() {
echo "Received stop signal, shutting down services..."
# Kill all background processes spawned by this script
# The 'jobs -p' command lists the PIDs of all background jobs.
kill $(jobs -p) 2>/dev/null
echo "All services stopped."
exit 0
}
# Trap TERM and INT signals to run the cleanup function.
# This ensures that when Docker stops the container, we can clean up.
trap cleanup SIGTERM SIGINT
# Activate virtual environment
# Note: In Docker, dependencies are usually pre-installed in the image,
# but this makes the script runnable outside of Docker too.
if [ -d "venv" ]; then
. venv/bin/activate
fi
# Start background services
echo "Starting listener service in the background..."
python3 run_listener.py &> logs/listener.log &
echo "Starting worker service in the background..."
python3 upload_worker.py &> logs/worker.log &
# Start the main Flask application in the FOREGROUND.
# This process will keep the container running.
# 'exec' replaces the shell process with the python process, which is a good practice.
echo "Starting Flask application in the foreground..."
exec python3 app.py