easy-devops 1.2.0 → 1.3.0
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 +97 -6
- package/dist/ui/assets/index-B6zdwEnG.css +1 -0
- package/dist/ui/assets/index-Cy0oNmul.js +442 -0
- package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
- package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
- package/dist/ui/brand/apple-touch-icon.png +0 -0
- package/dist/ui/brand/favicon-16.png +0 -0
- package/dist/ui/brand/favicon-32.png +0 -0
- package/dist/ui/brand/favicon-light-16.png +0 -0
- package/dist/ui/brand/favicon-light-32.png +0 -0
- package/dist/ui/brand/favicon.ico +0 -0
- package/dist/ui/brand/icon-192.png +0 -0
- package/dist/ui/brand/icon-48.png +0 -0
- package/dist/ui/brand/icon-512.png +0 -0
- package/dist/ui/brand/icon-64-light.png +0 -0
- package/dist/ui/brand/icon-64.png +0 -0
- package/dist/ui/brand/logo-dark.png +0 -0
- package/dist/ui/brand/logo-light.png +0 -0
- package/dist/ui/brand/mark-dark.png +0 -0
- package/dist/ui/brand/mark-light.png +0 -0
- package/dist/ui/index.html +71 -0
- package/install.ps1 +188 -1
- package/install.sh +254 -29
- package/package.json +17 -5
- package/src/cli/dash.js +110 -0
- package/src/cli/index.js +237 -106
- package/src/cli/managers/domain-manager.js +60 -40
- package/src/cli/managers/ssl-manager.js +47 -330
- package/src/cli/menu.js +156 -0
- package/src/cli/menus/cleanup.js +205 -0
- package/src/cli/menus/dashboard.js +93 -2
- package/src/cli/menus/runtime.js +236 -0
- package/src/cli/menus/service.js +764 -0
- package/src/cli/menus/settings.js +176 -8
- package/src/cli/menus/uninstall.js +167 -0
- package/src/cli/menus/update.js +221 -65
- package/src/core/acme-challenge.js +273 -0
- package/src/core/cert-operations.js +189 -0
- package/src/{dashboard/lib → core}/cert-reader.js +2 -2
- package/src/core/cert-renewal.js +494 -0
- package/src/core/channels/discord.js +77 -0
- package/src/core/channels/telegram.js +120 -0
- package/src/core/cleanup.js +600 -0
- package/src/core/config.js +169 -2
- package/src/core/daemon/ipc.js +292 -0
- package/src/core/daemon/lock.js +294 -0
- package/src/core/daemon/run.js +241 -0
- package/src/core/daemon/stopRequest.js +162 -0
- package/src/core/db.js +44 -8
- package/src/core/deploy/apps.js +491 -0
- package/src/core/deploy/domainLink.js +200 -0
- package/src/core/deploy/engine.js +973 -0
- package/src/core/deploy/ezfile.js +361 -0
- package/src/core/deploy/github.js +239 -0
- package/src/core/deploy/githubApi.js +261 -0
- package/src/core/deploy/hookServer.js +325 -0
- package/src/core/deploy/hubCommands.js +267 -0
- package/src/core/deploy/launcher.js +57 -0
- package/src/core/deploy/status.js +91 -0
- package/src/core/deploy/store.js +398 -0
- package/src/core/domainNotifier.js +364 -0
- package/src/core/domains-db.js +234 -0
- package/src/core/events.js +222 -0
- package/src/core/hub/agent.js +842 -0
- package/src/core/hubLink.js +306 -0
- package/src/core/hubPermissions.js +430 -0
- package/src/core/installSource.js +162 -0
- package/src/core/jobs/bus.js +120 -0
- package/src/core/jobs/index.js +371 -0
- package/src/core/jobs/monitors.js +368 -0
- package/src/core/jobs/owner.js +217 -0
- package/src/core/jobs/revisionWatcher.js +106 -0
- package/src/core/nginx-apply.js +213 -0
- package/src/core/nginx-conf-generator.js +253 -17
- package/src/{dashboard/lib → core}/nginx-service.js +18 -9
- package/src/core/notifications/claim.js +214 -0
- package/src/core/notifications/dispatch.js +154 -0
- package/src/core/notifier.js +103 -0
- package/src/core/passwords.js +172 -0
- package/src/core/permissions.js +8 -4
- package/src/core/platform.js +709 -2
- package/src/core/probeCache.js +258 -0
- package/src/core/purge.js +372 -0
- package/src/core/runner.js +488 -0
- package/src/core/service/acl.js +226 -0
- package/src/core/service/dataDir.js +345 -0
- package/src/core/service/index.js +1128 -0
- package/src/core/service/legacy.js +218 -0
- package/src/core/service/runtime.js +446 -0
- package/src/core/service/runtimeUpdate.js +800 -0
- package/src/core/service/systemd.js +458 -0
- package/src/core/service/windowsPersonal.js +530 -0
- package/src/core/service/windowsService.js +576 -0
- package/src/core/service/winsw.js +260 -0
- package/src/core/setupCode.js +331 -0
- package/src/core/shell.js +128 -13
- package/src/core/ssl-issuer.js +627 -0
- package/src/core/updater.js +295 -0
- package/src/core/validators.js +99 -0
- package/src/dashboard/controllers/authController.js +316 -0
- package/src/dashboard/controllers/deploymentsController.js +479 -0
- package/src/dashboard/controllers/domainsController.js +403 -0
- package/src/dashboard/controllers/hubController.js +135 -0
- package/src/dashboard/controllers/nginxController.js +146 -0
- package/src/dashboard/controllers/processesController.js +368 -0
- package/src/dashboard/controllers/settingsController.js +503 -0
- package/src/dashboard/controllers/sslController.js +452 -0
- package/src/dashboard/lib/daemonBridge.js +163 -0
- package/src/dashboard/lib/localRequest.js +235 -0
- package/src/dashboard/lib/loginRateLimit.js +119 -0
- package/src/dashboard/lib/requireAuth.js +80 -0
- package/src/dashboard/public/img/icon.png +0 -0
- package/src/dashboard/public/img/icon_b.png +0 -0
- package/src/dashboard/public/js/app.js +595 -19
- package/src/dashboard/routes/auth.js +14 -33
- package/src/dashboard/routes/deployments.js +46 -0
- package/src/dashboard/routes/domains.js +20 -363
- package/src/dashboard/routes/hub.js +22 -0
- package/src/dashboard/routes/nginx.js +22 -146
- package/src/dashboard/routes/processes.js +29 -0
- package/src/dashboard/routes/settings.js +25 -232
- package/src/dashboard/routes/ssl.js +18 -276
- package/src/dashboard/server.js +279 -165
- package/src/dashboard/socketManager.js +246 -0
- package/src/dashboard/views/index.ejs +1 -0
- package/src/dashboard/views/partials/domain-form.ejs +64 -1
- package/src/dashboard/views/partials/login.ejs +69 -8
- package/src/dashboard/views/partials/processes-panel.ejs +261 -0
- package/src/dashboard/views/partials/settings-panel.ejs +549 -118
- package/src/dashboard/views/partials/sidebar.ejs +3 -1
- package/src/dashboard/lib/domains-db.js +0 -51
- /package/src/{dashboard/routes → core/channels}/.gitkeep +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cli/menus/cleanup.js
|
|
3
|
+
*
|
|
4
|
+
* `ezz cleanup` — show what can be reclaimed, then remove what the user picks.
|
|
5
|
+
*
|
|
6
|
+
* The dry run is not a flag, it is the first half of the command: the
|
|
7
|
+
* inventory is always printed, with a size per item, before anything is
|
|
8
|
+
* offered. Nothing is selected by default except the groups that are
|
|
9
|
+
* unambiguous, and installed Node versions are never selected by default at
|
|
10
|
+
* all — "unused" is a guess, and the evidence is printed beside each one so
|
|
11
|
+
* the user can judge it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import chalk from 'chalk';
|
|
15
|
+
import inquirer from 'inquirer';
|
|
16
|
+
import ora from 'ora';
|
|
17
|
+
|
|
18
|
+
import * as cleanup from '../../core/cleanup.js';
|
|
19
|
+
|
|
20
|
+
/** How each group is introduced, and whether it is safe to preselect. */
|
|
21
|
+
const GROUP_INFO = {
|
|
22
|
+
'runtime-backups': {
|
|
23
|
+
title: 'Old runtime backups',
|
|
24
|
+
note: 'the newest of each kind is kept, so the last change can still be undone',
|
|
25
|
+
preselect: true,
|
|
26
|
+
},
|
|
27
|
+
logs: {
|
|
28
|
+
title: 'Easy DevOps logs',
|
|
29
|
+
note: 'only files older than the age threshold',
|
|
30
|
+
preselect: true,
|
|
31
|
+
},
|
|
32
|
+
temp: {
|
|
33
|
+
title: 'Temporary files, stale claims and dead locks',
|
|
34
|
+
note: 'a live lock and a pending stop request are never listed',
|
|
35
|
+
preselect: true,
|
|
36
|
+
},
|
|
37
|
+
'nginx-bak': {
|
|
38
|
+
title: 'nginx .bak files',
|
|
39
|
+
note: 'backups of configs that were rewritten; the .conf files themselves are untouched',
|
|
40
|
+
preselect: true,
|
|
41
|
+
},
|
|
42
|
+
'pm2-logs': {
|
|
43
|
+
title: 'PM2 logs',
|
|
44
|
+
note: 'truncated with `pm2 flush`, because PM2 holds the files open',
|
|
45
|
+
preselect: false,
|
|
46
|
+
},
|
|
47
|
+
'node-versions': {
|
|
48
|
+
title: 'Installed Node versions',
|
|
49
|
+
note: 'listed only - nothing here is selected for you',
|
|
50
|
+
preselect: false,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {Object} [opts]
|
|
56
|
+
* @param {string|number} [opts.days]
|
|
57
|
+
* @param {boolean} [opts.yes] Remove the preselected groups without asking
|
|
58
|
+
* @returns {Promise<number>} Process exit code
|
|
59
|
+
*/
|
|
60
|
+
export async function cleanupCommand({ days, yes = false } = {}) {
|
|
61
|
+
const parsedDays = days === undefined ? cleanup.DEFAULT_LOG_DAYS : Number(days);
|
|
62
|
+
|
|
63
|
+
if (!Number.isFinite(parsedDays) || parsedDays < 0) {
|
|
64
|
+
process.stderr.write(`--days needs a number of days, not "${days}".\n`);
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const spinner = ora('Looking for reclaimable files...').start();
|
|
69
|
+
let report;
|
|
70
|
+
try {
|
|
71
|
+
report = await cleanup.scan({ days: parsedDays });
|
|
72
|
+
} finally {
|
|
73
|
+
spinner.stop();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log();
|
|
77
|
+
console.log(' ' + chalk.bold('Cleanup'));
|
|
78
|
+
console.log(' ' + chalk.gray('-'.repeat(58)));
|
|
79
|
+
console.log(' ' + chalk.gray(`data directory: ${report.dataDir}`));
|
|
80
|
+
console.log(' ' + chalk.gray(`logs older than ${report.days} days count as reclaimable (--days N)`));
|
|
81
|
+
console.log();
|
|
82
|
+
|
|
83
|
+
let anything = false;
|
|
84
|
+
|
|
85
|
+
for (const group of cleanup.GROUPS) {
|
|
86
|
+
const data = report.groups[group];
|
|
87
|
+
if (!data || data.count === 0) continue;
|
|
88
|
+
anything = true;
|
|
89
|
+
|
|
90
|
+
const info = GROUP_INFO[group];
|
|
91
|
+
console.log(' ' + chalk.bold(info.title)
|
|
92
|
+
+ chalk.gray(` ${cleanup.humanBytes(data.bytes)} reclaimable`));
|
|
93
|
+
console.log(' ' + chalk.gray(info.note));
|
|
94
|
+
|
|
95
|
+
for (const item of data.items) {
|
|
96
|
+
const mark = item.removable ? chalk.yellow('-') : chalk.green('=');
|
|
97
|
+
const size = item.bytes ? chalk.gray(` ${cleanup.humanBytes(item.bytes)}`) : '';
|
|
98
|
+
const label = item.version ? `Node v${item.version}` : item.path;
|
|
99
|
+
console.log(` ${mark} ${label}${size}`);
|
|
100
|
+
console.log(` ${chalk.gray(item.why)}`);
|
|
101
|
+
}
|
|
102
|
+
console.log();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!anything) {
|
|
106
|
+
console.log(' ' + chalk.green('Nothing to reclaim.'));
|
|
107
|
+
console.log();
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.log(' ' + chalk.white(`Total reclaimable: ${cleanup.humanBytes(report.totalBytes)}`));
|
|
112
|
+
console.log(' ' + chalk.gray('Nothing has been removed. The database, your settings, your'));
|
|
113
|
+
console.log(' ' + chalk.gray('certificates and every active nginx config are never listed.'));
|
|
114
|
+
console.log();
|
|
115
|
+
|
|
116
|
+
// What can actually be acted on.
|
|
117
|
+
const candidates = report.items.filter((i) => i.removable);
|
|
118
|
+
if (candidates.length === 0) {
|
|
119
|
+
console.log(' ' + chalk.gray('Everything found is in use or kept on purpose.'));
|
|
120
|
+
console.log();
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let chosen;
|
|
125
|
+
|
|
126
|
+
if (yes) {
|
|
127
|
+
// Only the unambiguous groups. --yes must never uninstall a Node version
|
|
128
|
+
// or touch PM2 on its own: those need a human to look at the evidence.
|
|
129
|
+
chosen = candidates.filter((i) => GROUP_INFO[i.group]?.preselect);
|
|
130
|
+
console.log(' ' + chalk.gray(`--yes: removing ${chosen.length} item(s) from the unambiguous groups only.`));
|
|
131
|
+
} else {
|
|
132
|
+
const { picked } = await inquirer.prompt([{
|
|
133
|
+
type: 'checkbox',
|
|
134
|
+
name: 'picked',
|
|
135
|
+
message: 'Remove which items?',
|
|
136
|
+
pageSize: 18,
|
|
137
|
+
choices: cleanup.GROUPS.flatMap((group) => {
|
|
138
|
+
const data = report.groups[group];
|
|
139
|
+
const removable = (data?.items ?? []).filter((i) => i.removable);
|
|
140
|
+
if (removable.length === 0) return [];
|
|
141
|
+
return [
|
|
142
|
+
new inquirer.Separator(` ${GROUP_INFO[group].title} `),
|
|
143
|
+
...removable.map((item) => ({
|
|
144
|
+
name: `${item.version ? `Node v${item.version}` : item.path} (${cleanup.humanBytes(item.bytes)})`,
|
|
145
|
+
value: item.id,
|
|
146
|
+
checked: GROUP_INFO[group].preselect,
|
|
147
|
+
})),
|
|
148
|
+
];
|
|
149
|
+
}),
|
|
150
|
+
}]);
|
|
151
|
+
|
|
152
|
+
chosen = candidates.filter((i) => picked.includes(i.id));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (chosen.length === 0) {
|
|
156
|
+
console.log(' ' + chalk.gray('Nothing selected; nothing was removed.'));
|
|
157
|
+
console.log();
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const bytes = chosen.reduce((sum, i) => sum + (i.bytes ?? 0), 0);
|
|
162
|
+
const nodeVersions = chosen.filter((i) => i.group === 'node-versions');
|
|
163
|
+
|
|
164
|
+
if (!yes) {
|
|
165
|
+
console.log();
|
|
166
|
+
if (nodeVersions.length) {
|
|
167
|
+
console.log(' ' + chalk.yellow(
|
|
168
|
+
`This will uninstall ${nodeVersions.length} Node version(s): `
|
|
169
|
+
+ nodeVersions.map((i) => `v${i.version}`).join(', '),
|
|
170
|
+
));
|
|
171
|
+
console.log(' ' + chalk.gray('Anything outside Easy DevOps that uses them will stop working.'));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const { confirm } = await inquirer.prompt([{
|
|
175
|
+
type: 'confirm',
|
|
176
|
+
name: 'confirm',
|
|
177
|
+
message: `Remove ${chosen.length} item(s), freeing about ${cleanup.humanBytes(bytes)}?`,
|
|
178
|
+
default: false,
|
|
179
|
+
}]);
|
|
180
|
+
|
|
181
|
+
if (!confirm) {
|
|
182
|
+
console.log(' ' + chalk.gray('Nothing was removed.'));
|
|
183
|
+
console.log();
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
console.log();
|
|
189
|
+
const result = await cleanup.apply({
|
|
190
|
+
items: chosen,
|
|
191
|
+
log: (line) => console.log(' ' + chalk.gray(line)),
|
|
192
|
+
});
|
|
193
|
+
console.log();
|
|
194
|
+
|
|
195
|
+
console.log(' ' + chalk.green(
|
|
196
|
+
`Removed ${result.removed.length} item(s), freeing about ${cleanup.humanBytes(result.freedBytes)}.`,
|
|
197
|
+
));
|
|
198
|
+
|
|
199
|
+
for (const failure of result.failed) {
|
|
200
|
+
console.log(' ' + chalk.yellow(`could not remove ${failure.path}: ${failure.reason}`));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
console.log();
|
|
204
|
+
return result.failed.length === 0 ? 0 : 1;
|
|
205
|
+
}
|
|
@@ -10,11 +10,15 @@ import { fileURLToPath } from 'url';
|
|
|
10
10
|
import path from 'path';
|
|
11
11
|
import { loadConfig } from '../../core/config.js';
|
|
12
12
|
import { dbGet, dbSet } from '../../core/db.js';
|
|
13
|
+
import { getDataDir } from '../../core/platform.js';
|
|
13
14
|
import { run } from '../../core/shell.js';
|
|
14
15
|
|
|
15
16
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
17
|
const isWindows = process.platform === 'win32';
|
|
17
|
-
|
|
18
|
+
// Principle IV: logs live in the user's data directory, never inside the
|
|
19
|
+
// package — a package-relative path is wiped by `npm update`. Follows
|
|
20
|
+
// EASY_DEVOPS_DATA_DIR in dev mode like the database and sessions do.
|
|
21
|
+
const LOG_PATH = path.join(getDataDir(), 'logs', 'dashboard.log');
|
|
18
22
|
const SERVER_PATH = path.resolve(__dirname, '../../dashboard/server.js');
|
|
19
23
|
|
|
20
24
|
// ─── Port helpers ─────────────────────────────────────────────────────────────
|
|
@@ -76,7 +80,7 @@ export async function getDashboardStatus() {
|
|
|
76
80
|
const pidAlive = isPidAlive(storedPid);
|
|
77
81
|
const responding = pidAlive && await httpPing(storedPort, 1000);
|
|
78
82
|
|
|
79
|
-
if (storedPid && !
|
|
83
|
+
if (storedPid && !responding) {
|
|
80
84
|
dbSet('dashboard-pid', null);
|
|
81
85
|
dbSet('dashboard-port', null);
|
|
82
86
|
}
|
|
@@ -159,12 +163,89 @@ function showUsageInfo() {
|
|
|
159
163
|
console.log();
|
|
160
164
|
}
|
|
161
165
|
|
|
166
|
+
// ─── `ezz dashboard <action>` ─────────────────────────────────────────────────
|
|
167
|
+
|
|
168
|
+
const DASHBOARD_ACTIONS = ['setup-code'];
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Issues a new first-run setup code and prints it.
|
|
172
|
+
*
|
|
173
|
+
* CLI-only, deliberately: the code's whole purpose is to prove that whoever is
|
|
174
|
+
* setting the first password can read this machine's terminal or its service
|
|
175
|
+
* log. An endpoint that handed it out would defeat it, so there is none — and
|
|
176
|
+
* this is also the only way back once a code has expired or been invalidated
|
|
177
|
+
* by too many wrong guesses.
|
|
178
|
+
*
|
|
179
|
+
* @returns {Promise<number>} Process exit code
|
|
180
|
+
*/
|
|
181
|
+
async function issueSetupCode() {
|
|
182
|
+
const { loadConfig } = await import('../../core/config.js');
|
|
183
|
+
const setupCode = await import('../../core/setupCode.js');
|
|
184
|
+
|
|
185
|
+
const config = loadConfig();
|
|
186
|
+
|
|
187
|
+
if (!setupCode.setupPending(config)) {
|
|
188
|
+
console.log();
|
|
189
|
+
console.log(' ' + chalk.white('The dashboard is already set up.'));
|
|
190
|
+
console.log(' ' + chalk.gray('A setup code only applies before the first password is set.'));
|
|
191
|
+
console.log(' ' + chalk.gray('Change the password in the dashboard under Settings.'));
|
|
192
|
+
console.log();
|
|
193
|
+
// Any leftover code is removed rather than left outstanding.
|
|
194
|
+
if (setupCode.clear()) {
|
|
195
|
+
console.log(' ' + chalk.gray('An outstanding code was cleared.'));
|
|
196
|
+
console.log();
|
|
197
|
+
}
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const issued = await setupCode.issue();
|
|
202
|
+
|
|
203
|
+
for (const line of setupCode.describe({ code: issued.code, expiresAt: issued.expiresAt })) {
|
|
204
|
+
console.log(line);
|
|
205
|
+
}
|
|
206
|
+
console.log(' ' + chalk.gray('This replaces any code issued earlier.'));
|
|
207
|
+
console.log();
|
|
208
|
+
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Entry point for the `dashboard` command.
|
|
214
|
+
*
|
|
215
|
+
* @param {string} action
|
|
216
|
+
* @returns {Promise<number>} Process exit code
|
|
217
|
+
*/
|
|
218
|
+
export async function dashboardCommand(action) {
|
|
219
|
+
if (!DASHBOARD_ACTIONS.includes(action)) {
|
|
220
|
+
process.stderr.write(
|
|
221
|
+
`Unknown dashboard action: ${action}\n` +
|
|
222
|
+
`Available: ${DASHBOARD_ACTIONS.join(', ')}\n`
|
|
223
|
+
);
|
|
224
|
+
return 1;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
switch (action) {
|
|
228
|
+
case 'setup-code': return issueSetupCode();
|
|
229
|
+
default: return 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
162
233
|
// ─── Menu ─────────────────────────────────────────────────────────────────────
|
|
163
234
|
|
|
164
235
|
export default async function dashboardMenu() {
|
|
165
236
|
while (true) {
|
|
166
237
|
const spinner = ora('Checking dashboard status...').start();
|
|
167
238
|
const status = await getDashboardStatus();
|
|
239
|
+
|
|
240
|
+
// The background SERVICE no longer runs the dashboard — it runs the daemon,
|
|
241
|
+
// which serves no UI. So this menu always owns starting and stopping the
|
|
242
|
+
// dashboard; what the service state changes is only what to tell the user
|
|
243
|
+
// about monitoring.
|
|
244
|
+
let background = null;
|
|
245
|
+
try {
|
|
246
|
+
const { backgroundServiceState } = await import('../../core/service/index.js');
|
|
247
|
+
background = backgroundServiceState();
|
|
248
|
+
} catch { /* unreadable state: the dashboard lines below still apply */ }
|
|
168
249
|
spinner.stop();
|
|
169
250
|
|
|
170
251
|
const url = `http://localhost:${status.port}`;
|
|
@@ -177,6 +258,16 @@ export default async function dashboardMenu() {
|
|
|
177
258
|
} else {
|
|
178
259
|
console.log(` ${chalk.red('❌ Stopped')} | port ${status.configPort}`);
|
|
179
260
|
}
|
|
261
|
+
|
|
262
|
+
// Whether monitoring survives closing the dashboard is a separate fact,
|
|
263
|
+
// and the one users were surprised by.
|
|
264
|
+
if (background?.running) {
|
|
265
|
+
console.log(chalk.gray(` Background service running (pid ${background.pid}) — monitoring continues without this page.`));
|
|
266
|
+
} else if (background?.installed) {
|
|
267
|
+
console.log(chalk.yellow(' Background service installed but not running') + chalk.gray(' — `ezz service start`'));
|
|
268
|
+
} else {
|
|
269
|
+
console.log(chalk.gray(' No background service — monitoring runs only while the dashboard is open.'));
|
|
270
|
+
}
|
|
180
271
|
console.log();
|
|
181
272
|
|
|
182
273
|
const choices = status.running
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cli/menus/runtime.js
|
|
3
|
+
*
|
|
4
|
+
* `ezz runtime status | update` — the Node runtime the background service is
|
|
5
|
+
* pinned to.
|
|
6
|
+
*
|
|
7
|
+
* CLI-only, for two reasons that are both about honesty rather than policy:
|
|
8
|
+
* the step that installs a Node version can take minutes and streams output
|
|
9
|
+
* nobody would see from a web request, and on Windows Server mode the swap
|
|
10
|
+
* needs an Administrator terminal, which a dashboard cannot obtain and must
|
|
11
|
+
* not pretend to. As everywhere else in this project, the CLI asks every
|
|
12
|
+
* question and `core/service/` does the work without prompting.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import chalk from 'chalk';
|
|
16
|
+
import inquirer from 'inquirer';
|
|
17
|
+
import ora from 'ora';
|
|
18
|
+
|
|
19
|
+
import { isWindows } from '../../core/platform.js';
|
|
20
|
+
import * as runtimeUpdate from '../../core/service/runtimeUpdate.js';
|
|
21
|
+
import * as service from '../../core/service/index.js';
|
|
22
|
+
|
|
23
|
+
const ACTIONS = ['status', 'update'];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} action
|
|
27
|
+
* @param {Object} [opts]
|
|
28
|
+
* @param {boolean} [opts.yes] Take the newest usable version without asking
|
|
29
|
+
* @returns {Promise<number>} Process exit code
|
|
30
|
+
*/
|
|
31
|
+
export async function runtimeCommand(action, { yes = false } = {}) {
|
|
32
|
+
if (!ACTIONS.includes(action)) {
|
|
33
|
+
process.stderr.write(
|
|
34
|
+
`Unknown runtime action: ${action}\n` +
|
|
35
|
+
`Available: ${ACTIONS.join(', ')}\n`
|
|
36
|
+
);
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return action === 'status' ? showStatus() : doUpdate({ yes });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const dot = (ok) => (ok ? chalk.green('*') : chalk.red('*'));
|
|
44
|
+
|
|
45
|
+
function header(title) {
|
|
46
|
+
console.log();
|
|
47
|
+
console.log(' ' + chalk.bold(title));
|
|
48
|
+
console.log(' ' + chalk.gray('-'.repeat(58)));
|
|
49
|
+
console.log();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Shared by both actions: read the state once and render the top of it. */
|
|
53
|
+
async function loadAndPrint() {
|
|
54
|
+
const spinner = ora('Reading the pinned runtime and the available versions...').start();
|
|
55
|
+
let targets;
|
|
56
|
+
try {
|
|
57
|
+
targets = await runtimeUpdate.listTargets();
|
|
58
|
+
} finally {
|
|
59
|
+
spinner.stop();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
header('Service runtime');
|
|
63
|
+
|
|
64
|
+
const pinned = targets.pinned;
|
|
65
|
+
console.log(` ${dot(Boolean(pinned.version) && !pinned.broken)} Pinned `
|
|
66
|
+
+ (pinned.version ? chalk.white(`v${pinned.version}`) : chalk.yellow('unknown'))
|
|
67
|
+
+ chalk.gray(` (${pinned.kind})`));
|
|
68
|
+
if (pinned.path) console.log(` ${chalk.gray(pinned.path)}`);
|
|
69
|
+
if (pinned.kind === 'symlink' && pinned.target) console.log(` ${chalk.gray('-> ' + pinned.target)}`);
|
|
70
|
+
if (pinned.broken) {
|
|
71
|
+
console.log(' ' + chalk.red('the pinned runtime is missing or does not run'));
|
|
72
|
+
console.log(' ' + chalk.gray('`ezz service repair` re-pins it to the Node you are using now'));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const system = targets.systemNode;
|
|
76
|
+
console.log(` ${dot(Boolean(system.version))} On PATH `
|
|
77
|
+
+ (system.version ? chalk.white(`v${system.version}`) : chalk.yellow('no node found')));
|
|
78
|
+
if (system.path) console.log(` ${chalk.gray(system.path)}`);
|
|
79
|
+
|
|
80
|
+
console.log(` ${dot(Boolean(targets.manager.manager))} Manager `
|
|
81
|
+
+ (targets.manager.manager
|
|
82
|
+
? chalk.white(targets.manager.manager)
|
|
83
|
+
: chalk.gray(targets.manager.reason)));
|
|
84
|
+
|
|
85
|
+
console.log(` ${chalk.gray(`minimum supported: Node ${targets.minimum.major} (${targets.minimum.raw})`)}`);
|
|
86
|
+
|
|
87
|
+
// A clone is not updated by npm, and the same is true of the runtime's app
|
|
88
|
+
// copy in Windows Server mode — it is refreshed from wherever this package
|
|
89
|
+
// lives, so where that is matters.
|
|
90
|
+
if (targets.installSource.kind !== 'npm') {
|
|
91
|
+
console.log(` ${chalk.gray(`this copy: ${targets.installSource.reason}`)}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return targets;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function showStatus() {
|
|
98
|
+
const targets = await loadAndPrint();
|
|
99
|
+
|
|
100
|
+
const usable = targets.candidates.filter((c) => c.meetsMinimum && !c.isPinned);
|
|
101
|
+
|
|
102
|
+
console.log();
|
|
103
|
+
if (targets.nothingToUpdate) {
|
|
104
|
+
console.log(' ' + chalk.green('Nothing to update.'));
|
|
105
|
+
for (const line of targets.hint ?? []) console.log(' ' + chalk.gray(line));
|
|
106
|
+
console.log();
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log(' ' + chalk.bold('Available'));
|
|
111
|
+
for (const candidate of usable.slice(0, 8)) {
|
|
112
|
+
const label = candidate.source === 'system'
|
|
113
|
+
? chalk.gray('already installed on this machine')
|
|
114
|
+
: chalk.gray(`install with ${candidate.source}`);
|
|
115
|
+
console.log(` v${candidate.version} ${label}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const blocked = targets.candidates.filter((c) => !c.meetsMinimum);
|
|
119
|
+
if (blocked.length) {
|
|
120
|
+
console.log();
|
|
121
|
+
console.log(' ' + chalk.gray(`${blocked.length} version(s) below the supported minimum are not offered.`));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
console.log();
|
|
125
|
+
console.log(' ' + chalk.white('ezz runtime update') + chalk.gray(' move the service onto one of these'));
|
|
126
|
+
console.log();
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function doUpdate({ yes = false } = {}) {
|
|
131
|
+
const targets = await loadAndPrint();
|
|
132
|
+
|
|
133
|
+
// Nothing is installed to update: say so rather than offering to re-pin a
|
|
134
|
+
// service that does not exist.
|
|
135
|
+
const installed = await service.status().catch(() => null);
|
|
136
|
+
if (installed && !installed.service.installed) {
|
|
137
|
+
console.log();
|
|
138
|
+
console.log(' ' + chalk.white('No background service is installed, so there is no pinned runtime to move.'));
|
|
139
|
+
console.log(' ' + chalk.gray('Install one with: ') + chalk.white('ezz service install'));
|
|
140
|
+
console.log();
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (targets.nothingToUpdate) {
|
|
145
|
+
console.log();
|
|
146
|
+
console.log(' ' + chalk.green('Nothing to update.'));
|
|
147
|
+
for (const line of targets.hint ?? []) console.log(' ' + chalk.gray(line));
|
|
148
|
+
console.log();
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const usable = targets.candidates.filter((c) => c.meetsMinimum && !c.isPinned);
|
|
153
|
+
|
|
154
|
+
let target = usable[0];
|
|
155
|
+
|
|
156
|
+
if (!yes) {
|
|
157
|
+
console.log();
|
|
158
|
+
const { chosen } = await inquirer.prompt([{
|
|
159
|
+
type: 'list',
|
|
160
|
+
name: 'chosen',
|
|
161
|
+
message: 'Move the service to which Node version?',
|
|
162
|
+
pageSize: 12,
|
|
163
|
+
choices: [
|
|
164
|
+
...usable.slice(0, 10).map((c) => ({
|
|
165
|
+
name: `v${c.version}${c.source === 'system' ? ' (already on this machine)' : ` (via ${c.source})`}`,
|
|
166
|
+
value: c,
|
|
167
|
+
})),
|
|
168
|
+
new inquirer.Separator(),
|
|
169
|
+
{ name: 'Cancel', value: null },
|
|
170
|
+
],
|
|
171
|
+
}]);
|
|
172
|
+
|
|
173
|
+
if (!chosen) {
|
|
174
|
+
console.log(' ' + chalk.gray('Nothing was changed.'));
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
target = chosen;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
console.log();
|
|
181
|
+
console.log(' ' + chalk.bold(`Updating the service runtime to v${target.version}`));
|
|
182
|
+
console.log(' ' + chalk.gray('The service keeps running until the new runtime has been tested.'));
|
|
183
|
+
console.log();
|
|
184
|
+
|
|
185
|
+
const result = await runtimeUpdate.update({
|
|
186
|
+
target,
|
|
187
|
+
log: (line) => console.log(' ' + chalk.gray(line)),
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
console.log();
|
|
191
|
+
|
|
192
|
+
if (result.ok) {
|
|
193
|
+
console.log(' ' + chalk.green(`Done. The service runs Node v${result.version}.`));
|
|
194
|
+
if (result.detail) console.log(' ' + chalk.gray(result.detail));
|
|
195
|
+
console.log(' ' + chalk.gray(`The daemon reported in after ${result.waitedMs}ms.`));
|
|
196
|
+
console.log();
|
|
197
|
+
console.log(' ' + chalk.gray('The previous runtime was left in place: nothing uninstalls a Node version.'));
|
|
198
|
+
console.log(' ' + chalk.gray('`ezz cleanup` lists the backup copy when you no longer want it.'));
|
|
199
|
+
console.log();
|
|
200
|
+
return 0;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Failures are reported by the step that failed, because what the user
|
|
204
|
+
// should do next is entirely different for each one.
|
|
205
|
+
console.log(' ' + chalk.red(`The runtime was not updated (${result.step}).`));
|
|
206
|
+
console.log();
|
|
207
|
+
for (const line of String(result.reason ?? '').split('\n')) console.log(' ' + line);
|
|
208
|
+
if (result.fix) {
|
|
209
|
+
console.log();
|
|
210
|
+
for (const line of String(result.fix).split('\n')) console.log(' ' + chalk.gray(line));
|
|
211
|
+
}
|
|
212
|
+
console.log();
|
|
213
|
+
|
|
214
|
+
if (result.untouched) {
|
|
215
|
+
console.log(' ' + chalk.green('Nothing was changed and the service was not stopped.'));
|
|
216
|
+
} else if (result.rolledBack) {
|
|
217
|
+
console.log(' ' + chalk.green('The previous runtime was restored.')
|
|
218
|
+
+ (result.restored ? chalk.gray(' The service is running again.') : ''));
|
|
219
|
+
if (!result.restored) {
|
|
220
|
+
console.log(' ' + chalk.yellow('The service did not come back by itself: ')
|
|
221
|
+
+ chalk.white('ezz service start'));
|
|
222
|
+
}
|
|
223
|
+
} else if (result.restarted) {
|
|
224
|
+
console.log(' ' + chalk.gray('The service was started again on the runtime it had.'));
|
|
225
|
+
} else {
|
|
226
|
+
console.log(' ' + chalk.yellow('The service may be stopped. Check: ') + chalk.white('ezz service status'));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (result.needsElevation && isWindows) {
|
|
230
|
+
console.log();
|
|
231
|
+
console.log(' ' + chalk.gray('No password is needed - only elevation.'));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
console.log();
|
|
235
|
+
return 1;
|
|
236
|
+
}
|