projeto-hit/TEST_SERVER1/test/api/helpers/findAndDeletePm2Process.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

const pm2 = require('pm2');
function findAndDeletePm2Process(pm2_process_name) {
pm2.connect(function (err) {
if (err) {
console.error(err);
// process.exit(2);
}
pm2.list(function (err, processes) {
if (err) {
console.error(err);
// process.exit(2);
}
const processToDelete = processes.find(process => process.name === pm2_process_name);
if (!processToDelete) {
console.error('Process not found');
// process.exit(2);
}
else {
pm2.delete(processToDelete.pm_id, function (err) {
if (err) {
console.error(err);
// process.exit(2);
}
else{
console.log(`Process deleted: ${pm2_process_name}`)
}
pm2.disconnect();
});
}
});
});
}
module.exports = findAndDeletePm2Process