使用 pm2 编程重命名进程 api

rename process using pm2 programmatic api

我有一个电子应用程序,它使用 pm2 启动一些使用 pm2 的应用程序 module.Everything 是 fine.However 我正在尝试实现以下 feature:Renaming 您拥有的应用程序 started.I 知道使用 cli 我可以执行以下操作:

pm2 restart app --name"New name";

所以我找到了 pm2.restart 函数,它接受一个对象和一个回调作为 parameter.So 我试过这个:

var options = {app:"Blogsport App",name:"New name"};
var callback = function(err){
   if(err) {console.log('Failed')}
   else {console.log('App renamed')}
};

pm2.restart(options,callback);

这将始终记录 "App renamed"。但是如果我这样做 pm2 list 我发现该应用程序还没有 renamed.Is 我可以做任何事情来重命名应用程序而不删除它并且用不同的名字重新开始?

你可以试试这个:

pm2 restart id --name newName

例如:你的id是1,那么你可以输入:pm2 restart 1 --name development

你可以


pm2 delete id|name  
pm2 start app.js -n newname

pm2 restart id|name -n newname
pm2 ls

查看您的应用程序 ID

那么你有两个选择 删除并重新开始

pm2 delete <id> 
pm2 start index.js --name newname

或者重新启动以保持相同的 ID

pm2 restart <id> --name newname