How to use the restart function from pm2

Find comprehensive JavaScript pm2.restart code examples handpicked from public code repositorys.

92
93
94
95
96
97
98
99
100
101
.command('restart')
.description('Restart Raneto Service')
.action(() => {
  pm2.connect(() => {
    // (error, proc)
    pm2.restart('raneto', (error) => {
      if (error) {
        console.log(`Raneto could not be restarted: ${error.msg}`);
        process.exit(1);
      } else {
fork icon449
star icon0
watch icon0

146
147
148
149
150
151
152
153
154
155
console.info(m);
console.error(m);

// Process restart
return new Promise((resolve, reject) => {
    pm2.restart(this.pm_id, (err) => {
        if (err) {
            console.error(`Process ${this.name} - restart failed. ${err.message || err}`);
            reject(err);
            return;
fork icon8
star icon16
watch icon5

+ 29 other calls in file

801
802
803
804
805
806
807
808
809
810
await game.startinteraction.followUp({
  embeds: [embed],
  components: [],
});
//The bot is completely restarted via the pm2 api to reset all vars
pm2.restart("pokerbot", (err) => {
  if (err) throw err;

  console.log("Bot restarted successfully");
});
fork icon0
star icon1
watch icon0

21
22
23
24
25
26
27
28
29
30
setTimeout(() => {
  pm2.connect(() => {
    setInterval(function shouldRestart() {
      if (restart) {
        bot.send("Restarting due to hanged process");
        pm2.restart("index");
      } else {
        restart = true;
      }
    }, 60000);
fork icon1
star icon0
watch icon2

+ 116 other calls in file

3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
      bot.sendMessage(chatId, messages.messages.update_error);
    } else {
      console.log(stdout);
      child.exec("chmod 777 ./update.sh");
      bot.sendMessage(chatId, messages.messages.update_done);
      pm2.restart("./app.js");
    }
  }
);
break;
fork icon0
star icon1
watch icon1

+ 67 other calls in file

245
246
247
248
249
250
251
252
253
254
  }
}

//Função responsavel por reiniciar a instancia caso desconect
function onCrashBotMakeThat() {
  pm2.restart('sofie-hermes')
}

function writeReasonCrashJson(reason){
  let object_reason = {
fork icon0
star icon0
watch icon1

17
18
19
20
21
22
23
24
25
26
27
  });
};


const restartAsync = (process) => {
  return new Promise((resolve, reject) => {
    pm2.restart(process, (err, proc) => {
      if (err) reject(err);
      resolve(proc);
    });
  });
fork icon0
star icon0
watch icon1