WIP: Join Process
This commit is contained in:
parent
7beb10947f
commit
173a6f3109
|
|
@ -146,6 +146,9 @@ function load_config() {
|
|||
config.package = JSON.parse(fs.readFileSync(path.join(config.dirs.app, 'package.json'), 'utf8'));
|
||||
config.dependencies = {}
|
||||
|
||||
// SDL Version
|
||||
config.cluster.sdl_version = config.package.version
|
||||
|
||||
for (let d in config.package.dependencies) {
|
||||
config.dependencies[d] = JSON.parse(fs.readFileSync(path.join(config.dirs.app, 'node_modules', d, 'package.json'), 'utf8'));
|
||||
}
|
||||
|
|
@ -158,6 +161,7 @@ function load_config() {
|
|||
ips: [],
|
||||
|
||||
os: {
|
||||
platform: null,
|
||||
id: null,
|
||||
name: null,
|
||||
version: null,
|
||||
|
|
@ -218,6 +222,8 @@ function load_config() {
|
|||
config.host.cpu.cores_logical = cpus.length;
|
||||
}
|
||||
|
||||
config.host.os.platform = os.platform();
|
||||
|
||||
// -------------------------------
|
||||
// OS Info from /etc/os-release (Linux)
|
||||
// -------------------------------
|
||||
|
|
|
|||
|
|
@ -1,14 +1,83 @@
|
|||
const module = 'sdl-mgr'; // Module Name
|
||||
|
||||
import { load_config, log, ipToInt, intToIp, computeBroadcast, getUptimeDHMS } from '../nwa-lib/index.js';
|
||||
import { load_config, log, ipToInt, intToIp, computeBroadcast, getProcessStartTs, getUptimeDHMS } from '../nwa-lib/index.js';
|
||||
import mqtt from 'mqtt';
|
||||
import os from 'os';
|
||||
import dgram from 'dgram';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
|
||||
const config = load_config();
|
||||
|
||||
log(`Loaded module: ${module}`);
|
||||
// log(`${module}: Cluster Conf: ${JSON.stringify(config.cluster, null, 2)}`, true);
|
||||
// log(`${module}: Dirs: ${JSON.stringify(config.dirs, null, 2)}`, true);
|
||||
|
||||
function loadClusterState(config) {
|
||||
const clusterDir = config.dirs.clstr;
|
||||
const clusterFile = path.join(clusterDir, 'cluster.json');
|
||||
|
||||
// Ensure cluster directory exists
|
||||
if (!fs.existsSync(clusterDir)) {
|
||||
fs.mkdirSync(clusterDir, { recursive: true });
|
||||
}
|
||||
|
||||
// If cluster.json doesn't exist, create initial state
|
||||
if (!fs.existsSync(clusterFile)) {
|
||||
const initialState = {
|
||||
meta: {
|
||||
updated: new Date().toISOString(),
|
||||
started_at: new Date(getProcessStartTs()).toISOString(),
|
||||
uptime: getUptimeDHMS(),
|
||||
stats: {
|
||||
workers: {
|
||||
allocated: 0,
|
||||
available: 0,
|
||||
used: 0
|
||||
},
|
||||
resources: {
|
||||
cpus: {
|
||||
allocated: 0,
|
||||
available: 0,
|
||||
used: 0
|
||||
},
|
||||
memory: {
|
||||
allocated: 0,
|
||||
available: 0,
|
||||
used: 0
|
||||
},
|
||||
gpus: {
|
||||
allocated: 0,
|
||||
available: 0,
|
||||
used: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
cluster: config.cluster,
|
||||
"sdl-mgr": {
|
||||
sdl_id: config.identity.sdl_id,
|
||||
hostname: config.identity.hostname,
|
||||
platform: config.host.os.platform,
|
||||
arch: config.host.cpu.arch,
|
||||
distro: config.host.os.pretty_name,
|
||||
distro_name: config.host.os.name,
|
||||
distro_version: config.host.os.version
|
||||
},
|
||||
workers: {}
|
||||
};
|
||||
|
||||
fs.writeFileSync(clusterFile, JSON.stringify(initialState, null, 2));
|
||||
return initialState;
|
||||
}
|
||||
|
||||
// Load existing cluster state
|
||||
const data = fs.readFileSync(clusterFile, 'utf8');
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function startSDLStatusPub() {
|
||||
const sdlCfg = config.modules[module];
|
||||
|
|
@ -231,3 +300,4 @@ function startUdpBeacon() {
|
|||
// -------------------------------
|
||||
startSDLStatusPub();
|
||||
startUdpBeacon();
|
||||
loadClusterState(config);
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
"dist": "SDLHOME/dist",
|
||||
"logs": "SDLHOME/logs",
|
||||
"data": "SDLHOME/data",
|
||||
"clstr": "DATA/cluster",
|
||||
"proj": "DATA/proj",
|
||||
"jobs": "DATA/jobs",
|
||||
"conf": "SDLHOME/conf",
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const config = load_config();
|
|||
log('=======================================================================================');
|
||||
log(config.package.name + ': STARTING: ' + config.package.description + ' v' + config.package.version);
|
||||
// log(JSON.stringify(config, null, 2));
|
||||
log(JSON.stringify(config.dirs, null, 2), false);
|
||||
// log(JSON.stringify(config.dirs, null, 2), false);
|
||||
|
||||
for (let m in config.modules) {
|
||||
// log(`Loading module: ${m}`);
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ function load_config() {
|
|||
ips: [],
|
||||
|
||||
os: {
|
||||
platform: null,
|
||||
id: null,
|
||||
name: null,
|
||||
version: null,
|
||||
|
|
@ -218,6 +219,8 @@ function load_config() {
|
|||
config.host.cpu.cores_logical = cpus.length;
|
||||
}
|
||||
|
||||
config.host.os.platform = os.platform();
|
||||
|
||||
// -------------------------------
|
||||
// OS Info from /etc/os-release (Linux)
|
||||
// -------------------------------
|
||||
|
|
|
|||
Loading…
Reference in New Issue