mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
|
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() {
|
||
|
this.serverProcess = ChildProcess.spawn('./scripts/authelia-scripts serve ' + this.configPath, {
|
||
|
shell: true
|
||
|
} as any);
|
||
|
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;
|