Make it easier to stop services
This commit is contained in:
parent
87c5dd40cb
commit
4cd3c77a3e
|
@ -31,18 +31,53 @@ fi
|
||||||
|
|
||||||
### START
|
### START
|
||||||
|
|
||||||
# DEVICE
|
start_device() {
|
||||||
|
echo "Starting device..."
|
||||||
if [[ "$DEVICE_START" == "True" ]]; then
|
|
||||||
python device.py &
|
python device.py &
|
||||||
fi
|
DEVICE_PID=$!
|
||||||
|
echo "Device started as process $DEVICE_PID"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to start server
|
||||||
|
start_server() {
|
||||||
|
echo "Starting server..."
|
||||||
|
python server.py &
|
||||||
|
SERVER_PID=$!
|
||||||
|
echo "Server started as process $SERVER_PID"
|
||||||
|
}
|
||||||
|
|
||||||
|
# DEVICE
|
||||||
|
|
||||||
# SERVER
|
# SERVER
|
||||||
|
|
||||||
if [[ "$SERVER_START" == "True" ]]; then
|
stop_processes() {
|
||||||
python server.py &
|
if [[ -n $DEVICE_PID ]]; then
|
||||||
|
echo "Stopping device..."
|
||||||
|
kill $DEVICE_PID
|
||||||
|
fi
|
||||||
|
if [[ -n $SERVER_PID ]]; then
|
||||||
|
echo "Stopping server..."
|
||||||
|
kill $SERVER_PID
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Trap SIGINT and SIGTERM to stop processes when the script is terminated
|
||||||
|
trap stop_processes SIGINT SIGTERM
|
||||||
|
|
||||||
|
# Start device if DEVICE_START is True
|
||||||
|
if [[ "$DEVICE_START" == "True" ]]; then
|
||||||
|
start_device
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Start server if SERVER_START is True
|
||||||
|
if [[ "$SERVER_START" == "True" ]]; then
|
||||||
|
start_server
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Wait for device and server processes to exit
|
||||||
|
wait $DEVICE_PID
|
||||||
|
wait $SERVER_PID
|
||||||
|
|
||||||
# TTS, STT
|
# TTS, STT
|
||||||
|
|
||||||
# (todo)
|
# (todo)
|
||||||
|
|
Loading…
Reference in New Issue