mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-20 21:43:06 +00:00
Support gns3_server.ini configuration, Fixes: #324
This commit is contained in:
parent
7ccc9db33b
commit
24e9e23f7e
@ -2,6 +2,7 @@ const { spawn } = require('child_process');
|
||||
const kill = require('tree-kill');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const ini = require('ini');
|
||||
const { ipcMain } = require('electron')
|
||||
const { app } = require('electron')
|
||||
|
||||
@ -72,7 +73,7 @@ async function findLocalServerPath(baseDirectory) {
|
||||
return;
|
||||
}
|
||||
|
||||
function getServerArguments(server, overrides) {
|
||||
function getServerArguments(server, overrides, configPath) {
|
||||
let serverArguments = [];
|
||||
if(server.host) {
|
||||
serverArguments.push('--host');
|
||||
@ -82,6 +83,14 @@ function getServerArguments(server, overrides) {
|
||||
serverArguments.push('--port');
|
||||
serverArguments.push(server.port);
|
||||
}
|
||||
|
||||
serverArguments.push('--local');
|
||||
|
||||
if(configPath) {
|
||||
serverArguments.push('--config');
|
||||
serverArguments.push(configPath);
|
||||
}
|
||||
|
||||
return serverArguments;
|
||||
}
|
||||
|
||||
@ -153,6 +162,31 @@ async function stop(serverName) {
|
||||
return stopped;
|
||||
}
|
||||
|
||||
async function getIniFile(server) {
|
||||
return path.join(app.getPath('userData'), `gns3_server_${server.id}.ini`);
|
||||
}
|
||||
|
||||
async function configure(configPath, server) {
|
||||
if(!fs.existsSync(configPath)) {
|
||||
fs.closeSync(fs.openSync(configPath, 'w'));
|
||||
console.log(`Configuration file '${configPath}' has been created.`);
|
||||
}
|
||||
|
||||
var config = ini.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||
|
||||
if(server.path) {
|
||||
config.path = server.path;
|
||||
}
|
||||
if(server.host) {
|
||||
config.host = server.host;
|
||||
}
|
||||
if(server.port) {
|
||||
config.port = server.port;
|
||||
}
|
||||
|
||||
fs.writeFileSync(configPath, ini.stringify(config, { section: 'Server' }));
|
||||
}
|
||||
|
||||
async function run(server, options) {
|
||||
if(!options) {
|
||||
options = {};
|
||||
@ -161,9 +195,14 @@ async function run(server, options) {
|
||||
const logStdout = options.logStdout || false;
|
||||
const logSterr = options.logSterr || false;
|
||||
|
||||
console.log(`Configuring`)
|
||||
|
||||
const configPath = await getIniFile(server);
|
||||
await configure(configPath, server);
|
||||
|
||||
console.log(`Running '${server.path}'`);
|
||||
|
||||
let serverProcess = spawn(server.path, getServerArguments(server));
|
||||
let serverProcess = spawn(server.path, getServerArguments(server, {}, configPath));
|
||||
|
||||
notifyStatus({
|
||||
serverName: server.name,
|
||||
|
@ -58,6 +58,7 @@
|
||||
"css-tree": "^1.0.0-alpha.29",
|
||||
"d3-ng2-service": "^2.1.0",
|
||||
"hammerjs": "^2.0.8",
|
||||
"ini": "^1.3.5",
|
||||
"material-design-icons": "^3.0.1",
|
||||
"ng2-file-upload": "^1.3.0",
|
||||
"ngx-electron": "^2.1.1",
|
||||
@ -66,9 +67,9 @@
|
||||
"raven-js": "^3.27.0",
|
||||
"rxjs": "^6.4.0",
|
||||
"rxjs-compat": "^6.4.0",
|
||||
"tree-kill": "^1.2.1",
|
||||
"typeface-roboto": "^0.0.54",
|
||||
"yargs": "^13.2.1",
|
||||
"tree-kill": "^1.2.1",
|
||||
"zone.js": "^0.8.29"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -38,9 +38,11 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
|
||||
// attach to notification stream when any of running local servers experienced issues
|
||||
this.serverStatusSubscription = this.serverManagement.serverStatusChanged.subscribe((serverStatus) => {
|
||||
if(serverStatus.status === 'errored') {
|
||||
console.error(serverStatus.message);
|
||||
this.toasterService.error(serverStatus.message);
|
||||
}
|
||||
if(serverStatus.status === 'stderr') {
|
||||
console.error(serverStatus.message);
|
||||
this.toasterService.error(serverStatus.message);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user