Here’s a guide to install pm2 and pm2-logrotate on Debian 12:

Step 1: Update the System

Make sure your system is up-to-date:

sudo apt update && sudo apt upgrade -y

Step 2: Install Node.js (if not already installed)

If Node.js and npm aren’t installed yet, install them. Use the NodeSource setup script to get the latest stable version.

Step 3: Install pm2

Install pm2 globally using npm:

sudo npm install -g pm2

Step 4: Set up pm2 to Start on Boot

To ensure pm2 restarts your applications after a reboot, use:

pm2 startup

The command will output another command specific to your system, so copy and run it as instructed.

Step 5: Install pm2-logrotate

Now, install the pm2-logrotate module:

pm2 install pm2-logrotate

This will set up log rotation for all pm2 applications by default. You can also configure pm2-logrotate with custom settings.

Step 6: Configure pm2-logrotate (Optional)

To adjust pm2-logrotate settings, use the following command:

pm2 set pm2-logrotate:max_size 10M  # Rotate when log reaches 10MB
pm2 set pm2-logrotate:retain 7      # Keep logs for 7 days
pm2 set pm2-logrotate:compress true # Compress logs after rotation
pm2 set pm2-logrotate:rotateInterval '0 0 * * *' # Rotate daily

Step 7: Verify Installation

Run the following command to verify pm2 and pm2-logrotate are active:

pm2 list
pm2 logrotate

Now, pm2 and pm2-logrotate should be successfully set up on your Debian 12 system.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.