添加 kit 子目录

This commit is contained in:
Cheney
2024-03-07 15:50:13 +08:00
parent e0c2ab8c1e
commit 5fd50792a0
24 changed files with 3143 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
function getModuleInfo(){
}
module.exports = { getModuleInfo }
+33
View File
@@ -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
}