@docker-digital/dockernet-agent 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent.module.js +29 -3
- package/dist/agent/agent.module.js.map +1 -1
- package/dist/agent/commands/agent.command.d.ts +3 -50
- package/dist/agent/commands/agent.command.js +20 -465
- package/dist/agent/commands/agent.command.js.map +1 -1
- package/dist/agent/commands/apikey.command.d.ts +16 -0
- package/dist/agent/commands/apikey.command.js +71 -0
- package/dist/agent/commands/apikey.command.js.map +1 -0
- package/dist/agent/commands/config.command.d.ts +7 -0
- package/dist/agent/commands/config.command.js +44 -0
- package/dist/agent/commands/config.command.js.map +1 -0
- package/dist/agent/commands/log.command.d.ts +7 -0
- package/dist/agent/commands/log.command.js +45 -0
- package/dist/agent/commands/log.command.js.map +1 -0
- package/dist/agent/commands/profiles.command.d.ts +7 -0
- package/dist/agent/commands/profiles.command.js +67 -0
- package/dist/agent/commands/profiles.command.js.map +1 -0
- package/dist/agent/commands/restart.command.d.ts +9 -0
- package/dist/agent/commands/restart.command.js +40 -0
- package/dist/agent/commands/restart.command.js.map +1 -0
- package/dist/agent/commands/run.command.d.ts +29 -0
- package/dist/agent/commands/run.command.js +210 -0
- package/dist/agent/commands/run.command.js.map +1 -0
- package/dist/agent/commands/stop.command.d.ts +7 -0
- package/dist/agent/commands/stop.command.js +52 -0
- package/dist/agent/commands/stop.command.js.map +1 -0
- package/dist/agent/commands/upgrade.command.d.ts +7 -0
- package/dist/agent/commands/upgrade.command.js +37 -0
- package/dist/agent/commands/upgrade.command.js.map +1 -0
- package/dist/agent/commands/version.command.d.ts +4 -0
- package/dist/agent/commands/version.command.js +26 -0
- package/dist/agent/commands/version.command.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -9,7 +9,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.AgentModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const config_1 = require("@nestjs/config");
|
|
12
|
-
const
|
|
12
|
+
const run_command_1 = require("./commands/run.command");
|
|
13
|
+
const stop_command_1 = require("./commands/stop.command");
|
|
14
|
+
const restart_command_1 = require("./commands/restart.command");
|
|
15
|
+
const log_command_1 = require("./commands/log.command");
|
|
16
|
+
const version_command_1 = require("./commands/version.command");
|
|
17
|
+
const config_command_1 = require("./commands/config.command");
|
|
18
|
+
const profiles_command_1 = require("./commands/profiles.command");
|
|
19
|
+
const apikey_command_1 = require("./commands/apikey.command");
|
|
20
|
+
const upgrade_command_1 = require("./commands/upgrade.command");
|
|
13
21
|
const api_service_1 = require("./services/api.service");
|
|
14
22
|
const config_service_1 = require("./services/config.service");
|
|
15
23
|
const docker_service_1 = require("./services/docker.service");
|
|
@@ -29,7 +37,15 @@ exports.AgentModule = AgentModule = __decorate([
|
|
|
29
37
|
(0, common_1.Module)({
|
|
30
38
|
imports: [config_1.ConfigModule],
|
|
31
39
|
providers: [
|
|
32
|
-
|
|
40
|
+
run_command_1.RunCommand,
|
|
41
|
+
stop_command_1.StopCommand,
|
|
42
|
+
restart_command_1.RestartCommand,
|
|
43
|
+
log_command_1.LogCommand,
|
|
44
|
+
version_command_1.VersionCommand,
|
|
45
|
+
config_command_1.ConfigCommand,
|
|
46
|
+
profiles_command_1.ProfilesCommand,
|
|
47
|
+
apikey_command_1.ApiKeyCommand,
|
|
48
|
+
upgrade_command_1.UpgradeCommand,
|
|
33
49
|
api_service_1.ApiService,
|
|
34
50
|
config_service_1.ConfigService,
|
|
35
51
|
docker_service_1.DockerService,
|
|
@@ -43,7 +59,17 @@ exports.AgentModule = AgentModule = __decorate([
|
|
|
43
59
|
event_websocket_client_service_1.EventWebSocketClientService,
|
|
44
60
|
nebula_service_1.NebulaService,
|
|
45
61
|
],
|
|
46
|
-
exports: [
|
|
62
|
+
exports: [
|
|
63
|
+
run_command_1.RunCommand,
|
|
64
|
+
stop_command_1.StopCommand,
|
|
65
|
+
restart_command_1.RestartCommand,
|
|
66
|
+
log_command_1.LogCommand,
|
|
67
|
+
version_command_1.VersionCommand,
|
|
68
|
+
config_command_1.ConfigCommand,
|
|
69
|
+
profiles_command_1.ProfilesCommand,
|
|
70
|
+
apikey_command_1.ApiKeyCommand,
|
|
71
|
+
upgrade_command_1.UpgradeCommand,
|
|
72
|
+
],
|
|
47
73
|
})
|
|
48
74
|
], AgentModule);
|
|
49
75
|
//# sourceMappingURL=agent.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.module.js","sourceRoot":"","sources":["../../src/agent/agent.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2CAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"agent.module.js","sourceRoot":"","sources":["../../src/agent/agent.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2CAA8C;AAC9C,wDAAoD;AACpD,0DAAsD;AACtD,gEAA4D;AAC5D,wDAAoD;AACpD,gEAA4D;AAC5D,8DAA0D;AAC1D,kEAA8D;AAC9D,8DAA0D;AAC1D,gEAA4D;AAC5D,wDAAoD;AACpD,8DAA0D;AAC1D,8DAA0D;AAC1D,0EAAqE;AACrE,4DAAwD;AACxD,wDAAoD;AACpD,gEAA4D;AAC5D,gEAA4D;AAC5D,wEAAmE;AACnE,kFAA6E;AAC7E,8FAAwF;AACxF,8DAA0D;AAyCnD,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IAvCvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAY,CAAC;QACvB,SAAS,EAAE;YAET,wBAAU;YACV,0BAAW;YACX,gCAAc;YACd,wBAAU;YACV,gCAAc;YACd,8BAAa;YACb,kCAAe;YACf,8BAAa;YACb,gCAAc;YAEd,wBAAU;YACV,8BAAa;YACb,8BAAa;YACb,yCAAkB;YAClB,4BAAY;YACZ,wBAAU;YACV,gCAAc;YACd,gCAAc;YACd,uCAAiB;YACjB,iDAAsB;YACtB,4DAA2B;YAC3B,8BAAa;SACd;QACD,OAAO,EAAE;YACP,wBAAU;YACV,0BAAW;YACX,gCAAc;YACd,wBAAU;YACV,gCAAc;YACd,8BAAa;YACb,kCAAe;YACf,8BAAa;YACb,gCAAc;SACf;KACF,CAAC;GACW,WAAW,CAAG"}
|
|
@@ -2,61 +2,14 @@ import { OnModuleInit } from '@nestjs/common';
|
|
|
2
2
|
import { CommandRunner } from 'nest-commander';
|
|
3
3
|
import { ApiService } from '../services/api.service';
|
|
4
4
|
import { ConfigService } from '../services/config.service';
|
|
5
|
-
import { DockerService } from '../services/docker.service';
|
|
6
|
-
import { EventService } from '../services/event.service';
|
|
7
|
-
import { LogService } from '../services/log.service';
|
|
8
5
|
import { MachineService } from '../services/machine.service';
|
|
9
|
-
import { ProfileService } from '../services/profile.service';
|
|
10
|
-
import { VolumeSyncService } from '../services/volume-sync.service';
|
|
11
|
-
import { WebSocketClientService } from '../services/websocket-client.service';
|
|
12
|
-
import { NebulaService } from '../services/nebula.service';
|
|
13
|
-
interface AgentCommandOptions {
|
|
14
|
-
apiKey?: string;
|
|
15
|
-
config?: boolean;
|
|
16
|
-
profiles?: boolean;
|
|
17
|
-
upgrade?: boolean;
|
|
18
|
-
log?: boolean;
|
|
19
|
-
version?: boolean;
|
|
20
|
-
run?: boolean;
|
|
21
|
-
stop?: boolean;
|
|
22
|
-
restart?: boolean;
|
|
23
|
-
}
|
|
24
6
|
export declare class AgentCommand extends CommandRunner implements OnModuleInit {
|
|
25
7
|
private apiService;
|
|
26
8
|
private configService;
|
|
27
|
-
private dockerService;
|
|
28
|
-
private eventService;
|
|
29
|
-
private logService;
|
|
30
9
|
private machineService;
|
|
31
|
-
|
|
32
|
-
private volumeSyncService;
|
|
33
|
-
private websocketClientService;
|
|
34
|
-
private nebulaService;
|
|
35
|
-
private readonly logger;
|
|
36
|
-
private isRunning;
|
|
37
|
-
constructor(apiService: ApiService, configService: ConfigService, dockerService: DockerService, eventService: EventService, logService: LogService, machineService: MachineService, profileService: ProfileService, volumeSyncService: VolumeSyncService, websocketClientService: WebSocketClientService, nebulaService: NebulaService);
|
|
10
|
+
constructor(apiService: ApiService, configService: ConfigService, machineService: MachineService);
|
|
38
11
|
onModuleInit(): Promise<void>;
|
|
39
|
-
run(
|
|
40
|
-
parseApiKey(val: string): string;
|
|
41
|
-
parseConfig(): boolean;
|
|
42
|
-
parseProfiles(): boolean;
|
|
43
|
-
parseUpgrade(): boolean;
|
|
44
|
-
parseLog(): boolean;
|
|
45
|
-
parseVersion(): boolean;
|
|
46
|
-
parseRun(): boolean;
|
|
47
|
-
parseStop(): boolean;
|
|
48
|
-
parseRestart(): boolean;
|
|
49
|
-
private handleApiKey;
|
|
50
|
-
private handleConfig;
|
|
51
|
-
private handleProfiles;
|
|
52
|
-
private handleUpgrade;
|
|
53
|
-
private handleLog;
|
|
54
|
-
private handleVersion;
|
|
55
|
-
private handleWelcome;
|
|
56
|
-
private handleStop;
|
|
57
|
-
private handleRestart;
|
|
58
|
-
private printUsage;
|
|
12
|
+
run(): Promise<void>;
|
|
59
13
|
private promptForApiKey;
|
|
60
|
-
|
|
14
|
+
private handleWelcome;
|
|
61
15
|
}
|
|
62
|
-
export {};
|
|
@@ -8,204 +8,38 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var AgentCommand_1;
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
12
|
exports.AgentCommand = void 0;
|
|
14
13
|
const common_1 = require("@nestjs/common");
|
|
15
14
|
const nest_commander_1 = require("nest-commander");
|
|
16
|
-
const fs = require("fs-extra");
|
|
17
|
-
const path = require("path");
|
|
18
15
|
const readline = require("readline");
|
|
19
16
|
const api_service_1 = require("../services/api.service");
|
|
20
17
|
const config_service_1 = require("../services/config.service");
|
|
21
|
-
const docker_service_1 = require("../services/docker.service");
|
|
22
|
-
const event_service_1 = require("../services/event.service");
|
|
23
|
-
const log_service_1 = require("../services/log.service");
|
|
24
18
|
const machine_service_1 = require("../services/machine.service");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const websocket_client_service_1 = require("../services/websocket-client.service");
|
|
28
|
-
const nebula_service_1 = require("../services/nebula.service");
|
|
29
|
-
let AgentCommand = AgentCommand_1 = class AgentCommand extends nest_commander_1.CommandRunner {
|
|
30
|
-
constructor(apiService, configService, dockerService, eventService, logService, machineService, profileService, volumeSyncService, websocketClientService, nebulaService) {
|
|
19
|
+
let AgentCommand = class AgentCommand extends nest_commander_1.CommandRunner {
|
|
20
|
+
constructor(apiService, configService, machineService) {
|
|
31
21
|
super();
|
|
32
22
|
this.apiService = apiService;
|
|
33
23
|
this.configService = configService;
|
|
34
|
-
this.dockerService = dockerService;
|
|
35
|
-
this.eventService = eventService;
|
|
36
|
-
this.logService = logService;
|
|
37
24
|
this.machineService = machineService;
|
|
38
|
-
this.profileService = profileService;
|
|
39
|
-
this.volumeSyncService = volumeSyncService;
|
|
40
|
-
this.websocketClientService = websocketClientService;
|
|
41
|
-
this.nebulaService = nebulaService;
|
|
42
|
-
this.logger = new common_1.Logger(AgentCommand_1.name);
|
|
43
|
-
this.isRunning = false;
|
|
44
25
|
}
|
|
45
26
|
async onModuleInit() {
|
|
46
27
|
await this.apiService.initialize();
|
|
47
28
|
}
|
|
48
|
-
async run(
|
|
49
|
-
|
|
50
|
-
await this.handleApiKey(options.apiKey);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (options?.config) {
|
|
54
|
-
await this.handleConfig();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (options?.profiles) {
|
|
58
|
-
await this.handleProfiles();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (options?.upgrade) {
|
|
62
|
-
await this.handleUpgrade();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (options?.log) {
|
|
66
|
-
await this.handleLog();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (options?.version) {
|
|
70
|
-
this.handleVersion();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (options?.stop) {
|
|
74
|
-
await this.handleStop();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (options?.restart) {
|
|
78
|
-
await this.handleRestart();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!options || Object.keys(options).length === 0) {
|
|
82
|
-
if (passedParams.length === 0) {
|
|
83
|
-
await this.handleWelcome();
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (options?.run) {
|
|
88
|
-
await this.runDaemon();
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this.printUsage();
|
|
92
|
-
}
|
|
93
|
-
parseApiKey(val) {
|
|
94
|
-
return val;
|
|
95
|
-
}
|
|
96
|
-
parseConfig() {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
parseProfiles() {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
parseUpgrade() {
|
|
103
|
-
return true;
|
|
29
|
+
async run() {
|
|
30
|
+
await this.handleWelcome();
|
|
104
31
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
parseRestart() {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
async handleApiKey(apiKey) {
|
|
121
|
-
if (!apiKey) {
|
|
122
|
-
console.error('API key is required');
|
|
123
|
-
console.error('Example: agent --apiKey YOUR_API_KEY');
|
|
124
|
-
process.exit(1);
|
|
125
|
-
}
|
|
126
|
-
const existing = await this.configService.loadConfig();
|
|
127
|
-
const machineKey = existing.machineKey || this.machineService.generateMachineKey();
|
|
128
|
-
if (!existing.machineKey) {
|
|
129
|
-
console.log(`Generated new MACHINE_KEY: ${machineKey}`);
|
|
130
|
-
}
|
|
131
|
-
await this.configService.saveConfig({
|
|
132
|
-
apiKey,
|
|
133
|
-
machineKey,
|
|
134
|
-
serverUrl: existing.serverUrl,
|
|
32
|
+
async promptForApiKey() {
|
|
33
|
+
const rl = readline.createInterface({
|
|
34
|
+
input: process.stdin,
|
|
35
|
+
output: process.stdout,
|
|
36
|
+
});
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
rl.question('Please enter your API Key: ', (answer) => {
|
|
39
|
+
rl.close();
|
|
40
|
+
resolve(answer.trim());
|
|
41
|
+
});
|
|
135
42
|
});
|
|
136
|
-
await this.apiService.setApiKey(apiKey);
|
|
137
|
-
console.log(`API key saved to ${this.configService.configFilePath}`);
|
|
138
|
-
process.exit(0);
|
|
139
|
-
}
|
|
140
|
-
async handleConfig() {
|
|
141
|
-
const config = await this.configService.loadConfig();
|
|
142
|
-
console.log(`Config file : ${this.configService.configFilePath}`);
|
|
143
|
-
console.log(`SERVER_URL : ${this.configService.serverUrl}`);
|
|
144
|
-
console.log(`MACHINE_KEY : ${config.machineKey || '<not set>'}`);
|
|
145
|
-
if (config.apiKey) {
|
|
146
|
-
console.log(`API_KEY : (set, value hidden)`);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
console.log(`API_KEY : <not set>`);
|
|
150
|
-
}
|
|
151
|
-
process.exit(0);
|
|
152
|
-
}
|
|
153
|
-
async handleProfiles() {
|
|
154
|
-
const workDir = this.configService.workDirPath;
|
|
155
|
-
const profiles = await fs.readdir(workDir);
|
|
156
|
-
console.log(`Profiles in ${workDir}:`);
|
|
157
|
-
console.log(`${'PROFILE_ID'.padEnd(30)} | ${'WORKSPACE_ID'.padEnd(36)} | ${'RUNNING'.padEnd(10)}`);
|
|
158
|
-
console.log('-'.repeat(80));
|
|
159
|
-
let found = 0;
|
|
160
|
-
for (const profileId of profiles) {
|
|
161
|
-
const profileDir = path.join(workDir, profileId);
|
|
162
|
-
if (!(await fs.stat(profileDir)).isDirectory()) {
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
found++;
|
|
166
|
-
const metadataFile = path.join(profileDir, '.profile_metadata');
|
|
167
|
-
let workspaceId = '<unknown>';
|
|
168
|
-
let running = 'no';
|
|
169
|
-
if (await fs.pathExists(metadataFile)) {
|
|
170
|
-
const metadata = await fs.readFile(metadataFile, 'utf-8');
|
|
171
|
-
const match = metadata.match(/^workspace_id=(.+)$/m);
|
|
172
|
-
if (match) {
|
|
173
|
-
workspaceId = match[1].trim();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const composeFile = path.join(profileDir, `docker-compose_${profileId}.yaml`);
|
|
177
|
-
if (await fs.pathExists(composeFile)) {
|
|
178
|
-
running = 'yes';
|
|
179
|
-
}
|
|
180
|
-
console.log(`${profileId.padEnd(30)} | ${workspaceId.padEnd(36)} | ${running.padEnd(10)}`);
|
|
181
|
-
}
|
|
182
|
-
if (found === 0) {
|
|
183
|
-
console.log(`(no profiles found in ${workDir})`);
|
|
184
|
-
}
|
|
185
|
-
process.exit(0);
|
|
186
|
-
}
|
|
187
|
-
async handleUpgrade() {
|
|
188
|
-
const scriptUrl = `${this.configService.apiBaseUrl}/script`;
|
|
189
|
-
console.log(`Downloading latest agent from: ${scriptUrl}`);
|
|
190
|
-
console.log('Upgrade functionality to be implemented');
|
|
191
|
-
process.exit(0);
|
|
192
|
-
}
|
|
193
|
-
async handleLog() {
|
|
194
|
-
const logFile = this.configService.logFilePath;
|
|
195
|
-
if (await fs.pathExists(logFile)) {
|
|
196
|
-
console.log(`Following log from ${logFile}:`);
|
|
197
|
-
console.log('Press Ctrl+C to stop.');
|
|
198
|
-
console.log('Log viewing functionality to be implemented');
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
console.log(`No log file found at ${logFile}`);
|
|
202
|
-
console.log('Suggestion: run agent as daemon with: agent --run');
|
|
203
|
-
}
|
|
204
|
-
process.exit(0);
|
|
205
|
-
}
|
|
206
|
-
handleVersion() {
|
|
207
|
-
console.log('DockSplit Agent version 0.1.2');
|
|
208
|
-
process.exit(0);
|
|
209
43
|
}
|
|
210
44
|
async handleWelcome() {
|
|
211
45
|
console.log('DockSplit Agent version 0.1.2');
|
|
@@ -219,7 +53,7 @@ let AgentCommand = AgentCommand_1 = class AgentCommand extends nest_commander_1.
|
|
|
219
53
|
console.log('⚠ API key is required.');
|
|
220
54
|
console.log('');
|
|
221
55
|
console.log('To configure your API key:');
|
|
222
|
-
console.log('
|
|
56
|
+
console.log(' dockernet-agent apikey YOUR_API_KEY');
|
|
223
57
|
process.exit(1);
|
|
224
58
|
}
|
|
225
59
|
const machineKey = config.machineKey || this.machineService.generateMachineKey();
|
|
@@ -238,302 +72,23 @@ let AgentCommand = AgentCommand_1 = class AgentCommand extends nest_commander_1.
|
|
|
238
72
|
console.log('✓ Server: ' + this.configService.serverUrl);
|
|
239
73
|
console.log('');
|
|
240
74
|
console.log('To start the agent daemon, run:');
|
|
241
|
-
console.log(' dockernet-
|
|
75
|
+
console.log(' dockernet-agent run');
|
|
242
76
|
console.log('');
|
|
243
77
|
console.log('For more options, run:');
|
|
244
78
|
console.log(' dockernet-agent --help');
|
|
245
79
|
console.log('');
|
|
246
80
|
process.exit(0);
|
|
247
81
|
}
|
|
248
|
-
async handleStop() {
|
|
249
|
-
const pidFile = this.configService.pidFilePath;
|
|
250
|
-
if (await fs.pathExists(pidFile)) {
|
|
251
|
-
const pid = parseInt(await fs.readFile(pidFile, 'utf-8'), 10);
|
|
252
|
-
if (pid && !isNaN(pid)) {
|
|
253
|
-
try {
|
|
254
|
-
process.kill(pid, 'SIGTERM');
|
|
255
|
-
console.log(`Stopped DockSplit Agent (PID ${pid})`);
|
|
256
|
-
}
|
|
257
|
-
catch (error) {
|
|
258
|
-
console.log(`PID ${pid} is not valid or process is not running`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
await fs.remove(pidFile);
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
console.log(`No PID file found (${pidFile}). Agent may not be running.`);
|
|
265
|
-
}
|
|
266
|
-
process.exit(0);
|
|
267
|
-
}
|
|
268
|
-
async handleRestart() {
|
|
269
|
-
await this.handleStop();
|
|
270
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
271
|
-
await this.runDaemon();
|
|
272
|
-
process.exit(0);
|
|
273
|
-
}
|
|
274
|
-
printUsage() {
|
|
275
|
-
console.log(`
|
|
276
|
-
DockSplit Agent CLI
|
|
277
|
-
|
|
278
|
-
Usage:
|
|
279
|
-
npm run agent : Show welcome message and status
|
|
280
|
-
npm run agent -- --apiKey <API_KEY> : Save/update API key in config
|
|
281
|
-
npm run agent -- --config : Show current config (mask API key)
|
|
282
|
-
npm run agent -- --profiles : List saved profiles on this machine
|
|
283
|
-
npm run agent -- --upgrade : Download latest agent script
|
|
284
|
-
npm run agent -- --log : Show log (if running as daemon)
|
|
285
|
-
npm run agent -- --version : Show agent version
|
|
286
|
-
npm run agent -- --run : Run agent as daemon
|
|
287
|
-
npm run agent -- --stop : Stop running daemon
|
|
288
|
-
npm run agent -- --restart : Restart agent daemon
|
|
289
|
-
|
|
290
|
-
Note: When using npm run agent, use -- before flags (e.g., npm run agent -- --run)
|
|
291
|
-
`);
|
|
292
|
-
process.exit(0);
|
|
293
|
-
}
|
|
294
|
-
async promptForApiKey() {
|
|
295
|
-
const rl = readline.createInterface({
|
|
296
|
-
input: process.stdin,
|
|
297
|
-
output: process.stdout,
|
|
298
|
-
});
|
|
299
|
-
return new Promise((resolve) => {
|
|
300
|
-
rl.question('Please enter your API Key: ', (answer) => {
|
|
301
|
-
rl.close();
|
|
302
|
-
resolve(answer.trim());
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
async runDaemon() {
|
|
307
|
-
if (this.isRunning) {
|
|
308
|
-
this.logger.warn('Agent is already running');
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
this.isRunning = true;
|
|
312
|
-
this.logger.log('Starting DockSplit Agent daemon...');
|
|
313
|
-
try {
|
|
314
|
-
await this.dockerService.checkDependencies();
|
|
315
|
-
}
|
|
316
|
-
catch (error) {
|
|
317
|
-
this.logger.error(`Dependency check failed: ${error.message}`);
|
|
318
|
-
process.exit(1);
|
|
319
|
-
}
|
|
320
|
-
let config = await this.configService.loadConfig();
|
|
321
|
-
if (!config.apiKey) {
|
|
322
|
-
console.log('API key not found in configuration.');
|
|
323
|
-
const apiKey = await this.promptForApiKey();
|
|
324
|
-
if (!apiKey) {
|
|
325
|
-
this.logger.error('API key is required to run the agent.');
|
|
326
|
-
process.exit(1);
|
|
327
|
-
}
|
|
328
|
-
const machineKey = config.machineKey || this.machineService.generateMachineKey();
|
|
329
|
-
await this.configService.saveConfig({
|
|
330
|
-
apiKey,
|
|
331
|
-
machineKey,
|
|
332
|
-
serverUrl: config.serverUrl,
|
|
333
|
-
});
|
|
334
|
-
console.log(`API key saved to ${this.configService.configFilePath}`);
|
|
335
|
-
config = await this.configService.loadConfig();
|
|
336
|
-
}
|
|
337
|
-
await this.apiService.setApiKey(config.apiKey);
|
|
338
|
-
if (!config.machineKey) {
|
|
339
|
-
const machineKey = this.machineService.generateMachineKey();
|
|
340
|
-
await this.configService.saveConfig({
|
|
341
|
-
apiKey: config.apiKey,
|
|
342
|
-
machineKey,
|
|
343
|
-
serverUrl: config.serverUrl,
|
|
344
|
-
});
|
|
345
|
-
this.logger.log(`Generated new machine key: ${machineKey}`);
|
|
346
|
-
}
|
|
347
|
-
const registrationResult = await this.machineService.registerMachine();
|
|
348
|
-
if (registrationResult.nebula_config) {
|
|
349
|
-
try {
|
|
350
|
-
this.logger.log('🌐 Initializing Nebula mesh network...');
|
|
351
|
-
await this.nebulaService.initializeNebula(registrationResult.nebula_config);
|
|
352
|
-
await this.nebulaService.startNebula();
|
|
353
|
-
this.logger.log('✅ Nebula mesh network started');
|
|
354
|
-
}
|
|
355
|
-
catch (error) {
|
|
356
|
-
this.logger.error(`Failed to start Nebula: ${error.message}`);
|
|
357
|
-
this.logger.warn('Continuing without Nebula networking');
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
this.logger.log('Initializing WebSocket connection...');
|
|
361
|
-
try {
|
|
362
|
-
await this.profileService.initializeWebSocket();
|
|
363
|
-
this.logger.log('WebSocket initialization completed');
|
|
364
|
-
}
|
|
365
|
-
catch (error) {
|
|
366
|
-
this.logger.warn(`WebSocket initialization failed: ${error.message}, continuing with polling`);
|
|
367
|
-
}
|
|
368
|
-
this.logger.log('Checking and updating saved profiles status...');
|
|
369
|
-
try {
|
|
370
|
-
await this.profileService.updateAllProfilesStatus();
|
|
371
|
-
this.logger.log('Initial profile status check completed');
|
|
372
|
-
}
|
|
373
|
-
catch (error) {
|
|
374
|
-
this.logger.error(`Error during initial profile status check: ${error.message}`);
|
|
375
|
-
}
|
|
376
|
-
await this.logService.autoStreamLogsForAllContainers();
|
|
377
|
-
await this.eventService.startPolling();
|
|
378
|
-
const statusInterval = setInterval(async () => {
|
|
379
|
-
await this.machineService.updateMachineStatus('live');
|
|
380
|
-
}, 5000);
|
|
381
|
-
const logInterval = setInterval(async () => {
|
|
382
|
-
await this.logService.autoStreamLogsForAllContainers();
|
|
383
|
-
}, 10000);
|
|
384
|
-
let currentNebulaGroups = registrationResult.nebula_config?.groups || [];
|
|
385
|
-
const nebulaConfigInterval = setInterval(async () => {
|
|
386
|
-
try {
|
|
387
|
-
this.logger.log('🔍 Checking for Nebula config changes...');
|
|
388
|
-
const result = await this.machineService.registerMachine();
|
|
389
|
-
if (result.nebula_config) {
|
|
390
|
-
const newGroups = result.nebula_config.groups || [];
|
|
391
|
-
const groupsChanged = newGroups.length !== currentNebulaGroups.length ||
|
|
392
|
-
!newGroups.every((g, i) => g === currentNebulaGroups[i]);
|
|
393
|
-
if (groupsChanged) {
|
|
394
|
-
this.logger.log('🔄 Nebula groups changed! Re-initializing Nebula...');
|
|
395
|
-
this.logger.log(` Old groups: ${currentNebulaGroups.join(', ')}`);
|
|
396
|
-
this.logger.log(` New groups: ${newGroups.join(', ')}`);
|
|
397
|
-
await this.nebulaService.initializeNebula(result.nebula_config);
|
|
398
|
-
await this.nebulaService.restartNebula();
|
|
399
|
-
currentNebulaGroups = newGroups;
|
|
400
|
-
this.logger.log('✅ Nebula restarted with updated workspace groups');
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
this.logger.log(' No changes detected in Nebula groups');
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
catch (error) {
|
|
408
|
-
this.logger.error(`Error checking Nebula config: ${error.message}`);
|
|
409
|
-
}
|
|
410
|
-
}, 300000);
|
|
411
|
-
process.on('SIGTERM', async () => {
|
|
412
|
-
this.logger.log('Received SIGTERM, shutting down...');
|
|
413
|
-
clearInterval(statusInterval);
|
|
414
|
-
clearInterval(logInterval);
|
|
415
|
-
clearInterval(nebulaConfigInterval);
|
|
416
|
-
this.eventService.stopPolling();
|
|
417
|
-
this.websocketClientService.disconnect();
|
|
418
|
-
if (this.nebulaService.isRunning()) {
|
|
419
|
-
await this.nebulaService.stopNebula();
|
|
420
|
-
}
|
|
421
|
-
await this.machineService.updateMachineStatus('exit');
|
|
422
|
-
process.exit(0);
|
|
423
|
-
});
|
|
424
|
-
process.on('SIGINT', async () => {
|
|
425
|
-
this.logger.log('Received SIGINT, shutting down...');
|
|
426
|
-
clearInterval(statusInterval);
|
|
427
|
-
clearInterval(logInterval);
|
|
428
|
-
clearInterval(nebulaConfigInterval);
|
|
429
|
-
this.eventService.stopPolling();
|
|
430
|
-
this.websocketClientService.disconnect();
|
|
431
|
-
if (this.nebulaService.isRunning()) {
|
|
432
|
-
await this.nebulaService.stopNebula();
|
|
433
|
-
}
|
|
434
|
-
await this.machineService.updateMachineStatus('exit');
|
|
435
|
-
process.exit(0);
|
|
436
|
-
});
|
|
437
|
-
this.logger.log('DockSplit Agent daemon is running...');
|
|
438
|
-
}
|
|
439
82
|
};
|
|
440
83
|
exports.AgentCommand = AgentCommand;
|
|
441
|
-
__decorate([
|
|
442
|
-
(0, nest_commander_1.Option)({
|
|
443
|
-
flags: '--apiKey <apiKey>',
|
|
444
|
-
description: 'Save/update API key in config',
|
|
445
|
-
}),
|
|
446
|
-
__metadata("design:type", Function),
|
|
447
|
-
__metadata("design:paramtypes", [String]),
|
|
448
|
-
__metadata("design:returntype", String)
|
|
449
|
-
], AgentCommand.prototype, "parseApiKey", null);
|
|
450
|
-
__decorate([
|
|
451
|
-
(0, nest_commander_1.Option)({
|
|
452
|
-
flags: '--config',
|
|
453
|
-
description: 'Show current config (mask API key)',
|
|
454
|
-
}),
|
|
455
|
-
__metadata("design:type", Function),
|
|
456
|
-
__metadata("design:paramtypes", []),
|
|
457
|
-
__metadata("design:returntype", Boolean)
|
|
458
|
-
], AgentCommand.prototype, "parseConfig", null);
|
|
459
|
-
__decorate([
|
|
460
|
-
(0, nest_commander_1.Option)({
|
|
461
|
-
flags: '--profiles',
|
|
462
|
-
description: 'List saved profiles on this machine',
|
|
463
|
-
}),
|
|
464
|
-
__metadata("design:type", Function),
|
|
465
|
-
__metadata("design:paramtypes", []),
|
|
466
|
-
__metadata("design:returntype", Boolean)
|
|
467
|
-
], AgentCommand.prototype, "parseProfiles", null);
|
|
468
|
-
__decorate([
|
|
469
|
-
(0, nest_commander_1.Option)({
|
|
470
|
-
flags: '--upgrade',
|
|
471
|
-
description: 'Download latest agent script',
|
|
472
|
-
}),
|
|
473
|
-
__metadata("design:type", Function),
|
|
474
|
-
__metadata("design:paramtypes", []),
|
|
475
|
-
__metadata("design:returntype", Boolean)
|
|
476
|
-
], AgentCommand.prototype, "parseUpgrade", null);
|
|
477
|
-
__decorate([
|
|
478
|
-
(0, nest_commander_1.Option)({
|
|
479
|
-
flags: '--log',
|
|
480
|
-
description: 'Show log (if running as daemon)',
|
|
481
|
-
}),
|
|
482
|
-
__metadata("design:type", Function),
|
|
483
|
-
__metadata("design:paramtypes", []),
|
|
484
|
-
__metadata("design:returntype", Boolean)
|
|
485
|
-
], AgentCommand.prototype, "parseLog", null);
|
|
486
|
-
__decorate([
|
|
487
|
-
(0, nest_commander_1.Option)({
|
|
488
|
-
flags: '--version',
|
|
489
|
-
description: 'Show agent version',
|
|
490
|
-
}),
|
|
491
|
-
__metadata("design:type", Function),
|
|
492
|
-
__metadata("design:paramtypes", []),
|
|
493
|
-
__metadata("design:returntype", Boolean)
|
|
494
|
-
], AgentCommand.prototype, "parseVersion", null);
|
|
495
|
-
__decorate([
|
|
496
|
-
(0, nest_commander_1.Option)({
|
|
497
|
-
flags: '--run',
|
|
498
|
-
description: 'Run agent as daemon',
|
|
499
|
-
}),
|
|
500
|
-
__metadata("design:type", Function),
|
|
501
|
-
__metadata("design:paramtypes", []),
|
|
502
|
-
__metadata("design:returntype", Boolean)
|
|
503
|
-
], AgentCommand.prototype, "parseRun", null);
|
|
504
|
-
__decorate([
|
|
505
|
-
(0, nest_commander_1.Option)({
|
|
506
|
-
flags: '--stop',
|
|
507
|
-
description: 'Stop running daemon',
|
|
508
|
-
}),
|
|
509
|
-
__metadata("design:type", Function),
|
|
510
|
-
__metadata("design:paramtypes", []),
|
|
511
|
-
__metadata("design:returntype", Boolean)
|
|
512
|
-
], AgentCommand.prototype, "parseStop", null);
|
|
513
|
-
__decorate([
|
|
514
|
-
(0, nest_commander_1.Option)({
|
|
515
|
-
flags: '--restart',
|
|
516
|
-
description: 'Restart agent daemon',
|
|
517
|
-
}),
|
|
518
|
-
__metadata("design:type", Function),
|
|
519
|
-
__metadata("design:paramtypes", []),
|
|
520
|
-
__metadata("design:returntype", Boolean)
|
|
521
|
-
], AgentCommand.prototype, "parseRestart", null);
|
|
522
|
-
exports.AgentCommand = AgentCommand = AgentCommand_1 = __decorate([
|
|
84
|
+
exports.AgentCommand = AgentCommand = __decorate([
|
|
523
85
|
(0, common_1.Injectable)(),
|
|
524
86
|
(0, nest_commander_1.Command)({
|
|
525
|
-
name: '
|
|
526
|
-
description: 'DockSplit Agent CLI',
|
|
87
|
+
name: '',
|
|
88
|
+
description: 'DockSplit Agent CLI - Show welcome message',
|
|
527
89
|
}),
|
|
528
90
|
__metadata("design:paramtypes", [api_service_1.ApiService,
|
|
529
91
|
config_service_1.ConfigService,
|
|
530
|
-
|
|
531
|
-
event_service_1.EventService,
|
|
532
|
-
log_service_1.LogService,
|
|
533
|
-
machine_service_1.MachineService,
|
|
534
|
-
profile_service_1.ProfileService,
|
|
535
|
-
volume_sync_service_1.VolumeSyncService,
|
|
536
|
-
websocket_client_service_1.WebSocketClientService,
|
|
537
|
-
nebula_service_1.NebulaService])
|
|
92
|
+
machine_service_1.MachineService])
|
|
538
93
|
], AgentCommand);
|
|
539
94
|
//# sourceMappingURL=agent.command.js.map
|