- Add ecosystem.config.js with auto-restart settings - Add PM2 management scripts to package.json - Create PM2.md documentation - Update .gitignore to exclude logs - Create logs directory for PM2 output Scripts available: - npm run pm2:start - Start with PM2 - npm run pm2:stop - Stop process - npm run pm2:restart - Restart process - npm run pm2:logs - View logs - npm run pm2:status - Check status - npm run pm2:monit - Real-time monitoring
99 lines
1.6 KiB
Markdown
99 lines
1.6 KiB
Markdown
# PM2 Process Manager - LPD Gerana Webcam
|
|
|
|
## Quick Start
|
|
|
|
### Start aplikasi dengan PM2
|
|
```bash
|
|
npm run pm2:start
|
|
```
|
|
|
|
### Stop aplikasi
|
|
```bash
|
|
npm run pm2:stop
|
|
```
|
|
|
|
### Restart aplikasi
|
|
```bash
|
|
npm run pm2:restart
|
|
```
|
|
|
|
### Lihat logs
|
|
```bash
|
|
npm run pm2:logs
|
|
```
|
|
|
|
### Lihat status
|
|
```bash
|
|
npm run pm2:status
|
|
```
|
|
|
|
### Monitor real-time
|
|
```bash
|
|
npm run pm2:monit
|
|
```
|
|
|
|
### Hapus dari PM2
|
|
```bash
|
|
npm run pm2:delete
|
|
```
|
|
|
|
## Auto Start saat Server Boot
|
|
|
|
### Setup PM2 startup (jalankan sekali)
|
|
```bash
|
|
# Generate startup script
|
|
npx pm2 startup
|
|
|
|
# Salin dan jalankan command yang muncul (biasanya dengan sudo)
|
|
# Contoh: sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u wartana --hp /home/wartana
|
|
|
|
# Start aplikasi
|
|
npm run pm2:start
|
|
|
|
# Save PM2 process list untuk auto-start
|
|
npx pm2 save
|
|
```
|
|
|
|
### Disable auto-start
|
|
```bash
|
|
npx pm2 unstartup
|
|
```
|
|
|
|
## Fitur PM2
|
|
|
|
- ✅ **Auto Restart**: Aplikasi otomatis restart jika crash
|
|
- ✅ **Logs Management**: Log tersimpan di folder `logs/`
|
|
- ✅ **Memory Management**: Auto restart jika memory > 500MB
|
|
- ✅ **Monitoring**: Real-time monitoring dengan `npm run pm2:monit`
|
|
- ✅ **Status Tracking**: Cek uptime dan status aplikasi
|
|
- ✅ **Startup Script**: Auto start saat server boot
|
|
|
|
## Log Files
|
|
|
|
- **Error Log**: `logs/pm2-error.log`
|
|
- **Output Log**: `logs/pm2-out.log`
|
|
|
|
## Tips
|
|
|
|
1. **Update aplikasi tanpa downtime**:
|
|
```bash
|
|
git pull
|
|
npm install
|
|
npm run pm2:restart
|
|
```
|
|
|
|
2. **Lihat logs 100 baris terakhir**:
|
|
```bash
|
|
npx pm2 logs lpd-gerana-webcam --lines 100
|
|
```
|
|
|
|
3. **Flush logs**:
|
|
```bash
|
|
npx pm2 flush
|
|
```
|
|
|
|
4. **Cek resource usage**:
|
|
```bash
|
|
npx pm2 monit
|
|
```
|