MD@Home - Use PM2 As Manager

Joined
Feb 19, 2019
Messages
13
Long story short, I have developed in NodeJS for a few years and love PM2 for managing applications. So I set out to get it to work with MD@H.

1) I recommend getting a VPS from sdbx.moe or kimsufi (if you can). Zero issues so far and previous cheap hosts never worked.
-- Once you have your server. I am already assuming you know how to use SSH (mRemoteNG, Termius or Putty),

2) Make sure everything is up to date
Code:
sudo apt update; sudo apt update -y; sudo apt dist-upgrade -y

3) Install dependencies
Code:
sudo apt install -y build-essential git curl default-jre

4) Install node
Code:
sudo curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh; sudo bash nodesource_setup.sh; sudo apt install nodejs -y

5) Install PM2 and Logrotate
Code:
npm i -g pm2; pm2 install pm2-logrotate

6) Configure logrotate
Code:
pm2 set pm2-logrotate:max_size 100M
pm2 set pm2-logrotate:compress true
pm2 set pm2-logrotate:rotateInterval '* */1 * * *'
pm2 set pm2-logrotate:retain 10
max_size - Change this to whatever you want. M = Megabytes, G = Gigabytes, etc
compress - Highly recommend having it on. Otherwise change to false
roateInterval - Every hour but change to whatever. It uses cron format
retain - Change to what you want. I personally keep 10.

7) Make a directory where you want to keep MD@H and download.
Code:
mkdir -p ~/manga/{log,logs}; cd ~/manga
curl https://gitlab.com/mangadex-pub/mangadex_at_home/-/jobs/681534385/artifacts/raw/mangadex_at_home-1.2.1-all.jar -o mangadex_at_home-1.2.1-all.jar
OR
curl https://mangadex.org/dl/mangadex_at_home-1.1.5-all.jar -o mangadex_at_home-1.1.5-all.jar
curl https://mangadex.org/dl/settings.json -o settings.json

8) Change settings in settings.json to what you want.
9) Setting up PM2 process.json
Here is a sample - LINK

Example
Code:
{
    "apps": [{
            "name": "Client 1337",
            "cwd": "/home/ubuntu/manga/",
            "args": [
                "-Dfile-level=trace -Dstdout-level=info -Duser.dir=/home/ubuntu/manga",
                "-jar",
                "/home/ubuntu/manga/mangadex_at_home-1.2.1-all.jar",
                "--settings=/home/ubuntu/manga/settings.json"
            ],
            "script": "/usr/bin/java",
            "node_args": [],
            "log_date_format": "YYYY-MM-DD HH:mm Z",
            "exec_interpreter": "none",
            "exec_mode": "fork",
            "error_file": "/home/ubuntu/manga/logs/client_1337_error.log",
            "out_file": "/home/ubuntu/manga/logs/client_1337_out.log",
            "merge_logs": true,
            "instances" : 1,
            "watch": false
        }
    ]
}

10) Hopefully nothing blows up
Code:
cd ~/manga; pm2 start process.json

And if it works
Code:
┌─────┬──────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name             │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 2   │ Client 999       │ default     │ N/A     │ fork    │ 13550    │ 3h     │ 0    │ online    │ 0%       │ 338.8mb  │ root     │ disabled │
└─────┴──────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬───────────────────────────────────────┬────────────────────┬───────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module                                │ version            │ pid   │ status   │ ↺    │ cpu      │ mem      │ user     │
├────┼───────────────────────────────────────┼────────────────────┼───────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 0  │ pm2-logrotate                         │ 2.7.0              │ 12854 │ online   │ 4    │ 0%       │ 42.8mb   │ root     │
└────┴───────────────────────────────────────┴────────────────────┴───────┴──────────┴──────┴──────────┴──────────┴──────────┘

11) To see what its doing
Code:
#pm2 logs id
pm2 logs 2

12) To view/stop/start it
Code:
pm2 ls - Gets list
pm2 stop id - Replace ID with pm2 ID
pm2 start id - Replace ID with pm2 ID
 
Contributor
Joined
Dec 31, 2019
Messages
17,888
Seeing this posted in General instead of a more Technical subforum (Support/Bugs, I dunno?) feels wrong.

WTFamireading.jpg
 
carbotaniuman, Princeps Carbotia
Staff
Developer
Joined
Apr 14, 2020
Messages
40
Also, really nothing else fits (category wise). Do you mind contributing this to our wiki on GitLab?
 
Most powerful member of the GFG
Staff
Super Moderator
Joined
Feb 16, 2020
Messages
8,166
Don't mind me, i'm just here to ask @justforthelulz for the source, if he is so kind, of course.

Thanks, now i only have 29 tabs open, wait, the number increased?!
 

Users who are viewing this thread

Top