2022-01-07 13:06:22 -06:00
|
|
|
const https = require("https");
|
|
|
|
|
2021-07-08 05:14:57 -05:00
|
|
|
const { spawn, fork } = require('child_process');
|
|
|
|
if (process.argv.length < 5 || process.argv[2] == '--help') {
|
|
|
|
console.debug('bootstrap.js <ssl_true_or_false> <abs_top_builddir> <abs_srcdir>');
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
const ssl_flag = process.argv[2];
|
|
|
|
const top_builddir = process.argv[3];
|
|
|
|
const srcdir = process.argv[4];
|
2021-07-15 07:44:28 -05:00
|
|
|
const typing_speed = process.argv[5];
|
|
|
|
const single_view = process.argv[6];
|
|
|
|
const typing_duration = process.argv[7];
|
|
|
|
const inspect = process.argv[8];
|
2021-07-23 02:03:49 -05:00
|
|
|
const recordStats = process.argv[9];
|
2021-11-25 12:01:51 -06:00
|
|
|
|
|
|
|
// verbose console output
|
|
|
|
const debug = false;
|
|
|
|
|
2021-07-08 05:14:57 -05:00
|
|
|
/* dont use the default port (9980)*/
|
|
|
|
const port = '9999';
|
|
|
|
let args = [
|
|
|
|
`--o:sys_template_path=${top_builddir}/systemplate`,
|
|
|
|
'--o:security.capabilities=false',
|
|
|
|
`--o:child_root_path=${top_builddir}/jails`,
|
|
|
|
'--o:storage.filesystem[@allow]=true',
|
2022-01-07 13:06:22 -06:00
|
|
|
'--o:admin_console.username=admin',
|
|
|
|
'--o:admin_console.password=admin',
|
2021-11-25 12:01:51 -06:00
|
|
|
'--o:logging.file[@enable]=true --o:logging.level=' + (debug ? 'trace' : 'warning'),
|
2021-07-08 05:14:57 -05:00
|
|
|
'--o:trace_event[@enable]=true',
|
2022-04-13 13:56:40 -05:00
|
|
|
`--port=${port}`,
|
|
|
|
'--signal'
|
2021-07-08 05:14:57 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
let ssl_args = [
|
|
|
|
`--o:ssl.cert_file_path=${top_builddir}/etc/cert.pem`,
|
|
|
|
`--o:ssl.key_file_path=${top_builddir}/etc/key.pem`,
|
|
|
|
`--o:ssl.ca_file_path=${top_builddir}/etc/ca-chain.cert.pem`,
|
|
|
|
];
|
|
|
|
|
|
|
|
if (ssl_flag === 'true')
|
|
|
|
args = [...args, ...ssl_args];
|
|
|
|
|
2022-04-13 13:56:40 -05:00
|
|
|
process.on('SIGUSR2', serverReady);
|
2022-04-13 13:50:50 -05:00
|
|
|
|
|
|
|
var coolwsd_options = debug ? {} : { stdio: 'ignore'};
|
|
|
|
const coolwsd = spawn(`${top_builddir}/coolwsd`, args, coolwsd_options);
|
2021-07-08 05:14:57 -05:00
|
|
|
|
2021-11-25 12:01:51 -06:00
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
coolwsd.stdout.on('data', (data) => {
|
|
|
|
console.log(`stdout: ${data}`);
|
|
|
|
});
|
|
|
|
coolwsd.stderr.on('data', (data) => {
|
|
|
|
console.error(`stderr: ${data}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
coolwsd.on('exit', (code) => {
|
|
|
|
console.log(`coolwsd process exited with code ${code}`);
|
2021-07-08 05:14:57 -05:00
|
|
|
});
|
|
|
|
|
2022-04-13 13:56:40 -05:00
|
|
|
process.env.NODE_PATH = `${top_builddir}/browser/node_modules`
|
2021-07-08 05:14:57 -05:00
|
|
|
let childNodes = [];
|
2021-07-15 07:44:28 -05:00
|
|
|
|
2022-04-13 13:56:40 -05:00
|
|
|
function serverReady() {
|
|
|
|
console.log('\nTest running - connect to:\n\n\t' +
|
|
|
|
'https://localhost:9999/browser/1234/cool.html?file_path=file://' +
|
|
|
|
top_builddir + '/test/data/perf-test-edit.odt\n\n');
|
2022-03-28 16:00:48 -05:00
|
|
|
|
2022-04-13 13:56:40 -05:00
|
|
|
let execArgs = [];
|
2022-03-28 16:00:48 -05:00
|
|
|
|
2022-04-13 13:56:40 -05:00
|
|
|
if (inspect === 'true')
|
2021-07-15 07:44:28 -05:00
|
|
|
execArgs.push('--inspect');
|
2022-04-13 13:56:40 -05:00
|
|
|
childNodes.push(
|
2021-07-23 02:03:49 -05:00
|
|
|
fork(`${srcdir}/test/load.js`, [ssl_flag, top_builddir, `${top_builddir}/test/data/perf-test-edit.odt`, `testEdit_1`, `${port}`, `${typing_speed}`, `${typing_duration}`, `${recordStats}`, `${single_view}`], {execArgv: execArgs})
|
2021-07-15 07:44:28 -05:00
|
|
|
);
|
2022-04-13 13:56:40 -05:00
|
|
|
if(single_view !== "true") {
|
2021-07-15 07:44:28 -05:00
|
|
|
for (let i = 2; i <= 6; i++) {
|
2022-04-13 13:56:40 -05:00
|
|
|
childNodes.push(
|
|
|
|
fork(`${srcdir}/test/load.js`, [ssl_flag, top_builddir, `${top_builddir}/test/data/perf-test-edit.odt`, `testEdit_${i}`, `${port}`, `${typing_speed}`, `${typing_duration}`, 'false', 'false'])
|
2021-07-15 07:44:28 -05:00
|
|
|
);
|
|
|
|
}
|
2022-04-13 13:56:40 -05:00
|
|
|
}
|
2021-07-08 05:14:57 -05:00
|
|
|
}
|
|
|
|
|
2022-01-07 13:06:22 -06:00
|
|
|
|
|
|
|
|
2021-07-08 05:14:57 -05:00
|
|
|
function vacuumCleaner(kill, message, code) {
|
|
|
|
console.log(message);
|
|
|
|
childNodes.forEach(n => n.kill(kill));
|
2021-11-18 06:08:14 -06:00
|
|
|
coolwsd.kill(kill);
|
2021-07-08 05:14:57 -05:00
|
|
|
console.log(`Process exited with code ${code}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function exitHandler(options, exitCode) {
|
|
|
|
if (options.cleanup) {
|
|
|
|
vacuumCleaner('SIGKILL', 'cleaning up...', exitCode)
|
|
|
|
}
|
|
|
|
if (options.exit) {
|
|
|
|
vacuumCleaner('SIGINT', 'exiting...', exitCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//do something when app is closing
|
|
|
|
process.on('exit', exitHandler.bind(null,{cleanup: true}));
|
|
|
|
|
|
|
|
//catches ctrl+c event
|
|
|
|
process.on('SIGINT', exitHandler.bind(null, {exit: true}));
|
|
|
|
|
|
|
|
//catches uncaught exceptions
|
2022-01-07 13:06:22 -06:00
|
|
|
process.on('uncaughtException', ex => {
|
|
|
|
console.error(ex, 'uncaught exception');
|
|
|
|
exitHandler({exit:true});
|
|
|
|
});
|
|
|
|
|
|
|
|
function parseStats(content) {
|
|
|
|
var stats = {};
|
|
|
|
var lines = content.split('\n');
|
|
|
|
if (content.length < 128 || lines.length < 16)
|
|
|
|
return undefined; // too small
|
|
|
|
|
|
|
|
for (let l of lines) {
|
|
|
|
var keyval = l.split(' ');
|
|
|
|
if (keyval.length >= 2)
|
|
|
|
stats[keyval[0]] = keyval[1];
|
|
|
|
}
|
|
|
|
if (stats.size < 8)
|
|
|
|
return undefined; // not our stats
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dumpMemoryUse() {
|
|
|
|
var url = 'https://admin:admin@localhost:' + port + '/cool/getMetrics/';
|
|
|
|
console.log('Fetching stats from ' + url);
|
|
|
|
var req = https.request(
|
|
|
|
url,
|
|
|
|
{
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
requestCert: false,
|
|
|
|
timeout: 3000, // 3s
|
|
|
|
},
|
|
|
|
response => {
|
|
|
|
let data = [];
|
|
|
|
response.on('data', (frag) => {
|
|
|
|
data.push(frag);
|
|
|
|
});
|
|
|
|
response.on('end', () => {
|
|
|
|
let body = Buffer.concat(data);
|
|
|
|
var stats = parseStats(body.toString());
|
|
|
|
if (stats)
|
|
|
|
console.log('Stats: ' +
|
|
|
|
'views: ' + stats['document_all_views_all_count_total'] + ' ' +
|
|
|
|
'mem: ' + (stats['global_memory_used_bytes']/1000000) + 'Mb ' +
|
|
|
|
'sent: ' + (stats['document_all_sent_to_clients_total_bytes']/1000000) + 'Mb ' +
|
|
|
|
'recv: ' + (stats['document_all_received_from_clients_total_bytes']/1000) + 'Kb');
|
|
|
|
});
|
|
|
|
response.on('error', (err) => {
|
|
|
|
console.log('failed to get admin stats');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
req.end();
|
|
|
|
}
|
2021-07-08 05:14:57 -05:00
|
|
|
|
2022-01-07 13:06:22 -06:00
|
|
|
setInterval(dumpMemoryUse, 3000);
|