调接口
读json文件
修改json文件
nodemon或pm2监控到文件变化,自动重启
const restart = async (req, res) => {
//spawn.sync(`runChild6.bat`, [], { stdio: 'inherit' })\
const restartCountFilePath = './light/jenkins/restartCount.json'
const restartCountStr = fs.readFileSync(restartCountFilePath, 'utf-8')
let restartObj = eval('(' + restartCountStr + ')')
restartObj.restartCount = restartObj.restartCount + 1
res.send({
state: 1,
data: {
restartCountStr,
restartObj
},
message: '成功'
})
//修改json文件,会导致node服务自动重启
fs.writeFile(
restartCountFilePath,
JSON.stringify(restartObj, null, 2),
{ encoding: 'utf8' },
(err) => {}
)
}
./light/jenkins/restartCount.json:
{
"restartCount": 16
}