java status

This commit is contained in:
gaoshuaixing
2023-08-01 18:57:48 +08:00
parent 14b3fccf5d
commit 06d513a3e9
3 changed files with 51 additions and 0 deletions

View File

@@ -45,7 +45,16 @@ class JavaServerAddon {
* @since 1.0.0
*/
async check () {
Log.info("进入-----检查服务是否启动------"+this.javaServer);
if(this.javaServer == undefined){
Log.info("[addon:javaServer:check] status-----------"+false);
return false;
}
const flag = await this.javaServer.isRun(Conf.getValue('addons.javaServer'));
Log.info("[addon:javaServer:check] status-----------"+flag);
return flag;
}
/**

View File

@@ -95,6 +95,32 @@ class JavaServer {
// todo linux
}
}
/**
* 服务是否运行中
*/
async isRun(cfg){
const jarName = cfg.name;
if (is.windows()) {
const resultList = ps.lookup({
command: "java",
where: 'caption="javaw.exe"',
arguments: jarName,
});
Log.info("[addon:javaServer] resultList:", resultList);
return resultList.length>0;
} else if (is.macOS()) {
const cmd = `ps -ef | grep java | grep ${jarName} | grep -v grep | awk '{print $2}' `;
Log.info("[addon:javaServer:isRun] cmdStr:", cmd);
const result = execSync(cmd);
Log.info('[addon:javaServer:isRun] result:', result.toString());
//不等于空说明正在运行
return result.toString()!==""
} else {
// todo linux
}
}
}
module.exports = JavaServer;