Skip to content

Commit 309d47d

Browse files
authored
Merge pull request #89 from ByteInternet/tdgroot-patch-1
2 parents a64185a + abc1b7c commit 309d47d

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

docs/hypernode-platform/tools/installation-and-configuration-of-pm2.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
myst:
33
html_meta:
4-
description: PM2 is a porcess manager which keeps your application running as
5-
a deamon. In this article we’ll cover the installation and configuration process
4+
description: PM2 is a process manager which keeps your application running as
5+
a daemon. In this article we’ll cover the installation and configuration process
66
of PM2.
77
title: How to install and configure PM2 on Hypernode?
88
redirect_from:
@@ -21,25 +21,25 @@ We will run PM2 in combination with a program called supervisord to make sure th
2121

2222
PM2 can be installed in various ways. In this article we'll install the process manager globally for the app user. We'll also create an alias for PM2, so that the program will not spawn the PM2 daemon on the fly. We don't want that to happen, because we want PM2 to run in the foreground so that it can be managed by supervisord.
2323

24-
```
25-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Set NPM prefix to ~/.npm
26-
app@abbt5w-tdgroot-magweb-cmbl:~$ npm config set prefix ~/.npm
27-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Install PM2 in NPM prefix
28-
app@abbt5w-tdgroot-magweb-cmbl:~$ npm install --quiet -g pm2
24+
```console
25+
app@abbt5w-example-magweb-cmbl:~$ # Set NPM prefix to ~/.npm
26+
app@abbt5w-example-magweb-cmbl:~$ npm config set prefix ~/.npm
27+
app@abbt5w-example-magweb-cmbl:~$ # Install PM2 in NPM prefix
28+
app@abbt5w-example-magweb-cmbl:~$ npm install --quiet -g pm2
2929
/data/web/.npm/bin/pm2-dev -> /data/web/.npm/lib/node_modules/pm2/bin/pm2-dev
3030
/data/web/.npm/bin/pm2 -> /data/web/.npm/lib/node_modules/pm2/bin/pm2
3131
/data/web/.npm/bin/pm2-docker -> /data/web/.npm/lib/node_modules/pm2/bin/pm2-docker
3232
/data/web/.npm/bin/pm2-runtime -> /data/web/.npm/lib/node_modules/pm2/bin/pm2-runtime
3333
+ pm2@5.1.2
3434
added 181 packages from 200 contributors in 7.411s
35-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Add user NPM prefix bin directory to PATH
36-
app@abbt5w-tdgroot-magweb-cmbl:~$ echo 'export PATH="$PATH:$HOME/.npm/bin"' >> ~/.bashrc
37-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Create pm2 alias to skip creation of PM2 daemon on the fly
38-
app@abbt5w-tdgroot-magweb-cmbl:~$ echo 'alias pm2="pm2 --no-daemon"' >> ~/.bashrc
39-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Reload bash config
40-
app@abbt5w-tdgroot-magweb-cmbl:~$ source ~/.bashrc
41-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Check if pm2 program can be found
42-
app@abbt5w-tdgroot-magweb-cmbl:~$ which pm2
35+
app@abbt5w-example-magweb-cmbl:~$ # Add user NPM prefix bin directory to PATH
36+
app@abbt5w-example-magweb-cmbl:~$ echo 'export PATH="$PATH:$HOME/.npm/bin"' >> ~/.bashrc
37+
app@abbt5w-example-magweb-cmbl:~$ # Create pm2 alias to skip creation of PM2 daemon on the fly
38+
app@abbt5w-example-magweb-cmbl:~$ echo 'alias pm2="pm2 --no-daemon"' >> ~/.bashrc
39+
app@abbt5w-example-magweb-cmbl:~$ # Reload bash config
40+
app@abbt5w-example-magweb-cmbl:~$ source ~/.bashrc
41+
app@abbt5w-example-magweb-cmbl:~$ # Check if pm2 program can be found
42+
app@abbt5w-example-magweb-cmbl:~$ which pm2
4343
/data/web/.npm/bin/pm2
4444
```
4545

@@ -51,7 +51,7 @@ To make use of supervisord, we first have to make sure it is enabled and running
5151

5252
For this article we'll use a simple web server application written in Python. Feel free to use your own application!
5353

54-
```
54+
```python
5555
#!/usr/bin/env python3
5656

5757
from http.server import BaseHTTPRequestHandler, HTTPServer
@@ -87,7 +87,7 @@ The application only handles `GET` requests and responds with the text "Hello, V
8787

8888
Now that we have PM2 installed, supervisor available and an application to run, we can combine all the things together. Create a file at /data/web/supervisor/my_application.conf with the following contents.
8989

90-
```
90+
```ini
9191
[program:pm2_my_application]
9292
command=/data/web/.npm/bin/pm2 --no-daemon --interpreter=python3 start /data/web/my_application/main.py
9393
autostart=true
@@ -101,27 +101,27 @@ For more information about options and configuration of PM2 and supervisor, plea
101101

102102
Now we're almost done, we only need to execute a few commands to load the supervisord configuration and start the PM2 process manager.
103103

104-
```
105-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Make sure no pm2 background daemon is running
106-
app@abbt5w-tdgroot-magweb-cmbl:~$ pm2 kill
104+
```console
105+
app@abbt5w-example-magweb-cmbl:~$ # Make sure no pm2 background daemon is running
106+
app@abbt5w-example-magweb-cmbl:~$ pm2 kill
107107
pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)
108108
2022-02-04T11:58:30: PM2 log: Launching in no daemon mode
109109
2022-02-04T11:58:30: PM2 error: [PM2][WARN] No process found
110110
2022-02-04T11:58:30: PM2 log: [PM2] [v] All Applications Stopped
111111
2022-02-04T11:58:30: PM2 log: PM2 successfully stopped
112112
2022-02-04T11:58:30: PM2 log: [PM2] [v] PM2 Daemon Stopped
113-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Reload supervisor config files
114-
app@abbt5w-tdgroot-magweb-cmbl:~$ supervisorctl reread
113+
app@abbt5w-example-magweb-cmbl:~$ # Reload supervisor config files
114+
app@abbt5w-example-magweb-cmbl:~$ supervisorctl reread
115115
pm2_my_application: available
116-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Check which processes are available
117-
app@abbt5w-tdgroot-magweb-cmbl:~$ supervisorctl avail
116+
app@abbt5w-example-magweb-cmbl:~$ # Check which processes are available
117+
app@abbt5w-example-magweb-cmbl:~$ supervisorctl avail
118118
pm2_my_application avail auto 999:999
119-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Add our process to be managed by supervisor
120-
app@abbt5w-tdgroot-magweb-cmbl:~$ supervisorctl add pm2_my_application
119+
app@abbt5w-example-magweb-cmbl:~$ # Add our process to be managed by supervisor
120+
app@abbt5w-example-magweb-cmbl:~$ supervisorctl add pm2_my_application
121121
pm2_my_application: added process group
122-
app@abbt5w-tdgroot-magweb-cmbl:~$ # Check status of running processes
123-
app@abbt5w-tdgroot-magweb-cmbl:~$ supervisorctl status
122+
app@abbt5w-example-magweb-cmbl:~$ # Check status of running processes
123+
app@abbt5w-example-magweb-cmbl:~$ supervisorctl status
124124
pm2_my_application RUNNING pid 25139, uptime 0:00:04
125-
app@abbt5w-tdgroot-magweb-cmbl:~$ curl http://localhost:8000/
125+
app@abbt5w-example-magweb-cmbl:~$ curl http://localhost:8000/
126126
Hello, Visitor!
127127
```

0 commit comments

Comments
 (0)