@ducci/jarvis 1.0.48 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/scripts/onboarding.js +38 -0
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import os from 'os';
|
|
6
|
+
import { spawnSync } from 'child_process';
|
|
6
7
|
import inquirer from 'inquirer';
|
|
7
8
|
import chalk from 'chalk';
|
|
8
9
|
|
|
@@ -420,6 +421,43 @@ async function run() {
|
|
|
420
421
|
}
|
|
421
422
|
}
|
|
422
423
|
|
|
424
|
+
// --- PM2 + LOG ROTATION STEP ---
|
|
425
|
+
const pm2Check = spawnSync('pm2', ['--version'], { stdio: 'pipe' });
|
|
426
|
+
if (pm2Check.status !== 0) {
|
|
427
|
+
console.log(chalk.blue('Installing pm2 globally...'));
|
|
428
|
+
spawnSync('npm', ['install', '-g', 'pm2'], { stdio: 'inherit' });
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const logrotateModuleDir = path.join(os.homedir(), '.pm2', 'modules', 'pm2-logrotate');
|
|
432
|
+
const logrotateInstalled = fs.existsSync(logrotateModuleDir);
|
|
433
|
+
|
|
434
|
+
if (logrotateInstalled) {
|
|
435
|
+
console.log(chalk.green('pm2-logrotate is already installed — server.log will be rotated automatically.'));
|
|
436
|
+
} else {
|
|
437
|
+
const { setupLogrotate } = await inquirer.prompt([
|
|
438
|
+
{
|
|
439
|
+
type: 'confirm',
|
|
440
|
+
name: 'setupLogrotate',
|
|
441
|
+
message: 'Install pm2-logrotate to prevent server.log from growing indefinitely?',
|
|
442
|
+
default: true,
|
|
443
|
+
}
|
|
444
|
+
]);
|
|
445
|
+
|
|
446
|
+
if (setupLogrotate) {
|
|
447
|
+
console.log(chalk.blue('Installing pm2-logrotate...'));
|
|
448
|
+
const install = spawnSync('pm2', ['install', 'pm2-logrotate'], { stdio: 'inherit' });
|
|
449
|
+
if (install.status !== 0) {
|
|
450
|
+
console.log(chalk.yellow('Installation failed — make sure pm2 is installed globally (`npm install -g pm2`) and try again.'));
|
|
451
|
+
} else {
|
|
452
|
+
spawnSync('pm2', ['set', 'pm2-logrotate:max_size', '10M'], { stdio: 'inherit' });
|
|
453
|
+
spawnSync('pm2', ['set', 'pm2-logrotate:retain', '5'], { stdio: 'inherit' });
|
|
454
|
+
spawnSync('pm2', ['set', 'pm2-logrotate:compress', 'true'], { stdio: 'inherit' });
|
|
455
|
+
spawnSync('pm2', ['set', 'pm2-logrotate:rotateInterval', '0 0 * * *'], { stdio: 'inherit' });
|
|
456
|
+
console.log(chalk.green('pm2-logrotate installed: 10 MB max, 5 rotated files kept, daily rotation.'));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
423
461
|
console.log(chalk.green.bold('\nSetup complete!'));
|
|
424
462
|
}
|
|
425
463
|
|