添加 kit 子目录
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
function getModuleInfo(){
|
||||
|
||||
}
|
||||
|
||||
module.exports = { getModuleInfo }
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
async function killport(port) {
|
||||
$logger.info(`kill process on port ${port}`);
|
||||
const util = require('util');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
|
||||
try {
|
||||
// 查 PID
|
||||
let { stdout : stdout1 } = exec(`lsof -t -sTCP:LISTEN -i:${port}`)
|
||||
let pid = stdout1.trim();
|
||||
$logger.debug(`绑定端口号 ${port} 的进程 PID=${pid}`)
|
||||
|
||||
// 查进程信息
|
||||
let { stdout : stdout2 } = exec(`ps -p ${pid} -o comm=`)
|
||||
let processName = stdout2.trim();
|
||||
$logger.info(`绑定端口号=${port}; 进程 PID=${pid}; 程序=${processName};`);
|
||||
|
||||
// Kill 进程
|
||||
exec(`kill -9 ${pid}`)
|
||||
|
||||
} catch (e) {
|
||||
if ( 1 === e.code ) {
|
||||
$logger.error("此端口未被使用,或清理进程失败。")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
killport
|
||||
}
|
||||
Reference in New Issue
Block a user