easy-devops 1.3.6 → 1.4.1
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/README.md +1 -0
- package/dist/ui/assets/index-Bu7af-Kj.css +1 -0
- package/dist/ui/assets/index-gndgYe3K.js +532 -0
- package/dist/ui/assets/socket-Bv0wCEgi.js +65 -0
- package/dist/ui/index.html +2 -2
- package/install.bat +14 -7
- package/package.json +2 -2
- package/src/cli/index.js +8 -0
- package/src/cli/managers/domain-manager.js +37 -6
- package/src/cli/managers/nginx-manager.js +14 -5
- package/src/cli/managers/node-manager.js +19 -13
- package/src/cli/managers/ssl-manager.js +89 -26
- package/src/cli/menu.js +8 -2
- package/src/cli/menus/cleanup.js +4 -2
- package/src/cli/menus/dashboard.js +22 -15
- package/src/cli/menus/hub.js +402 -0
- package/src/cli/menus/runtime.js +12 -0
- package/src/cli/menus/service.js +80 -13
- package/src/cli/menus/settings.js +46 -12
- package/src/cli/menus/uninstall.js +13 -5
- package/src/cli/menus/update.js +24 -14
- package/src/cli/ui/page.js +123 -0
- package/src/core/cert-operations.js +34 -4
- package/src/core/cert-reader.js +67 -22
- package/src/core/cert-renewal.js +65 -9
- package/src/core/cert-suggest.js +120 -0
- package/src/core/cleanup.js +221 -1
- package/src/core/cloudflare-ips.js +161 -0
- package/src/core/daemon/ipc.js +1 -1
- package/src/core/daemon/lock.js +296 -9
- package/src/core/daemon/run.js +12 -0
- package/src/core/daemon/stateFile.js +128 -0
- package/src/core/dashboardProcess.js +134 -6
- package/src/core/db.js +26 -1
- package/src/core/deploy/apps.js +36 -62
- package/src/core/deploy/deployKey.js +331 -0
- package/src/core/deploy/domainLink.js +280 -23
- package/src/core/deploy/engine.js +382 -63
- package/src/core/deploy/ezfile.js +496 -29
- package/src/core/deploy/githubApi.js +100 -13
- package/src/core/deploy/hubCommands.js +158 -18
- package/src/core/deploy/status.js +28 -1
- package/src/core/domains-db.js +1 -0
- package/src/core/hub/agent.js +238 -32
- package/src/core/hub/deployProgress.js +411 -0
- package/src/core/hubConnect.js +205 -0
- package/src/core/hubPermissions.js +48 -10
- package/src/core/jobs/bus.js +1 -1
- package/src/core/jobs/owner.js +268 -6
- package/src/core/nginx-conf-generator.js +124 -19
- package/src/core/notifications/claim.js +26 -3
- package/src/core/permissions.js +277 -59
- package/src/core/platform.js +73 -2
- package/src/core/runner.js +96 -40
- package/src/core/service/dataDir.js +34 -9
- package/src/core/service/index.js +203 -24
- package/src/core/service/runtime.js +40 -3
- package/src/core/service/windowsService.js +452 -107
- package/src/core/service/winsw.js +44 -3
- package/src/core/ssl/preflight.js +548 -0
- package/src/core/ssl/progress.js +196 -0
- package/src/core/ssl-issuer.js +502 -148
- package/src/core/validators.js +24 -0
- package/src/dashboard/controllers/authController.js +12 -5
- package/src/dashboard/controllers/deploymentsController.js +76 -11
- package/src/dashboard/controllers/domainsController.js +35 -1
- package/src/dashboard/controllers/hubController.js +4 -3
- package/src/dashboard/controllers/settingsController.js +73 -68
- package/src/dashboard/controllers/sslController.js +135 -15
- package/src/dashboard/public/js/app.js +42 -7
- package/src/dashboard/routes/deployments.js +2 -0
- package/src/dashboard/routes/domains.js +1 -0
- package/src/dashboard/server.js +42 -7
- package/src/dashboard/socketManager.js +19 -25
- package/src/dashboard/views/partials/settings-panel.ejs +29 -10
- package/dist/ui/assets/index-BUpPxWmp.css +0 -1
- package/dist/ui/assets/index-DD0JjK0Q.js +0 -475
- package/dist/ui/assets/socket-4tfdap-e.js +0 -65
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cli/menus/hub.js
|
|
3
|
+
*
|
|
4
|
+
* `ezz hub connect | status | unlink` and the interactive Hub menu.
|
|
5
|
+
*
|
|
6
|
+
* Anything that reaches core/db.js lives here rather than in cli/index.js:
|
|
7
|
+
* index.js is a thin bootstrap that decides the data directory before this
|
|
8
|
+
* module is dynamically imported.
|
|
9
|
+
*
|
|
10
|
+
* The rule this file exists to keep: the connection string, the secret and the
|
|
11
|
+
* one-time token are credentials. Nothing here prints them. The operator sees
|
|
12
|
+
* the Hub's origin and the server id — which identify the pairing without
|
|
13
|
+
* revealing anything that could be used to authenticate.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import chalk from 'chalk';
|
|
17
|
+
import inquirer from 'inquirer';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
CONNECT_ERRORS,
|
|
21
|
+
linkOrigin,
|
|
22
|
+
resolveConnectInput,
|
|
23
|
+
} from '../../core/hubConnect.js';
|
|
24
|
+
import {
|
|
25
|
+
clearHubLink,
|
|
26
|
+
describeRejection,
|
|
27
|
+
getHubLink,
|
|
28
|
+
getLinkStatus,
|
|
29
|
+
parseConnectionString,
|
|
30
|
+
resolveHubOrigin,
|
|
31
|
+
saveConnectionString,
|
|
32
|
+
} from '../../core/hubLink.js';
|
|
33
|
+
import { inspect } from '../../core/daemon/lock.js';
|
|
34
|
+
import { connectToDaemon } from '../../core/daemon/ipc.js';
|
|
35
|
+
import { readAgentStateFromFile } from '../../core/daemon/stateFile.js';
|
|
36
|
+
import { getDataDir } from '../../core/platform.js';
|
|
37
|
+
import { page, pause, BACK } from '../ui/page.js';
|
|
38
|
+
|
|
39
|
+
const ACTIONS = ['connect', 'status', 'unlink'];
|
|
40
|
+
|
|
41
|
+
/** How long `connect` waits for the agent to report its first real outcome. */
|
|
42
|
+
const CONNECT_WAIT_MS = 30_000;
|
|
43
|
+
/** A status read must not make an ordinary command feel hung. */
|
|
44
|
+
const STATUS_WAIT_MS = 2_500;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A test-only override for the link fetch timeout. Honoured only under
|
|
48
|
+
* EZ_TEST=1, so a normal installation cannot change how long a pairing request
|
|
49
|
+
* may take by setting an environment variable.
|
|
50
|
+
*/
|
|
51
|
+
const TEST_TIMEOUT_ENV = 'EZ_HUB_CONNECT_TIMEOUT_MS';
|
|
52
|
+
|
|
53
|
+
function connectDeps() {
|
|
54
|
+
if (process.env.EZ_TEST !== '1') return {};
|
|
55
|
+
const ms = Number(process.env[TEST_TIMEOUT_ENV]);
|
|
56
|
+
return Number.isFinite(ms) && ms > 0 ? { timeoutMs: ms } : {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isInteractive() {
|
|
60
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The Hub's origin, never a path or token. */
|
|
64
|
+
function displayOrigin(hubUrl) {
|
|
65
|
+
const resolved = resolveHubOrigin(hubUrl);
|
|
66
|
+
return linkOrigin(resolved) ?? resolved;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function say(line = '') {
|
|
70
|
+
process.stdout.write(`${line}\n`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Waits, with a bound, for the daemon to tell us the agent's state.
|
|
75
|
+
*
|
|
76
|
+
* The daemon already publishes `hub:agentState` on the job bus and forwards its
|
|
77
|
+
* frames over IPC (server → client only). Its hello frame carries the state at
|
|
78
|
+
* connect time, so a CLI that starts after the agent connected still sees it.
|
|
79
|
+
*
|
|
80
|
+
* In Windows Server mode the pipe belongs to NT SERVICE\EasyDevOps and the CLI
|
|
81
|
+
* cannot open it, so the same state is also read from the file the running
|
|
82
|
+
* daemon keeps in the data directory (core/daemon/stateFile.js) — trusted only
|
|
83
|
+
* while its pid holds the live daemon lock. Whichever answers first wins.
|
|
84
|
+
*
|
|
85
|
+
* @param {Object} opts
|
|
86
|
+
* @param {number} opts.timeoutMs
|
|
87
|
+
* @param {(state: Object|null) => boolean} [opts.until]
|
|
88
|
+
* @returns {Promise<{ state: Object|null, timedOut: boolean }>}
|
|
89
|
+
*/
|
|
90
|
+
function waitForAgentState({ timeoutMs, until = () => false }) {
|
|
91
|
+
return new Promise((resolve) => {
|
|
92
|
+
let latest = null;
|
|
93
|
+
let finished = false;
|
|
94
|
+
let client = null;
|
|
95
|
+
|
|
96
|
+
const dataDir = getDataDir();
|
|
97
|
+
let filePoll = null;
|
|
98
|
+
|
|
99
|
+
const finish = (timedOut) => {
|
|
100
|
+
if (finished) return;
|
|
101
|
+
finished = true;
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
clearInterval(filePoll);
|
|
104
|
+
try { client?.close(); } catch { /* already closed */ }
|
|
105
|
+
resolve({ state: latest, timedOut });
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const timer = setTimeout(() => finish(true), timeoutMs);
|
|
109
|
+
|
|
110
|
+
const fromFile = () => {
|
|
111
|
+
if (finished) return;
|
|
112
|
+
const state = readAgentStateFromFile({ dataDir });
|
|
113
|
+
if (!state) return;
|
|
114
|
+
latest = state;
|
|
115
|
+
if (until(latest)) finish(false);
|
|
116
|
+
};
|
|
117
|
+
fromFile();
|
|
118
|
+
filePoll = setInterval(fromFile, 500);
|
|
119
|
+
|
|
120
|
+
client = connectToDaemon({
|
|
121
|
+
onEvent(event, payload) {
|
|
122
|
+
if (finished) return;
|
|
123
|
+
if (event === 'daemon:hello') latest = payload?.hub ?? null;
|
|
124
|
+
else if (event === 'hub:agentState') latest = payload;
|
|
125
|
+
|
|
126
|
+
if (until(latest)) finish(false);
|
|
127
|
+
},
|
|
128
|
+
// Connecting is not yet state: the hello frame is what carries it.
|
|
129
|
+
onStatus() {},
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function printFailure(failure) {
|
|
135
|
+
// hubConnect.js's messages never contain the token or connection string.
|
|
136
|
+
say(chalk.red(failure.error));
|
|
137
|
+
if (failure.code === CONNECT_ERRORS.REVOKED) {
|
|
138
|
+
say(chalk.gray('A revoked link means the server was deleted on the Hub, or its secret changed.'));
|
|
139
|
+
}
|
|
140
|
+
if (failure.retryAfterSeconds) {
|
|
141
|
+
say(chalk.gray(`The Hub asked to wait ${failure.retryAfterSeconds}s before trying again.`));
|
|
142
|
+
}
|
|
143
|
+
return 1;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Reports the agent's state after a pairing was saved. Never prints a secret;
|
|
148
|
+
* the only identifiers are the Hub origin and the server id.
|
|
149
|
+
*/
|
|
150
|
+
async function reportConnection(origin, serverId) {
|
|
151
|
+
say(`Linked to ${chalk.bold(origin)}.`);
|
|
152
|
+
say(` Server: ${serverId}`);
|
|
153
|
+
|
|
154
|
+
const daemon = inspect();
|
|
155
|
+
if (!daemon.running) {
|
|
156
|
+
say(chalk.yellow('The background service is not running, so the server is not connected yet — ')
|
|
157
|
+
+ 'run ' + chalk.bold('`ezz service start`') + ' (or open the dashboard).');
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
say(chalk.gray('Waiting for the background service to report the agent…'));
|
|
162
|
+
const { state, timedOut } = await waitForAgentState({
|
|
163
|
+
timeoutMs: CONNECT_WAIT_MS,
|
|
164
|
+
until: (s) => s?.status === 'connected' || s?.status === 'rejected',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
if (!state) {
|
|
168
|
+
say(chalk.yellow(`The background service is running but did not report the agent's state `
|
|
169
|
+
+ `within ${Math.round(CONNECT_WAIT_MS / 1000)}s.`));
|
|
170
|
+
say(chalk.gray('Check it with `ezz hub status`.'));
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (state.status === 'connected') {
|
|
175
|
+
say(chalk.green(`Connected to ${origin}.`));
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (state.status === 'rejected') {
|
|
180
|
+
say(chalk.red('The Hub rejected this pairing.'));
|
|
181
|
+
say(' ' + (state.lastError || describeRejection('INVALID_SECRET')));
|
|
182
|
+
say(chalk.gray('Create a new link in the Hub and run the new command.'));
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (state.status === 'unreachable') {
|
|
187
|
+
say(chalk.yellow(`Saved, but the server cannot reach ${origin} yet.`));
|
|
188
|
+
if (state.lastError) say(' ' + state.lastError);
|
|
189
|
+
say(chalk.gray('It keeps retrying in the background.'));
|
|
190
|
+
return 0;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Still connecting, or the daemon answered with a state this CLI does not
|
|
194
|
+
// recognise. Both are "not connected yet", which is the honest answer.
|
|
195
|
+
say(chalk.yellow(timedOut
|
|
196
|
+
? `Still connecting to ${origin} after ${Math.round(CONNECT_WAIT_MS / 1000)}s.`
|
|
197
|
+
: `Saved. The agent is ${state.status ?? 'not reported'} — it will keep trying in the background.`));
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function connect(target, { yes = false } = {}) {
|
|
202
|
+
if (!target) {
|
|
203
|
+
say(chalk.red('Missing pairing link.'));
|
|
204
|
+
say(' ezz hub connect <link-or-ezops-string> [--yes]');
|
|
205
|
+
return 1;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let resolved;
|
|
209
|
+
try {
|
|
210
|
+
resolved = await resolveConnectInput(target, connectDeps());
|
|
211
|
+
} catch {
|
|
212
|
+
// resolveConnectInput() returns failures rather than throwing; this is a
|
|
213
|
+
// belt-and-braces guard that still says nothing about the input.
|
|
214
|
+
say(chalk.red('Could not read the pairing link or connection string.'));
|
|
215
|
+
return 1;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!resolved.ok) return printFailure(resolved);
|
|
219
|
+
|
|
220
|
+
const parsed = parseConnectionString(resolved.connectionString);
|
|
221
|
+
if (!parsed.ok) {
|
|
222
|
+
say(chalk.red(parsed.error));
|
|
223
|
+
return 1;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const next = parsed.link;
|
|
227
|
+
const nextOrigin = displayOrigin(next.hubUrl);
|
|
228
|
+
|
|
229
|
+
const current = getHubLink();
|
|
230
|
+
if (current) {
|
|
231
|
+
const sameHub = resolveHubOrigin(current.hubUrl) === resolveHubOrigin(next.hubUrl);
|
|
232
|
+
const sameServer = current.serverId === next.serverId;
|
|
233
|
+
if (!sameHub || !sameServer) {
|
|
234
|
+
const currentOrigin = displayOrigin(current.hubUrl);
|
|
235
|
+
|
|
236
|
+
if (!yes && !isInteractive()) {
|
|
237
|
+
say(chalk.yellow(`This server is already linked to ${currentOrigin} as server ${current.serverId}.`));
|
|
238
|
+
say('Run the same command with ' + chalk.bold('--yes') + ' to replace that link.');
|
|
239
|
+
return 1;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!yes) {
|
|
243
|
+
const { replace } = await inquirer.prompt([{
|
|
244
|
+
type: 'confirm',
|
|
245
|
+
name: 'replace',
|
|
246
|
+
message: `Replace the existing link to ${currentOrigin} (server ${current.serverId})?`,
|
|
247
|
+
default: false,
|
|
248
|
+
}]);
|
|
249
|
+
if (!replace) {
|
|
250
|
+
say('Nothing was changed.');
|
|
251
|
+
return 0;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const saved = saveConnectionString(resolved.connectionString);
|
|
258
|
+
if (!saved.ok) {
|
|
259
|
+
say(chalk.red(saved.error));
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return reportConnection(nextOrigin, next.serverId);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async function status() {
|
|
267
|
+
const link = getLinkStatus();
|
|
268
|
+
|
|
269
|
+
say(chalk.bold('Hub pairing'));
|
|
270
|
+
if (!link.linked) {
|
|
271
|
+
say(' Not linked.');
|
|
272
|
+
say(chalk.gray('Pair with: ') + 'ezz hub connect <link-or-ezops-string>');
|
|
273
|
+
return 0;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const origin = displayOrigin(link.hubUrl);
|
|
277
|
+
const enabled = Object.entries(link.permissions ?? {})
|
|
278
|
+
.filter(([, value]) => value === true)
|
|
279
|
+
.map(([id]) => id);
|
|
280
|
+
|
|
281
|
+
say(` Hub : ${origin}`);
|
|
282
|
+
say(` Server : ${link.serverId}`);
|
|
283
|
+
say(` Permissions: ${enabled.length ? `${enabled.length} granted — ${enabled.join(', ')}` : 'none granted'}`);
|
|
284
|
+
|
|
285
|
+
const daemon = inspect();
|
|
286
|
+
if (!daemon.running) {
|
|
287
|
+
say(' Agent : the background service is not running, so the server is not connected');
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const { state } = await waitForAgentState({
|
|
292
|
+
timeoutMs: STATUS_WAIT_MS,
|
|
293
|
+
until: (s) => Boolean(s),
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
if (!state) {
|
|
297
|
+
say(' Agent : not reported by the background service yet');
|
|
298
|
+
return 0;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const suffix = state.lastError ? ` — ${state.lastError}` : '';
|
|
302
|
+
say(` Agent : ${state.status ?? 'unknown'}${suffix}`);
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async function unlink({ yes = false } = {}) {
|
|
307
|
+
const link = getLinkStatus();
|
|
308
|
+
if (!link.linked) {
|
|
309
|
+
say('Not linked to a Hub.');
|
|
310
|
+
return 0;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const origin = displayOrigin(link.hubUrl);
|
|
314
|
+
|
|
315
|
+
if (!yes) {
|
|
316
|
+
if (!isInteractive()) {
|
|
317
|
+
say(chalk.yellow(`This server is linked to ${origin}.`));
|
|
318
|
+
say('Run ' + chalk.bold('ezz hub unlink --yes') + ' to remove the link.');
|
|
319
|
+
return 1;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const { confirm } = await inquirer.prompt([{
|
|
323
|
+
type: 'confirm',
|
|
324
|
+
name: 'confirm',
|
|
325
|
+
message: `Unlink this server from ${origin}?`,
|
|
326
|
+
default: false,
|
|
327
|
+
}]);
|
|
328
|
+
if (!confirm) {
|
|
329
|
+
say('Nothing was changed.');
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
clearHubLink();
|
|
335
|
+
say(`Unlinked from ${origin}.`);
|
|
336
|
+
say(chalk.gray('The server stays listed in the Hub as offline until you delete it there.'));
|
|
337
|
+
return 0;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @param {string} [action]
|
|
342
|
+
* @param {string[]} [args] Positional arguments after the action
|
|
343
|
+
* @param {{ yes?: boolean }} [opts]
|
|
344
|
+
* @returns {Promise<number>} Process exit code
|
|
345
|
+
*/
|
|
346
|
+
export async function hubCommand(action = 'status', args = [], { yes = false } = {}) {
|
|
347
|
+
if (!ACTIONS.includes(action)) {
|
|
348
|
+
process.stderr.write(
|
|
349
|
+
`Unknown hub action: ${action}\n` +
|
|
350
|
+
`Available: ${ACTIONS.join(', ')}\n`,
|
|
351
|
+
);
|
|
352
|
+
return 1;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (action === 'connect') return connect(args[0], { yes });
|
|
356
|
+
if (action === 'status') return status();
|
|
357
|
+
return unlink({ yes });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** The interactive Hub menu. */
|
|
361
|
+
export async function hubMenu() {
|
|
362
|
+
page(['Hub']);
|
|
363
|
+
|
|
364
|
+
const { choice } = await inquirer.prompt([{
|
|
365
|
+
type: 'list',
|
|
366
|
+
name: 'choice',
|
|
367
|
+
message: 'Hub:',
|
|
368
|
+
choices: ['Connect / re-pair', 'Status', 'Unlink', new inquirer.Separator(), BACK],
|
|
369
|
+
}]);
|
|
370
|
+
|
|
371
|
+
if (choice === BACK) return;
|
|
372
|
+
|
|
373
|
+
if (choice === 'Status') {
|
|
374
|
+
page(['Hub', 'Status']);
|
|
375
|
+
await status();
|
|
376
|
+
await pause();
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (choice === 'Unlink') {
|
|
381
|
+
page(['Hub', 'Unlink']);
|
|
382
|
+
await unlink({ yes: false });
|
|
383
|
+
await pause();
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
page(['Hub', 'Connect']);
|
|
388
|
+
const { target } = await inquirer.prompt([{
|
|
389
|
+
type: 'password',
|
|
390
|
+
name: 'target',
|
|
391
|
+
mask: '*',
|
|
392
|
+
message: 'Paste the pairing link or ezops:// connection string:',
|
|
393
|
+
}]);
|
|
394
|
+
|
|
395
|
+
await connect(target, { yes: false });
|
|
396
|
+
await pause();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Every other file in menus/ is imported as a default by cli/menu.js. This
|
|
400
|
+
// file's primary export is the non-interactive command, so the interactive
|
|
401
|
+
// menu is exported as the default as well.
|
|
402
|
+
export default hubMenu;
|
package/src/cli/menus/runtime.js
CHANGED
|
@@ -19,6 +19,7 @@ import ora from 'ora';
|
|
|
19
19
|
import { isWindows } from '../../core/platform.js';
|
|
20
20
|
import * as runtimeUpdate from '../../core/service/runtimeUpdate.js';
|
|
21
21
|
import * as service from '../../core/service/index.js';
|
|
22
|
+
import { page, pause } from '../ui/page.js';
|
|
22
23
|
|
|
23
24
|
const ACTIONS = ['status', 'update'];
|
|
24
25
|
|
|
@@ -128,6 +129,17 @@ async function showStatus() {
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
async function doUpdate({ yes = false } = {}) {
|
|
132
|
+
// `ezz runtime status` stays a plain command page: it is read-only output
|
|
133
|
+
// that people pipe. Moving the runtime is an operation, so it gets a page of
|
|
134
|
+
// its own and its outcome is held until Enter (a no-op without a TTY).
|
|
135
|
+
page(['Runtime', 'Update']);
|
|
136
|
+
|
|
137
|
+
const code = await runUpdate({ yes });
|
|
138
|
+
await pause();
|
|
139
|
+
return code;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function runUpdate({ yes = false } = {}) {
|
|
131
143
|
const targets = await loadAndPrint();
|
|
132
144
|
|
|
133
145
|
// Nothing is installed to update: say so rather than offering to re-pin a
|
package/src/cli/menus/service.js
CHANGED
|
@@ -20,9 +20,17 @@ import ora from 'ora';
|
|
|
20
20
|
import { isWindows, isDevDataDir, getDataDir } from '../../core/platform.js';
|
|
21
21
|
import * as service from '../../core/service/index.js';
|
|
22
22
|
import { describeLegacy } from '../../core/service/legacy.js';
|
|
23
|
+
import { page, pause } from '../ui/page.js';
|
|
23
24
|
|
|
24
25
|
const ACTIONS = ['install', 'uninstall', 'status', 'start', 'stop', 'restart', 'logs', 'repair'];
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Actions that change something, as opposed to read-only ones (`status`,
|
|
29
|
+
* `logs`). Only these get a page heading and hold their result until Enter;
|
|
30
|
+
* the read-only pair must stay pipeable, so it does neither.
|
|
31
|
+
*/
|
|
32
|
+
const MUTATING_ACTIONS = new Set(['install', 'uninstall', 'start', 'stop', 'restart', 'repair']);
|
|
33
|
+
|
|
26
34
|
/**
|
|
27
35
|
* Entry point for the `service` command.
|
|
28
36
|
* @param {string} action
|
|
@@ -37,17 +45,21 @@ export async function serviceCommand(action) {
|
|
|
37
45
|
return 1;
|
|
38
46
|
}
|
|
39
47
|
|
|
48
|
+
let code;
|
|
40
49
|
switch (action) {
|
|
41
|
-
case 'status':
|
|
42
|
-
case 'install':
|
|
43
|
-
case 'uninstall':
|
|
44
|
-
case 'start':
|
|
45
|
-
case 'stop':
|
|
46
|
-
case 'restart':
|
|
47
|
-
case 'logs':
|
|
48
|
-
case 'repair':
|
|
49
|
-
default:
|
|
50
|
-
}
|
|
50
|
+
case 'status': code = await showStatus(); break;
|
|
51
|
+
case 'install': code = await doInstall(); break;
|
|
52
|
+
case 'uninstall': code = await doUninstall(); break;
|
|
53
|
+
case 'start': code = await doStart(); break;
|
|
54
|
+
case 'stop': code = await doStop(); break;
|
|
55
|
+
case 'restart': code = await doRestart(); break;
|
|
56
|
+
case 'logs': code = await showLogs(); break;
|
|
57
|
+
case 'repair': code = await doRepair(); break;
|
|
58
|
+
default: code = 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (MUTATING_ACTIONS.has(action)) await pause();
|
|
62
|
+
return code;
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
// ─── Shared rendering ─────────────────────────────────────────────────────────
|
|
@@ -160,8 +172,16 @@ export async function showStatus() {
|
|
|
160
172
|
const daemonDot = d.running ? dot(true) : s.stoppedByUser ? chalk.yellow('●') : dot(false);
|
|
161
173
|
console.log(` Daemon ${daemonDot} ${daemonLine}`);
|
|
162
174
|
|
|
175
|
+
// Clean restarts (a stop, restart, update or repair) and crash restarts are
|
|
176
|
+
// told apart: only the second kind is a problem, and only it can make a
|
|
177
|
+
// crash loop.
|
|
163
178
|
if (s.service.restarts) {
|
|
164
|
-
|
|
179
|
+
const crashes = s.service.crashRestarts ?? 0;
|
|
180
|
+
const clean = s.service.cleanRestarts ?? (s.service.restarts - crashes);
|
|
181
|
+
const parts = [];
|
|
182
|
+
if (clean) parts.push(`${clean} clean (stop/restart)`);
|
|
183
|
+
if (crashes) parts.push(s.service.crashLooping ? chalk.red(`${crashes} after a crash`) : `${crashes} after a crash`);
|
|
184
|
+
console.log(` Restarts ${parts.join(', ')} ${chalk.gray('in the last 10 min')}`);
|
|
165
185
|
}
|
|
166
186
|
|
|
167
187
|
console.log(` Data directory ${chalk.gray(s.dataDir)}${s.serverMode ? chalk.gray(' (server mode)') : ''}`);
|
|
@@ -206,6 +226,7 @@ function describeBoot(enabled) {
|
|
|
206
226
|
// ─── install ──────────────────────────────────────────────────────────────────
|
|
207
227
|
|
|
208
228
|
async function doInstall() {
|
|
229
|
+
page(['Service', 'Install']);
|
|
209
230
|
console.log();
|
|
210
231
|
console.log(' ' + chalk.bold('Install the Easy DevOps background service'));
|
|
211
232
|
console.log(' ' + chalk.gray('─'.repeat(58)));
|
|
@@ -239,7 +260,30 @@ async function doInstall() {
|
|
|
239
260
|
message: 'Install in Server mode?',
|
|
240
261
|
default: true,
|
|
241
262
|
}]);
|
|
242
|
-
|
|
263
|
+
if (confirmServer) {
|
|
264
|
+
mode = service.MODES.SERVER;
|
|
265
|
+
} else {
|
|
266
|
+
// Allowed, but not without saying what it costs on a server: Personal
|
|
267
|
+
// mode is tied to this user's logon session.
|
|
268
|
+
console.log();
|
|
269
|
+
console.log(' ' + chalk.yellow('Personal mode instead:'));
|
|
270
|
+
console.log(' ' + chalk.gray('• It only runs while this user is logged in.'));
|
|
271
|
+
console.log(' ' + chalk.gray('• Signing out of RDP stops it; disconnecting the RDP window keeps it running.'));
|
|
272
|
+
console.log(' ' + chalk.gray('• It does not start at boot before someone logs in.'));
|
|
273
|
+
console.log();
|
|
274
|
+
|
|
275
|
+
const { confirmPersonal } = await inquirer.prompt([{
|
|
276
|
+
type: 'confirm',
|
|
277
|
+
name: 'confirmPersonal',
|
|
278
|
+
message: 'Install in Personal mode?',
|
|
279
|
+
default: true,
|
|
280
|
+
}]);
|
|
281
|
+
if (!confirmPersonal) {
|
|
282
|
+
console.log(' ' + chalk.gray('Nothing was changed.'));
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
mode = service.MODES.PERSONAL;
|
|
286
|
+
}
|
|
243
287
|
} else {
|
|
244
288
|
const { chosen } = await inquirer.prompt([{
|
|
245
289
|
type: 'list',
|
|
@@ -338,6 +382,8 @@ async function doInstall() {
|
|
|
338
382
|
console.log(' ' + chalk.gray('No password is needed — only elevation.'));
|
|
339
383
|
}
|
|
340
384
|
console.log();
|
|
385
|
+
console.log(' ' + chalk.gray('Troubleshooting: https://easy-devops.devxor.team/docs/troubleshooting'));
|
|
386
|
+
console.log();
|
|
341
387
|
return 1;
|
|
342
388
|
}
|
|
343
389
|
|
|
@@ -346,7 +392,8 @@ async function doInstall() {
|
|
|
346
392
|
|
|
347
393
|
if (result.migrated) {
|
|
348
394
|
console.log(' ' + chalk.gray(`Data moved to ${result.dataDir}`));
|
|
349
|
-
|
|
395
|
+
const original = service.describeOriginal(result);
|
|
396
|
+
console.log(' ' + chalk.gray(`${original[0].toUpperCase()}${original.slice(1)}.`));
|
|
350
397
|
}
|
|
351
398
|
|
|
352
399
|
if (result.legacy?.removed?.length) {
|
|
@@ -380,6 +427,17 @@ async function doInstall() {
|
|
|
380
427
|
console.log(' ' + chalk.gray(`Daemon reported in after ${Math.round(result.daemon.waitedMs / 1000)}s (pid ${result.daemon.pid})`));
|
|
381
428
|
}
|
|
382
429
|
|
|
430
|
+
// Out of waiting time while Windows reports the service RUNNING: installed,
|
|
431
|
+
// just slow to initialise on its first start. Not a failure, so the status
|
|
432
|
+
// table (which would show the daemon as not yet running) is not printed.
|
|
433
|
+
if (result.stillInitialising) {
|
|
434
|
+
console.log(' ' + chalk.yellow('Started, still initialising.'));
|
|
435
|
+
console.log(' ' + chalk.gray('The first start can be slow while Windows scans the new runtime.'));
|
|
436
|
+
console.log(' ' + chalk.gray('Check with ') + chalk.white('ezz service status') + chalk.gray(' in a minute.'));
|
|
437
|
+
console.log();
|
|
438
|
+
return 0;
|
|
439
|
+
}
|
|
440
|
+
|
|
383
441
|
console.log();
|
|
384
442
|
return showStatus();
|
|
385
443
|
}
|
|
@@ -421,6 +479,7 @@ async function offerToStart() {
|
|
|
421
479
|
// ─── uninstall ────────────────────────────────────────────────────────────────
|
|
422
480
|
|
|
423
481
|
async function doUninstall() {
|
|
482
|
+
page(['Service', 'Uninstall']);
|
|
424
483
|
const current = await service.status().catch(() => null);
|
|
425
484
|
|
|
426
485
|
console.log();
|
|
@@ -587,6 +646,7 @@ async function doUninstall() {
|
|
|
587
646
|
// ─── stop / start ─────────────────────────────────────────────────────────────
|
|
588
647
|
|
|
589
648
|
async function doStop() {
|
|
649
|
+
page(['Service', 'Stop']);
|
|
590
650
|
const spinner = ora('Stopping the background service…').start();
|
|
591
651
|
const lines = [];
|
|
592
652
|
|
|
@@ -626,6 +686,7 @@ async function doStop() {
|
|
|
626
686
|
}
|
|
627
687
|
|
|
628
688
|
async function doStart() {
|
|
689
|
+
page(['Service', 'Start']);
|
|
629
690
|
const spinner = ora('Starting the background service…').start();
|
|
630
691
|
const lines = [];
|
|
631
692
|
|
|
@@ -655,6 +716,8 @@ async function doStart() {
|
|
|
655
716
|
console.log(' ' + chalk.gray('No password is needed — only elevation.'));
|
|
656
717
|
}
|
|
657
718
|
console.log();
|
|
719
|
+
console.log(' ' + chalk.gray('Troubleshooting: https://easy-devops.devxor.team/docs/troubleshooting'));
|
|
720
|
+
console.log();
|
|
658
721
|
return 1;
|
|
659
722
|
}
|
|
660
723
|
|
|
@@ -667,6 +730,7 @@ async function doStart() {
|
|
|
667
730
|
// ─── restart ──────────────────────────────────────────────────────────────────
|
|
668
731
|
|
|
669
732
|
async function doRestart() {
|
|
733
|
+
page(['Service', 'Restart']);
|
|
670
734
|
const spinner = ora('Restarting the service…').start();
|
|
671
735
|
|
|
672
736
|
let result;
|
|
@@ -722,6 +786,7 @@ async function showLogs() {
|
|
|
722
786
|
// ─── repair ───────────────────────────────────────────────────────────────────
|
|
723
787
|
|
|
724
788
|
async function doRepair() {
|
|
789
|
+
page(['Service', 'Repair']);
|
|
725
790
|
console.log();
|
|
726
791
|
console.log(' ' + chalk.bold('Repair the Easy DevOps service'));
|
|
727
792
|
console.log(' ' + chalk.gray('─'.repeat(58)));
|
|
@@ -751,6 +816,8 @@ async function doRepair() {
|
|
|
751
816
|
console.log(' ' + chalk.gray('No password is needed — only elevation.'));
|
|
752
817
|
}
|
|
753
818
|
console.log();
|
|
819
|
+
console.log(' ' + chalk.gray('Troubleshooting: https://easy-devops.devxor.team/docs/troubleshooting'));
|
|
820
|
+
console.log();
|
|
754
821
|
return 1;
|
|
755
822
|
}
|
|
756
823
|
|