mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-14 14:17:25 -05:00
Completely rewrote the code, home builds locally rather on Gitlab, releases are done manually aswell
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
const { spawn } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const http = require('http');
|
||||
const CredentialManager = require('./credential-manager');
|
||||
|
||||
class ServiceManager {
|
||||
@@ -23,6 +22,8 @@ class ServiceManager {
|
||||
const logPath = path.join(this.logsDir, `${name}.log`);
|
||||
const timestamp = new Date().toISOString();
|
||||
fs.appendFileSync(logPath, `[${timestamp}] ${line}\n`, 'utf8');
|
||||
|
||||
process.stdout.write(JSON.stringify({ event: "service-log", data: { service: name, message: line } }) + '\n');
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
@@ -39,10 +40,14 @@ class ServiceManager {
|
||||
throw new Error(`Service script not found: ${scriptPath}`);
|
||||
}
|
||||
|
||||
const tokenSecret = process.env.TOKEN_SECRET ||
|
||||
let tokenSecret = process.env.TOKEN_SECRET ||
|
||||
process.env.STREAM_API_TOKEN_SECRET ||
|
||||
this.credentialManager.getCredential('stream-api', 'TOKEN_SECRET') ||
|
||||
require('crypto').randomBytes(32).toString('hex');
|
||||
this.credentialManager.getCredential('stream-api', 'TOKEN_SECRET');
|
||||
|
||||
if (!tokenSecret || tokenSecret.length < 32) {
|
||||
tokenSecret = require('crypto').randomBytes(32).toString('hex');
|
||||
this.credentialManager.setCredential('stream-api', 'TOKEN_SECRET', tokenSecret);
|
||||
}
|
||||
|
||||
const env = {
|
||||
...process.env,
|
||||
@@ -77,13 +82,11 @@ class ServiceManager {
|
||||
|
||||
child.stdout.on('data', (data) => {
|
||||
const text = data.toString().trim();
|
||||
console.log(`[${name}] STDOUT: ${text}`);
|
||||
this.logToFile(name, `STDOUT: ${text}`);
|
||||
});
|
||||
|
||||
child.stderr.on('data', (data) => {
|
||||
const text = data.toString().trim();
|
||||
console.error(`[${name}] STDERR: ${text}`);
|
||||
this.logToFile(name, `STDERR: ${text}`);
|
||||
});
|
||||
|
||||
@@ -117,10 +120,6 @@ class ServiceManager {
|
||||
));
|
||||
}
|
||||
|
||||
async waitForPorts(ports, timeoutMs = 30000) {
|
||||
await Promise.all(ports.map((port) => this.waitForPort(port, timeoutMs)));
|
||||
}
|
||||
|
||||
async stopAll() {
|
||||
this.isStopping = true;
|
||||
for (const name of Object.keys(this.stableTimers)) {
|
||||
@@ -146,6 +145,10 @@ class ServiceManager {
|
||||
this.processes = {};
|
||||
}
|
||||
|
||||
async waitForPorts(ports, timeoutMs = 30000) {
|
||||
await Promise.all(ports.map((port) => this.waitForPort(port, timeoutMs)));
|
||||
}
|
||||
|
||||
async waitForPort(port, timeoutMs = 30000) {
|
||||
const start = Date.now();
|
||||
const net = require('net');
|
||||
|
||||
Reference in New Issue
Block a user