From 19605c228353d2971bd6fbb126a24b696f085851 Mon Sep 17 00:00:00 2001 From: Ryan Lelek Date: Tue, 11 Apr 2023 13:59:58 -0500 Subject: [PATCH] Fix: CLI Version with PM2/Commander (Unsupported) --- bin/raneto | 51 ++++++++++++++++++++++++++++++++++++++++----------- package.json | 5 +++-- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/bin/raneto b/bin/raneto index a3836a22..3152e875 100755 --- a/bin/raneto +++ b/bin/raneto @@ -1,5 +1,23 @@ #!/usr/bin/env node +// ################################ +// ########## DEPRECATED ########## +// ################################ +// PM2 is not officially recommended for +// production use by Raneto authors. +// Consider alternatives like systemd instead. +// This has been kept for the time being +// for those that use it and others that +// don't want to use systemd + +// ################### +// ##### WARNING ##### +// ################### +// This can only be used when installing development modules +// Additionally, the logs will only output the first process +// and not multiple process logs. This should be easy to fix +// by looping through the output but is not developed/tested + // Hide Keymetrics banner on first time PM2 is required // var consoleLog = console.log; // console.log = function () {}; @@ -9,6 +27,7 @@ var pm2 = require('pm2'); // Modules var path = require('path'); var program = require('commander'); +var Tail = require('tail').Tail; var pkg = require('../package.json'); process.chdir(path.normalize(path.join(__dirname, '..'))); @@ -22,12 +41,15 @@ program pm2.connect(() => { pm2.start( { - script: path.normalize( - path.join(__dirname, '..', 'example', 'server.js') - ), + script: path.normalize(path.join(__dirname, '..', 'server.js')), exec_mode: 'fork', instances: 1, name: 'raneto', + env: { + PORT: 3000, + NODE_ENV: 'development', + DEBUG: 'raneto*', + }, }, // (error, apps) (error) => { @@ -98,14 +120,21 @@ program console.log('Raneto not running'); process.exit(0); } else { - // var log = new Tail(list[0].pm2_env.pm_out_log_path, '\n', { interval : 500 }); - // var error_log = new Tail(list[0].pm2_env.pm_err_log_path, '\n', { interval : 500 }); - // log.on('line', function (data) { - // console.log(data); - // }); - // error_log.on('line', function (data) { - // console.log(data); - // }); + var log = new Tail(list[0].pm2_env.pm_out_log_path, '\n', { + interval: 500, + }); + var error_log = new Tail(list[0].pm2_env.pm_err_log_path, '\n', { + interval: 500, + }); + console.log('##### WARNING! THIS FEATURE IS UNTESTED #####'); + console.log('FILEOUT', list[0].pm2_env.pm_out_log_path); + console.log('FILEERR', list[0].pm2_env.pm_err_log_path); + log.on('line', function (data) { + console.log(data); + }); + error_log.on('line', function (data) { + console.log(data); + }); } }); }); diff --git a/package.json b/package.json index 0883f14a..54cd19aa 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "dependencies": { "@raneto/theme-default": "0.0.1", "body-parser": "1.20.2", - "commander": "9.5.0", + "commander": "10.0.0", "cookie-parser": "1.4.6", "debug": "4.3.4", "express": "4.18.2", @@ -89,6 +89,7 @@ "mocha": "10.2.0", "pm2": "5.3.0", "prettier": "2.8.7", - "supertest": "6.3.3" + "supertest": "6.3.3", + "tail": "2.2.6" } }