Skip to content

Instantly share code, notes, and snippets.

@shikhir-arora
Last active November 18, 2017 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shikhir-arora/b1ec4820e3299c255e4f97dcfdf99d87 to your computer and use it in GitHub Desktop.
Save shikhir-arora/b1ec4820e3299c255e4f97dcfdf99d87 to your computer and use it in GitHub Desktop.
pm2 setup for Linux - Nadeko Install

Create a new Session - pm2:

  • tmux works well for most enviornments, however, we can use pm2 which allows us to have more control and also more automation.

  • pm2 requires NodeJS/npm. If you don't have these already, you can get them the following ways:

Ubuntu/Debian systems can use curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs to install NodeJS.

CentOS and RHEL users can use curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - and then run yum -y install nodejs as root.

This will install the latest version of NodeJS and npm. There is a good chance you have them already, however.

  • After this, we can install pm2 simply: npm install pm2 -g

  • We now want to start Nadeko. This part requires you to make the decision whether you want the auto-update on restart or the start normally without updating - also, if you want the .die command (auto-restart) without updates.

  • You should have these files already, but if not, depending on which option you choose you'll need to use a different script. For the auto-restart without updating option, you can wget https://raw.githubusercontent.com/Kwoth/NadekoBot-BashScript/1.9/NadekoARN.sh if you don't have it already. For the auto-restart and update option, you can wget https://raw.githubusercontent.com/Kwoth/NadekoBot-BashScript/1.9/NadekoARU_Latest.sh - and for the normal start without auto-restart on .die, you can wget https://raw.githubusercontent.com/Kwoth/NadekoBot-BashScript/1.9/nadeko_run.sh

  • Now, simply type the following command pm2 start [your chosen startup script.sh] --interpreter bash --name "Nadeko"

For example, if we want the auto-restart without updating option, we type pm2 start NadekoARN.sh --interpreter bash --name "Nadeko"

  • This will now start Nadeko as a pm2 process, and automatically manage restarts as well.

  • For the last step to take full advantage of pm2, we can run pm2 startup - on most Linux systems this is systemd, so pm2 startup systemd followed by pm2 save will now save your pm2 processes and even if your server/VPS goes down and has to reboot, pm2 will automatically boot up and start Nadeko.

  • The other benefits are easy stopping of the bot: simply type pm2 status and find the "process ID" or name of the bot, in this case Nadeko, and one can do pm2 stop [process ID or name] and pm2 start [process ID or name] -- this is great for easy updating.

  • We can also get logs anytime: pm2 logs [process ID or name] will give a short log, but you can do something like pm2 logs [process ID or name] --lines 1000 to get a large output of the log. This is very helpful.

  • This gives us a lot of control, and pm2 comes in handy for many other things! Although a bit more work to setup initially, it's worth the benefit in the long-run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment