52 lines
1.1 KiB
Bash
Executable File
52 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Default port
|
|
PORT=9999
|
|
|
|
# Parse command line arguments
|
|
FORCE=false
|
|
while getopts "f" opt; do
|
|
case $opt in
|
|
f)
|
|
FORCE=true
|
|
;;
|
|
\?)
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Function to check if port is in use
|
|
is_port_in_use() {
|
|
lsof -i :$1 &>/dev/null
|
|
return $?
|
|
}
|
|
|
|
# Function to kill process on port
|
|
kill_process_on_port() {
|
|
echo "Killing process on port $1..."
|
|
lsof -ti :$1 | xargs kill -9 2>/dev/null
|
|
}
|
|
|
|
# Kill any processes using ports in the 99xx range if force flag is set
|
|
if [ "$FORCE" = true ]; then
|
|
echo "Force flag set. Killing any processes on port $PORT..."
|
|
kill_process_on_port $PORT
|
|
else
|
|
# Check if port is already in use
|
|
if is_port_in_use $PORT; then
|
|
echo "Port $PORT is already in use. Use -f flag to force kill and restart."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Change to the directory where the script is located
|
|
cd "$(dirname "$0")"
|
|
|
|
# Navigate to the Actix application directory
|
|
cd actix_mvc_app
|
|
|
|
# Run the application on the specified port
|
|
echo "Starting application on port $PORT..."
|
|
cargo run -- --port $PORT |