75 lines
2.3 KiB
Bash
Executable File
75 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script to restart the robotwin_daemon.py process
|
|
# Requirements: Uses conda RoboTwin environment and checks for existing processes
|
|
|
|
# Get the project root directory (parent of daemon directory)
|
|
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
|
|
echo "Project root: $PROJECT_ROOT"
|
|
|
|
# Check if robotwin_daemon.py is already running
|
|
echo "Checking for existing robotwin_daemon.py processes..."
|
|
PIDS=$(ps aux | grep "[p]ython.*robotwin_daemon\.py" | awk '{print $2}')
|
|
|
|
if [ -n "$PIDS" ]; then
|
|
echo "Found robotwin_daemon.py process(es) with PID(s): $PIDS"
|
|
echo "Killing existing process(es)..."
|
|
|
|
# Loop through each PID and kill it
|
|
for PID in $PIDS; do
|
|
echo "Killing process with PID: $PID"
|
|
kill $PID
|
|
sleep 1
|
|
|
|
# Check if process was killed successfully
|
|
if ps -p $PID > /dev/null; then
|
|
echo "Process $PID did not terminate gracefully, using kill -9..."
|
|
kill -9 $PID
|
|
sleep 1
|
|
|
|
# Final check
|
|
if ps -p $PID > /dev/null; then
|
|
echo "Warning: Failed to kill process $PID"
|
|
else
|
|
echo "Process $PID terminated."
|
|
fi
|
|
else
|
|
echo "Process $PID terminated."
|
|
fi
|
|
done
|
|
else
|
|
echo "No existing robotwin_daemon.py process found."
|
|
fi
|
|
|
|
# Remove any existing socket file
|
|
SOCKET_PATH="/tmp/robotwin.sock"
|
|
if [ -S "$SOCKET_PATH" ]; then
|
|
echo "Removing existing socket file: $SOCKET_PATH"
|
|
rm "$SOCKET_PATH"
|
|
fi
|
|
|
|
# Activate conda environment and start the daemon
|
|
echo "Starting robotwin_daemon.py with conda RoboTwin environment..."
|
|
|
|
# Get conda base path
|
|
CONDA_BASE=$(conda info --base)
|
|
|
|
# Start the daemon in the background using conda run to ensure it runs in the RoboTwin environment
|
|
cd "$PROJECT_ROOT/daemon"
|
|
"$CONDA_BASE/bin/conda" run -n RoboTwin python robotwin_daemon.py > "$PROJECT_ROOT/daemon/daemon.log" 2>&1 &
|
|
|
|
# Get the PID of the new process
|
|
NEW_PID=$!
|
|
echo "Started robotwin_daemon.py with PID: $NEW_PID"
|
|
|
|
# Wait a moment and check if the process is running
|
|
sleep 2
|
|
if ps -p $NEW_PID > /dev/null; then
|
|
echo "Daemon started successfully."
|
|
else
|
|
echo "Failed to start daemon. Check daemon.log for details."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Restart completed successfully."
|