8000 Auto-Restart start_sse_dev_server.sh on Server File Changes by dvlpjrs · Pull Request #135 · gumloop/guMCP · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Auto-Restart start_sse_dev_server.sh on Server File Changes #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions scripts/server_watcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import sys
import time
import subprocess
from pathlib import Path


def get_file_mtimes(directory, pattern="*.py"):
result = {}
for path in Path(directory).rglob(pattern):
if path.is_file():
result[str(path)] = path.stat().st_mtime
return result


def run_server():
cmd = [sys.executable, "src/servers/main.py"]
process = subprocess.Popen(cmd)
return process


def watch_files():
servers_dir = "src/servers"
print(f"Watching for changes in {servers_dir}/*.py")

mtimes = get_file_mtimes(servers_dir)
process = run_server()

try:
while True:
time.sleep(1)
new_mtimes = get_file_mtimes(servers_dir)

# Check for changed files
for file_path, mtime in new_mtimes.items():
if file_path not in mtimes or mtimes[file_path] != mtime:
print(f"\nChange detected in {file_path}, restarting server...")
process.terminate()
process.wait()
mtimes = new_mtimes
process = run_server()
break

# Check for new files
if set(new_mtimes.keys()) != set(mtimes.keys()):
print("\nNew or deleted files detected, restarting server...")
process.terminate()
process.wait()
mtimes = new_mtimes
process = run_server()

except KeyboardInterrupt:
print("\nShutting down server...")
process.terminate()
sys.exit(0)


if __name__ == "__main__":
watch_files()
22 changes: 13 additions & 9 deletions start_sse_dev_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ fi
export GUMCP_HOST=${GUMCP_HOST:-"0.0.0.0"}
export GUMCP_PORT=${GUMCP_PORT:-"8000"}

# Kill any process running on the specified port
echo "Checking for processes running on port $GUMCP_PORT..."
if lsof -i :$GUMCP_PORT > /dev/null; then
echo "Killing process running on port $GUMCP_PORT"
lsof -ti :$GUMCP_PORT | xargs kill -9
sleep 1
fi
# Function to kill server process
kill_server() {
echo "Checking for processes running on port $GUMCP_PORT..."
if lsof -i :$GUMCP_PORT > /dev/null; then
echo "Killing process running on port $GUMCP_PORT"
lsof -ti :$GUMCP_PORT | xargs kill -9
sleep 1
fi
}

echo "Starting guMCP development server on $GUMCP_HOST:$GUMCP_PORT"
# Kill any existing server process
kill_server

python src/servers/main.py
echo "Starting guMCP development server on $GUMCP_HOST:$GUMCP_PORT with hot reloading"
python scripts/server_watcher.py
0