MCPcopy
hub / github.com/Unitech/pm2 / exec

Function exec

lib/ProcessContainerBun.js:107–355  ·  view source on GitHub ↗

* Description * @method exec * @param {} script * @param {} stds * @return

(script, stds)

Source from the content-addressed store, hash-verified

105 * @return
106 */
107function exec(script, stds) {
108 process.on('message', function (msg) {
109 if (msg.type === 'log:reload') {
110 for (var k in stds){
111 if (typeof stds[k] == 'object' && !isNaN(stds[k].fd)){
112 if (stds[k].destroy) stds[k].destroy();
113 else if (stds[k].end) stds[k].end();
114 else if (stds[k].close) stds[k].close();
115 stds[k] = stds[k]._file;
116 }
117 }
118 Utility.startLogging(stds, function (err) {
119 if (err)
120 return console.error('Failed to reload logs:', err.stack);
121 console.log('Reloading log...');
122 });
123 }
124 });
125
126 var dayjs = null;
127
128 if (pm2_env.log_date_format)
129 dayjs = require('dayjs');
130
131 Utility.startLogging(stds, function (err) {
132 if (err) {
133 process.send({
134 type : 'process:exception',
135 data : {
136 message: err.message,
137 syscall: 'ProcessContainer.startLogging'
138 }
139 });
140 throw err;
141 return;
142 }
143
144 ['warn', 'error'].forEach((method) => {
145 console[method] = (...args) => {
146 let log_data = null;
147
148 const msg = util.format(...args);
149
150 if (pm2_env.disable_logs === true) {
151 return false;
152 }
153
154 if (pm2_env.log_type && pm2_env.log_type === 'json') {
155 log_data = JSON.stringify({
156 message : msg,
157 timestamp : pm2_env.log_date_format && dayjs ?
158 dayjs().format(pm2_env.log_date_format) : new Date().toISOString(),
159 type : 'err',
160 process_id : pm2_env.pm_id,
161 app_name : pm2_env.name
162 }) + '\n';
163 }
164 else if (pm2_env.log_date_format && dayjs)

Callers 1

Calls 10

cbFunction · 0.85
toStringMethod · 0.80
chdirMethod · 0.80
onMethod · 0.65
destroyMethod · 0.65
endMethod · 0.65
closeMethod · 0.65
sendMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…