2019-03-02 15:19:08 +00:00
|
|
|
import AutheliaServerInterface from './AutheliaServerInterface';
|
|
|
|
import ChildProcess from 'child_process';
|
|
|
|
import treeKill = require('tree-kill');
|
|
|
|
import fs from 'fs';
|
|
|
|
|
|
|
|
class AutheliaServerFromDist implements AutheliaServerInterface {
|
|
|
|
private configPath: string;
|
|
|
|
private logInFile: boolean;
|
|
|
|
private serverProcess: ChildProcess.ChildProcess | undefined;
|
|
|
|
|
|
|
|
constructor(configPath: string, logInFile: boolean = false) {
|
|
|
|
this.configPath = configPath;
|
|
|
|
this.logInFile = logInFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
async start() {
|
2019-10-29 20:54:47 +00:00
|
|
|
console.log("Spawn authelia server from dist using config " + this.configPath);
|
|
|
|
this.serverProcess = ChildProcess.spawn('./cmd/authelia-scripts/authelia-scripts serve ' + this.configPath, {
|
2019-03-27 20:57:16 +00:00
|
|
|
shell: true,
|
|
|
|
env: process.env,
|
2019-03-02 15:19:08 +00:00
|
|
|
} as any);
|
2019-04-24 21:52:08 +00:00
|
|
|
if (!this.serverProcess || !this.serverProcess.stdout || !this.serverProcess.stderr) return;
|
2019-03-02 15:19:08 +00:00
|
|
|
if (this.logInFile) {
|
|
|
|
var logStream = fs.createWriteStream('/tmp/authelia-server.log', {flags: 'a'});
|
|
|
|
this.serverProcess.stdout.pipe(logStream);
|
|
|
|
this.serverProcess.stderr.pipe(logStream);
|
|
|
|
} else {
|
|
|
|
this.serverProcess.stdout.pipe(process.stdout);
|
|
|
|
this.serverProcess.stderr.pipe(process.stderr);
|
|
|
|
}
|
|
|
|
this.serverProcess.on('exit', (statusCode) => {
|
|
|
|
console.log('Authelia server exited with code ' + statusCode);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async stop() {
|
|
|
|
if (!this.serverProcess) return;
|
|
|
|
treeKill(this.serverProcess.pid, 'SIGKILL');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AutheliaServerFromDist;
|