# ____ __ __ ____
# | _ \| \/ |___ \
# | |_) | |\/| | __) |
# | __/| | | |/ __/
# |_| |_| |_|_____|
#
I have been a fan of pm2 for sometime, and frankly don’t know why everyone else isn’t absolutely crazy about using it. It practically needs zero configuration, installs in seconds, and is ready to run whatever the hell you want with a simple command.
Just for reference, the official website is pm2.keymetrics.io It is nice, you should visit it.
To install pm2, you need to have already installed nodejs and npm on your system, afterwards simply execute sudo
npm install -g pm2
, and you are ready to rock with the best of them.
To start whatever the hell you want as a service you only need to: pm2 start whatever-the-hell
To start a service that requires a flag, or a service that has mandatory options. Encase the command and options in double quotations. Like so:
pm2 start "whatever-the-hell --option arg1 --option arg2" --name whatever-the-hell -- other args for command
Doing so prevents word splitting and contains the service command with options together for pm2 to run as a whole
command. Notice the additional flag outside the double quotes, it is directed at pm2, and not the command
pm2 is running. Using --name
gives your service a clean service name, where normally the flag would include
the flags used as well.
To configure bash completeion: pm2 completion >> ~/.bashrc
Only slightly more involved than the above.
pm2 startup
sudo env PATH=$PATH:/home/user/.nvm/versions/node/v16.4.0/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u user --hp /home/user
sudo systemctl start pm2
pm2 start whatever-the-hell
pm2 save
If you need to, or desire to, remove it at a later point in time. Just run pm2 unstartup
.
monit | Spawns a monitoring dashboard in the terminal |
list/status | Lists services being managed |
ping | Checks to see if service is running |
--name |
Ascribe a name to the command. |
--log $LOG_FILE |
Log output to file. |
-- |
Pass extra arguments to the script (?) |
--time |
Add time to log file. |
--watch |
Restart when files change |
--restart-delay |
Delay between auto restart |
--no-autorestart |
Do not restart |
--cron $cron_pattern |
Specify cron for forced restrart |