diff --git a/local-server.js b/local-server.js index 6e6e8285..840a0c28 100644 --- a/local-server.js +++ b/local-server.js @@ -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, diff --git a/package.json b/package.json index f7d78be8..ecae042f 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/app/layouts/default-layout/default-layout.component.ts b/src/app/layouts/default-layout/default-layout.component.ts index 5035fca2..8e608da4 100644 --- a/src/app/layouts/default-layout/default-layout.component.ts +++ b/src/app/layouts/default-layout/default-layout.component.ts @@ -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); } });