Restart Button Implementation
Overview
Added a red restart button to the ComfyUI topbar menu that allows users to restart the ComfyUI server.
Files Created/Modified
1. nodes/restart_api.py (NEW)
- Created a new API endpoint
/swissarmyknife/restart(POST) - Handles server restart by sending SIGTERM signal
- Gracefully shuts down and exits the process
2. __init__.py (MODIFIED)
- Imported and registered the restart API routes
- The restart endpoint is now available when ComfyUI starts
3. web/js/swiss-army-knife.js (MODIFIED)
- Added new extension
comfyui_swissarmyknife.restart_button - Defined restart command with ID
swissarmyknife.restart - Added command to topbar menu under "Swiss Army Knife" menu
- Injected CSS styles to make the button red
- Includes confirmation dialog before restarting
- Shows toast notifications for restart status
4. web/css/restart-button.css (NEW)
- Standalone CSS file for restart button styling (optional, styles are also injected via JS)
Features
Button Appearance
- Red background (#dc3545) with white text
- Bold font for prominence
- Hover effect - darker red (#c82333)
- Active effect - even darker red (#bd2130)
- 🔴 emoji prefix for visual indication
User Experience
- User clicks "Swiss Army Knife" → "🔴 Restart ComfyUI Server" in topbar
- Confirmation dialog appears
- If confirmed, sends POST request to
/swissarmyknife/restart - Shows "Server Restarting" toast notification
- Waits 2 seconds then reloads the page
- ComfyUI server restarts in background
Error Handling
- Shows error toast if restart fails
- Falls back to alert() if toast notifications unavailable
- Logs all events to browser console
Usage
After ComfyUI restarts with this extension:
- Look for "Swiss Army Knife" in the topbar menu
- Click to expand the menu
- Click "🔴 Restart ComfyUI Server"
- Confirm the restart
- Wait for server to restart and page to reload
Notes
- Restart works by sending SIGTERM to the server process
- Requires ComfyUI to be running under a process manager or restart script for automatic restart
- If running manually, the server will shut down and need manual restart
- The 2-second delay before page reload allows the server to begin shutdown