Spaces:
Configuration error
Configuration error
Download kill-server.js from carefullycraftedtree/cc_site_maker: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/carefullycraftedtree/cc_site_maker/resolve/main/kill-server.js
- Command line
-
hf download hf://spaces/carefullycraftedtree/cc_site_maker/kill-server.js
-
curl -L -o kill-server.js https://huggingface.co/spaces/carefullycraftedtree/cc_site_maker/resolve/main/kill-server.js
1.61 kB
| // Script to kill any existing processes on port 7860 | |
| import { execSync } from 'child_process'; | |
| const PORT = 7860; | |
| try { | |
| console.log(`Checking for processes using port ${PORT}...`); | |
| // Different commands based on OS | |
| let command; | |
| if (process.platform === 'win32') { | |
| command = `netstat -ano | findstr :${PORT}`; | |
| } else { | |
| command = `lsof -i :${PORT} | grep LISTEN | awk '{print $2}'`; | |
| } | |
| const result = execSync(command, { encoding: 'utf8' }); | |
| if (result) { | |
| console.log(`Found processes using port ${PORT}. Attempting to kill...`); | |
| if (process.platform === 'win32') { | |
| // Extract PID from Windows netstat output | |
| const pidMatches = result.match(/\s+(\d+)$/m); | |
| if (pidMatches && pidMatches[1]) { | |
| const pid = pidMatches[1]; | |
| execSync(`taskkill /F /PID ${pid}`); | |
| console.log(`Killed process with PID ${pid}`); | |
| } | |
| } else { | |
| // On Unix systems, kill processes directly from lsof output | |
| const pids = result.trim().split('\n'); | |
| for (const pid of pids) { | |
| if (pid) { | |
| execSync(`kill -9 ${pid}`); | |
| console.log(`Killed process with PID ${pid}`); | |
| } | |
| } | |
| } | |
| console.log(`Port ${PORT} is now available`); | |
| } else { | |
| console.log(`No processes found using port ${PORT}`); | |
| } | |
| } catch (error) { | |
| // If no processes are found, lsof/netstat might return non-zero exit code | |
| if (error.status !== 0 && !error.stdout && !error.stderr) { | |
| console.log(`No processes found using port ${PORT}`); | |
| } else { | |
| console.error(`Error checking port ${PORT}:`, error.message); | |
| } | |
| } | |