mirror of
https://github.com/koush/scrypted.git
synced 2026-05-20 04:00:27 +01:00
server: add env control
This commit is contained in:
4
server/package-lock.json
generated
4
server/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/server",
|
||||
"version": "0.123.41",
|
||||
"version": "0.123.42",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/server",
|
||||
"version": "0.123.41",
|
||||
"version": "0.123.42",
|
||||
"hasInstallScript": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
|
||||
@@ -46,6 +46,7 @@ import { UsersService } from './services/users';
|
||||
import { getState, ScryptedStateManager, setState } from './state';
|
||||
import { isClusterAddress } from './cluster/cluster-setup';
|
||||
import { RunningClusterWorker } from './scrypted-cluster-main';
|
||||
import { EnvControl } from './services/env';
|
||||
|
||||
interface DeviceProxyPair {
|
||||
handler: PluginDeviceProxyHandler;
|
||||
@@ -90,6 +91,7 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
|
||||
addressSettings = new AddressSettings(this);
|
||||
usersService = new UsersService(this);
|
||||
clusterFork = new ClusterForkService(this);
|
||||
envControl = new EnvControl();
|
||||
info = new Info();
|
||||
backup = new Backup(this);
|
||||
pluginHosts = getBuiltinRuntimeHosts();
|
||||
@@ -125,7 +127,7 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
|
||||
}
|
||||
|
||||
let address = clusterObject.address;
|
||||
if (isClusterAddress(address))
|
||||
if (isClusterAddress(address))
|
||||
address = '127.0.0.1';
|
||||
const socket = net.connect({
|
||||
port: clusterObject.port,
|
||||
@@ -376,6 +378,8 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
|
||||
return this.backup;
|
||||
case 'cluster-fork':
|
||||
return this.clusterFork;
|
||||
case 'env-control':
|
||||
return this.envControl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import type { ScryptedRuntime } from './runtime';
|
||||
import type { ClusterForkService } from './services/cluster-fork';
|
||||
import { sleep } from './sleep';
|
||||
import type { ServiceControl } from './services/service-control';
|
||||
import { EnvControl } from './services/env';
|
||||
|
||||
installSourceMapSupport({
|
||||
environment: 'node',
|
||||
@@ -200,6 +201,9 @@ function createClusterForkParam(mainFilename: string, clusterId: string, cluster
|
||||
|
||||
export function startClusterClient(mainFilename: string, serviceControl?: ServiceControl) {
|
||||
console.log('Cluster client starting.');
|
||||
|
||||
const envControl = new EnvControl();
|
||||
|
||||
const originalClusterAddress = process.env.SCRYPTED_CLUSTER_ADDRESS;
|
||||
const labels = getClusterLabels();
|
||||
|
||||
@@ -248,6 +252,8 @@ export function startClusterClient(mainFilename: string, serviceControl?: Servic
|
||||
process.env.SCRYPTED_CLUSTER_ADDRESS = socket.localAddress;
|
||||
|
||||
const peer = preparePeer(socket, 'client');
|
||||
peer.params['service-control'] = serviceControl;
|
||||
peer.params['env-control'] = envControl;
|
||||
const { localAddress, localPort } = socket;
|
||||
console.log('Cluster server connected.', localAddress, localPort);
|
||||
socket.on('close', () => {
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import dns from 'dns';
|
||||
import dotenv from 'dotenv';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import process from 'process';
|
||||
import semver from 'semver';
|
||||
import v8 from 'v8';
|
||||
import vm from 'vm';
|
||||
import { getScryptedClusterMode } from './cluster/cluster-setup';
|
||||
import { PluginError } from './plugin/plugin-error';
|
||||
import { getScryptedVolume } from './plugin/plugin-volume';
|
||||
import { isNodePluginWorkerProcess } from './plugin/runtime/node-fork-worker';
|
||||
import { RPCResultError, startPeriodicGarbageCollection } from './rpc';
|
||||
import type { Runtime } from './scrypted-server-main';
|
||||
import { getScryptedClusterMode } from './cluster/cluster-setup';
|
||||
import { getDotEnvPath } from './services/env';
|
||||
import type { ServiceControl } from './services/service-control';
|
||||
|
||||
function start(mainFilename: string, options?: {
|
||||
@@ -66,7 +65,7 @@ function start(mainFilename: string, options?: {
|
||||
});
|
||||
|
||||
dotenv.config({
|
||||
path: path.join(getScryptedVolume(), '.env'),
|
||||
path: getDotEnvPath(),
|
||||
});
|
||||
|
||||
const clusterMode = getScryptedClusterMode();
|
||||
|
||||
17
server/src/services/env.ts
Normal file
17
server/src/services/env.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { getScryptedVolume } from '../plugin/plugin-volume';
|
||||
|
||||
export function getDotEnvPath() {
|
||||
return path.join(getScryptedVolume(), '.env')
|
||||
}
|
||||
|
||||
export class EnvControl {
|
||||
async setDotEnv(env: string) {
|
||||
await fs.promises.writeFile(getDotEnvPath(), env, 'utf8');
|
||||
}
|
||||
|
||||
getDotEnv() {
|
||||
return fs.promises.readFile(getDotEnvPath(), 'utf8');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user