PM2 Manager
PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
The PM2 Manager in FlashPanel provides an intuitive interface to manage your Node.js applications through PM2, making it easy to start, stop, restart, and monitor your processes.
Key Features
- Process Management: Start, stop, restart, and delete Node.js applications
- Process Monitoring: View real-time status, CPU usage, and memory consumption
- Log Management: Access application logs for debugging and monitoring
- Easy Deployment: Start new Node.js applications with simple form inputs
- User Isolation: Run processes under specific system users for security
Prerequisites
Before using PM2 Manager, you need to:
- Install the PM2 application on your server
- Have Node.js installed on your server (PM2 will be installed automatically with Node.js)
Interface Overview
The PM2 Manager interface is organized around a main process list view with action buttons that open dialogs for specific operations:
- Process List: View and manage all running PM2 processes
- Add New Process: Start a new Node.js application with PM2 (opens in dialog)
- View Logs: View logs for your PM2 processes (opens in dialog)
1. Process List
This section displays all PM2 processes running on your server.
Process List Columns
The process list shows detailed information for each process:
- ID: The process ID (PID) assigned by the system
- Name: The name of the process (custom or auto-generated)
- Path: The path to the script file (hover to see command arguments)
- Status: Current status (online, stopped, errored)
- User: The system user under which the process is running
- CPU: Current CPU usage percentage
- Memory: Current memory consumption in MB
Process Actions
For each process, you can perform the following actions:
- Start: Start a stopped process
- Stop: Stop a running process
- Restart: Restart a process (useful for applying code changes)
- Delete: Remove a process from PM2 management
- View Log: View logs for a process (opens in dialog)
Refreshing Processes
Click the "Refresh" button at the top right to update the process list with the latest information from PM2.
2. Add New Process
This section allows you to start new Node.js applications using PM2 through a dialog interface.
Starting a Process
To start a new process:
- Click the "Add New" button at the top of the process list
- In the dialog that opens, select the Website Isolation Username - The system user under which the process should run (optional, defaults to root)
- Enter the Command - The command to start your Node.js application (e.g.,
app.js --name my-app
or/path/to/your/script.js --max-memory-restart 512M
) - Click the "Start" button
After starting a process, the dialog will close and the process list will automatically refresh to show your new process.
3. View Logs
This section allows you to view logs for your PM2 processes through a dialog interface, which is essential for debugging and monitoring.
Viewing Logs
To view logs for a process:
- In the process list, click the "View Log" button for the process you want to examine
- In the dialog that opens, you can adjust the Number of lines slider to select how many log lines you want to retrieve (100-1000)
- The logs will be displayed in a scrollable text area with syntax highlighting
- Click the "Refresh" button in the dialog to update the logs with the latest information
Best Practices
- Use Process Names: Always give your processes meaningful names to easily identify them
- Monitor Resource Usage: Keep an eye on CPU and memory usage to ensure optimal performance
- Check Logs Regularly: Regularly review logs to catch errors and performance issues early
- Use User Isolation: Run processes under dedicated system users for improved security
- Use Cluster Mode: For production applications, consider using PM2's cluster mode to take advantage of multiple CPU cores
Troubleshooting
Process Won't Start
- Check that the script path is correct and the file exists
- Verify that the Node.js application doesn't have syntax errors
- Check the logs for detailed error messages
- Ensure the selected user has proper permissions to access the script
High Resource Usage
- Review your application code for potential memory leaks
- Consider implementing proper error handling to prevent crashes
- Monitor logs for recurring errors that might cause resource spikes
Process Keeps Restarting
- Check the application logs for unhandled exceptions
- Ensure all required dependencies are installed
- Verify that the application is not encountering runtime errors
For more detailed information about PM2 features and configuration options, refer to the official PM2 documentation.