Skip to content

Instantly share code, notes, and snippets.

@fedecarg
Created July 9, 2018 14:23
Show Gist options
  • Select an option

  • Save fedecarg/fbb074789d99ba44bde7a5b0a442a5b3 to your computer and use it in GitHub Desktop.

Select an option

Save fedecarg/fbb074789d99ba44bde7a5b0a442a5b3 to your computer and use it in GitHub Desktop.
$ sudo npm install pm2 -g
/opt/bitnami/nodejs/bin/pm2 -> /opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2
/opt/bitnami/nodejs/bin/pm2-dev -> /opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2-dev
/opt/bitnami/nodejs/bin/pm2-runtime -> /opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2-runtime
/opt/bitnami/nodejs/bin/pm2-docker -> /opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2-docker
+ [email protected]
added 242 packages in 15.45s
bitnami@~/www/commerce-api$ pm2
-------------
__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
_\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
_\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
_\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
_\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
_\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
_\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
_\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
_\///______________\///______________\///__\///////////////__
Runtime Edition
PM2 is a Production Process Manager for Node.js applications
with a built-in Load Balancer.
$ pm2 -v
3.0.0
bitnami@~/www/commerce-api$ ll
total 72
drwxrwxr-x 9 bitnami bitnami 4096 Jul 9 11:06 .
drwxrwxr-x 3 bitnami bitnami 4096 Jul 9 10:46 ..
drwxrwxr-x 8 bitnami bitnami 4096 Jul 9 10:46 admin
drwxrwxr-x 3 bitnami bitnami 4096 Jul 9 12:08 api
drwxrwxr-x 5 bitnami bitnami 4096 Jul 9 10:46 config
-rw-rw-r-- 1 bitnami bitnami 249 Jul 9 10:46 .editorconfig
-rwxr-xr-x 1 bitnami bitnami 19 Jul 9 10:46 .eslintignore
-rwxr-xr-x 1 bitnami bitnami 563 Jul 9 10:46 .eslintrc
-rwxr-xr-x 1 bitnami bitnami 1150 Jul 9 10:46 favicon.ico
-rw-rw-r-- 1 bitnami bitnami 988 Jul 9 10:46 .gitignore
drwxrwxr-x 129 bitnami bitnami 4096 Jul 9 10:46 node_modules
-rw-rw-r-- 1 bitnami bitnami 1189 Jul 9 10:46 .npmignore
-rw-rw-r-- 1 bitnami bitnami 1081 Jul 9 10:46 package.json
drwxrwxr-x 8 bitnami bitnami 4096 Jul 9 10:46 plugins
drwxrwxr-x 3 bitnami bitnami 4096 Jul 9 10:46 public
-rw-rw-r-- 1 bitnami bitnami 53 Jul 9 10:46 README.md
-rwxr-xr-x 1 bitnami bitnami 315 Jul 9 10:46 server.js
bitnami@~/www/commerce-api$ pm2 start server.js
[PM2] Spawning PM2 daemon with pm2_home=/home/bitnami/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /home/bitnami/www/commerce-api/server.js in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬─────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼─────────┼──────────┤
│ server │ 0 │ fork │ 13976 │ online │ 0 │ 0s │ 0% │ 21.4 MB │ bitnami │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴─────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
bitnami@~/www/commerce-api$ pm2 startup ubuntu
[PM2] Init System found: systemd
-----------------------------------------------------------
PM2 detected systemd but you precised ubuntu
Please verify that your choice is indeed your init system
If you arent sure, just run : pm2 startup
-----------------------------------------------------------
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/opt/bitnami/nodejs/bin /opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2 startup ubuntu -u bitnami --hp /home/bitnami
bitnami@~/www/commerce-api$ sudo env PATH=$PATH:/opt/bitnami/nodejs/bin /opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2 startup ubuntu -u bitnami --hp /home/bitnami
[PM2] Init System found: systemd
-----------------------------------------------------------
PM2 detected systemd but you precised ubuntu
Please verify that your choice is indeed your init system
If you arent sure, just run : pm2 startup
-----------------------------------------------------------
Platform ubuntu
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target
[Service]
Type=forking
User=bitnami
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/opt/bitnami/nodejs/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/bitnami/.pm2
PIDFile=/home/bitnami/.pm2/pm2.pid
ExecStart=/opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/opt/bitnami/nodejs/lib/node_modules/pm2/bin/pm2 kill
[Install]
WantedBy=multi-user.target
Target path
/etc/systemd/system/pm2-bitnami.service
Command list
[ 'systemctl enable pm2-bitnami' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-bitnami.service
[PM2] Making script booting at startup...
[PM2] [-] Executing: systemctl enable pm2-bitnami...
Created symlink from /etc/systemd/system/multi-user.target.wants/pm2-bitnami.service to /etc/systemd/system/pm2-bitnami.service.
[PM2] [v] Command successfully executed.
+---------------------------------------+
[PM2] Freeze a process list on reboot via:
$ pm2 save
[PM2] Remove init script via:
$ pm2 unstartup ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment