Sindbad~EG File Manager

Current Path : /home/beeson/ThreeBody/bin/
Upload File :
Current File : //home/beeson/ThreeBody/bin/restartEngine3.sh

#!/bin/sh

# Define Engine details
ENGINE_PORT=12350
ENGINE_BINARY="./ThreeBodyEngine"
LOG_FILE="engine3.log"

echo "Stopping any existing ThreeBodyEngine processes on port $ENGINE_PORT..."

# Find and kill processes using the port
PIDS=$(sockstat -4 -l | awk -v port=$ENGINE_PORT '$6 ~ port {print $3}')  # Correct field for FreeBSD
if [ -n "$PIDS" ]; then
    echo "Killing processes: $PIDS"
    sudo kill -9 $PIDS
    sleep 2  # Give time for processes to terminate
else
    echo "No running processes found on port $ENGINE_PORT."
fi

# Verify if process is truly stopped
if sockstat -4 -l | grep -q ":$ENGINE_PORT"; then
    echo "Error: Engine3 is still running. Try manually killing it."
    exit 1
fi

# Start the Engine in the background and log output
echo "Starting ThreeBodyEngine..."
nohup stdbuf -oL $ENGINE_BINARY 2>&1 | tee -a $LOG_FILE &
# Wait briefly to confirm it started
sleep 2
if sockstat -4 -l | grep -q ":$ENGINE_PORT"; then
    echo "ThreeBodyEngine started successfully!"
else
    echo "Failed to start ThreeBodyEngine. Check $LOG_FILE for details."
fi

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists