@roomi-fields/grillhouse 0.52.0 → 0.53.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/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +48 -0
- package/agents/direct.md +1 -1
- package/cadre/templates/projet/vitest.config.cjs +45 -0
- package/charte/superviseur.md +36 -37
- package/charte.md +1 -1
- package/dist/temporal/circuit/appel.d.ts +2 -0
- package/dist/temporal/circuit/appel.js +24 -2
- package/dist/temporal/circuit/appel.js.map +1 -1
- package/dist/temporal/circuit/client.d.ts +14 -5
- package/dist/temporal/circuit/client.js +41 -9
- package/dist/temporal/circuit/client.js.map +1 -1
- package/dist/temporal/circuit/commande.js +17 -6
- package/dist/temporal/circuit/commande.js.map +1 -1
- package/dist/temporal/circuit/contrat.d.ts +9 -0
- package/dist/temporal/circuit/contrat.js +6 -0
- package/dist/temporal/circuit/contrat.js.map +1 -1
- package/dist/temporal/circuit/deroule.js +25 -4
- package/dist/temporal/circuit/deroule.js.map +1 -1
- package/dist/temporal/client.d.ts +35 -1
- package/dist/temporal/client.js +144 -1
- package/dist/temporal/client.js.map +1 -1
- package/dist/temporal/commande.js +31 -13
- package/dist/temporal/commande.js.map +1 -1
- package/dist/temporal/etat.d.ts +3 -1
- package/dist/temporal/etat.js +31 -17
- package/dist/temporal/etat.js.map +1 -1
- package/dist/temporal/file/activites.js +1 -1
- package/dist/temporal/file/activites.js.map +1 -1
- package/dist/temporal/file/contrat.d.ts +4 -5
- package/dist/temporal/file/contrat.js +2 -2
- package/dist/temporal/file/contrat.js.map +1 -1
- package/dist/temporal/file/deroule.js +7 -5
- package/dist/temporal/file/deroule.js.map +1 -1
- package/dist/temporal/installation.d.ts +103 -53
- package/dist/temporal/installation.js +842 -237
- package/dist/temporal/installation.js.map +1 -1
- package/dist/temporal/nuits/deroule.js +3 -1
- package/dist/temporal/nuits/deroule.js.map +1 -1
- package/dist/temporal/places/deroule.js +2 -1
- package/dist/temporal/places/deroule.js.map +1 -1
- package/dist/temporal/sonde/deroule.js +2 -1
- package/dist/temporal/sonde/deroule.js.map +1 -1
- package/dist/temporal/tickets/deroule.js +4 -3
- package/dist/temporal/tickets/deroule.js.map +1 -1
- package/dist/temporal/travailleur.d.ts +7 -1
- package/dist/temporal/travailleur.js +49 -25
- package/dist/temporal/travailleur.js.map +1 -1
- package/docs/INTERFACE.md +17 -12
- package/docs/architecture/circuit.md +18 -15
- package/docs/architecture/entree.md +7 -8
- package/docs/architecture/greffon.md +30 -21
- package/docs/architecture/installation.md +87 -58
- package/docs/architecture/machine.md +1 -1
- package/docs/architecture/tests.md +14 -5
- package/docs/lexique.md +2 -2
- package/hooks/hooks.json +10 -0
- package/hooks/register.tsx +19 -25
- package/package.json +3 -2
- package/scripts/activites.mjs +5 -4
- package/scripts/aiguillage.mjs +1 -0
- package/scripts/circuit.mjs +254 -42
- package/scripts/circuits-du-serveur.mjs +3 -2
- package/scripts/circuits-tenus.d.mts +7 -0
- package/scripts/circuits-tenus.mjs +17 -0
- package/scripts/copie-de-montee.mjs +354 -0
- package/scripts/copies-du-depot.d.mts +13 -0
- package/scripts/copies-du-depot.mjs +66 -0
- package/scripts/copies-finies.mjs +6 -40
- package/scripts/crochets.mjs +16 -2
- package/scripts/direct.mjs +2 -2
- package/scripts/droits.mjs +2 -2
- package/scripts/engendres.mjs +5 -3
- package/scripts/enveloppe/travail-de-la-copie.mjs +77 -0
- package/scripts/etapes.mjs +11 -3
- package/scripts/faits-du-circuit.mjs +12 -5
- package/scripts/file-des-tickets.d.mts +13 -2
- package/scripts/file-des-tickets.mjs +44 -12
- package/scripts/greffons.mjs +42 -27
- package/scripts/grillhouse-maj.mjs +105 -85
- package/scripts/init.mjs +1 -1
- package/scripts/integration/file.mjs +5 -2
- package/scripts/integration/integrer.mjs +14 -4
- package/scripts/jointure.d.ts +16 -0
- package/scripts/langages/c/commandes.mjs +17 -7
- package/scripts/langages/cargo/commandes.mjs +87 -34
- package/scripts/langages/cargo/index.mjs +6 -3
- package/scripts/langages/cargo/sccache.mjs +15 -12
- package/scripts/langages/python/commandes.mjs +18 -8
- package/scripts/langages/python/squelette.mjs +2 -2
- package/scripts/langages/typescript/configurations-de-vitest.mjs +118 -0
- package/scripts/langages/typescript/index.mjs +2 -0
- package/scripts/langages/typescript/migrations/configurations-en-commonjs.mjs +299 -0
- package/scripts/langages/typescript/squelette.mjs +20 -17
- package/scripts/langages/typescript/tests-de-nuit.mjs +3 -3
- package/scripts/langages/typescript/turbo-des-paquets.mjs +24 -37
- package/scripts/langages/typescript/vitest-config/base.mjs +1 -1
- package/scripts/langages/typescript/vitest-config/bornes.mjs +1 -1
- package/scripts/langages/typescript/vitest-config/cibles.mjs +2 -2
- package/scripts/langages/typescript/{vitest.nuit.config.mjs → vitest.nuit.config.cjs} +61 -50
- package/scripts/mesure/pression.mjs +5 -3
- package/scripts/montee.mjs +524 -0
- package/scripts/outil.mjs +5 -3
- package/scripts/paquet-npm.mjs +22 -0
- package/scripts/paquet.mjs +5 -5
- package/scripts/pre-compact.mjs +25 -0
- package/scripts/reponses-du-circuit.d.mts +17 -2
- package/scripts/reponses-du-circuit.mjs +78 -20
- package/scripts/resultats.mjs +40 -12
- package/scripts/retirer-les-copies-finies.mjs +4 -7
- package/scripts/seances.mjs +28 -3
- package/scripts/services-du-noyau.mjs +7 -2
- package/scripts/session-start.sh +18 -11
- package/scripts/sortie.mjs +4 -7
- package/scripts/sous-commandes.mjs +1 -0
- package/scripts/superviseur.mjs +110 -70
- package/scripts/tableau.mjs +127 -108
- package/scripts/ticket-du-circuit.mjs +22 -0
- package/scripts/transitions.d.mts +6 -9
- package/scripts/transitions.mjs +123 -36
- package/scripts/verrou-de-fichier.d.mts +11 -0
- package/skills/direct/SKILL.md +21 -11
- package/skills/explorateur/SKILL.md +6 -1
- package/skills/grill/SKILL.md +9 -7
- package/skills/grill/references/paquets.md +4 -4
- package/skills/pitmaster/SKILL.md +45 -33
- package/skills/pitmaster/references/consigne-agent.md +1 -1
- package/skills/relecteur/SKILL.md +8 -1
- package/skills/testwriter/SKILL.md +1 -1
- package/cadre/templates/projet/vitest.config.ts +0 -44
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// The installation of the account's Temporal (`grillhouse temporal installer`): the program
|
|
2
2
|
// `temporal` at its pinned version, its archive checked against its pinned sum, laid down under
|
|
3
|
-
// ~/.cache/grillhouse/temporal/<version>/temporal; the units of the account's systemd
|
|
4
|
-
// the worker of the project, the worker of the machine),
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// ~/.cache/grillhouse/temporal/<version>/temporal; the units of the account's systemd: the server,
|
|
4
|
+
// and one template of unit per task queue (the worker of the project, the worker of the machine),
|
|
5
|
+
// whose instance names the version of the frame it runs, each started again by systemd; the
|
|
6
|
+
// templates get `Environment=TEMPORAL=<the program laid down>`, the package.json untouched. The
|
|
7
|
+
// mechanism is installation.md §5.3 (step 4, the program and the units), §3.1, in
|
|
8
|
+
// packages/grillhouse/docs/architecture/: Temporal's Worker Deployments, one living worker per
|
|
9
|
+
// version.
|
|
8
10
|
//
|
|
9
11
|
// - The pin (EPINGLE) is the version of the program and the SHA-256 of the archive of each
|
|
10
12
|
// platform, as its release publishes them (checksums.txt); an archive whose sum differs is
|
|
@@ -20,10 +22,10 @@
|
|
|
20
22
|
// - Applying the server's unit (its text changed, or the program newly laid down) asks the server
|
|
21
23
|
// for the circuits in flight before any writing; when there is one (`circuitsEnVol`; a server
|
|
22
24
|
// that does not answer has none), the server's unit alone is deferred to a later run, the
|
|
23
|
-
// circuits named in the report (`serveurDiffere`), the program laid down and the workers'
|
|
24
|
-
// applied all the same; otherwise it stops the server, compacts
|
|
25
|
-
//
|
|
26
|
-
//
|
|
25
|
+
// circuits named in the report (`serveurDiffere`), the program laid down and the workers'
|
|
26
|
+
// templates applied all the same; otherwise it stops the server, compacts its database
|
|
27
|
+
// (`compacterLaBase`, `VACUUM` by the runtime's `node:sqlite`) and starts it again, and the
|
|
28
|
+
// report says the sizes before and after. A failed compaction starts the server again and
|
|
27
29
|
// refuses the installation by its name, the unit not recorded as applied.
|
|
28
30
|
// - `purger` deletes by query the workflows closed for longer than the retention, never a running
|
|
29
31
|
// one (the server keeps the deletion timer a workflow got when it closed, under the retention of
|
|
@@ -31,48 +33,89 @@
|
|
|
31
33
|
// no execution references (`retirerLesOrphelins`, in SQL: a gap to the reference), compacts the
|
|
32
34
|
// database as above and starts the server again. A circuit in flight refuses it by its tickets,
|
|
33
35
|
// before the deletion and again before the stop.
|
|
34
|
-
// -
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
36
|
+
// - The version a project installs is its key `grillhouse.outil` (scripts/aiguillage.mjs), else
|
|
37
|
+
// that of the package it installed. It is laid down under the cache of the home
|
|
38
|
+
// (~/.cache/grillhouse/outil/<version>/) before any unit is written, and refused, named, when it
|
|
39
|
+
// does not install, carries no worker or, without the key, when the integrity the project's lock
|
|
40
|
+
// file gives the installed package differs from the cache's, or is missing on either side.
|
|
41
|
+
// - Each template runs dist/temporal/travailleur.js of the version its instance names (`%i`), from
|
|
42
|
+
// that cache, on its task queue: `grillhouse-projet-<projet>` for the project's,
|
|
43
|
+
// `grillhouse-machine` for the machine's. Its text is the same from a version to the next; an
|
|
44
|
+
// instance that starts again reads it as it is then.
|
|
40
45
|
// - Every refusal comes before any writing (the archive, an account's tool, a fault of
|
|
41
|
-
// `grillhouse.outils
|
|
42
|
-
//
|
|
43
|
-
// - A unit of systemd starts with a bare PATH: each
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
46
|
+
// `grillhouse.outils`), but the published version itself: it is laid down in its cache before
|
|
47
|
+
// its refusal, which reads it there.
|
|
48
|
+
// - A unit of systemd starts with a bare PATH: each template names the PATH of the account's tools
|
|
49
|
+
// a circuit runs (node, npm, claude, bd, gh), found in the installer's PATH, and the tools of the
|
|
50
|
+
// project (`grillhouse.outils`), each its variable.
|
|
51
|
+
// - No running instance is ever restarted: the pass writes the templates, has systemd read them,
|
|
52
|
+
// starts the instance of the version it installs (`enable --now`), and names the running
|
|
53
|
+
// instances started under a former text. The server's unit alone is restarted.
|
|
54
|
+
// - Once its instance started, the version becomes the current one of the Worker Deployment of the
|
|
55
|
+
// task queue (`rendreCourante`, ./client.ts), which waits for the server within a bounded delay;
|
|
56
|
+
// past it, the installation fails, naming the version and the queue, no instance stopped.
|
|
57
|
+
// - Each pass retires (stops, disables, forgets) the instance whose version is not current, is not
|
|
58
|
+
// the one it installs, is drained or was never current (on the machine's queue, never current and
|
|
59
|
+
// lower than the current one), and whose process holds no started activity of a running workflow;
|
|
60
|
+
// a server that does not answer keeps every instance. The unit of before the template
|
|
61
|
+
// (`grillhouse-travailleur-<…>.service`) leaves, file and sum, at the first pass that finds its
|
|
62
|
+
// queue current on the version installed and its process holding no activity.
|
|
63
|
+
// - The drop-ins of a unit of before the template (`<unit>.d/*.conf`, systemd.unit(5)) follow it to
|
|
64
|
+
// the folder of its template: each pass that finds the unit copies them there before any instance
|
|
65
|
+
// starts, content unchanged, and the pass that retires the unit removes the former ones, before
|
|
66
|
+
// the file of the unit, then their folder once empty. A name the folder of the template holds with
|
|
67
|
+
// another content is neither overwritten nor removed. The output names each copy, each move and
|
|
68
|
+
// each such pair of paths; a pass that changes nothing speaks of none.
|
|
69
|
+
// - A single pass of installation plays on the account, from the laying down of the project's
|
|
70
|
+
// version to the end of the purge: a lock under the home (cheminsDe, `verrou`), which a second
|
|
71
|
+
// pass waits for, and which the lock of a dead process does not hold.
|
|
72
|
+
// - The last gesture of a pass that succeeds is the purge of the versions of the tool nothing names
|
|
73
|
+
// (`purgerLesVersions`): a version `x.y.z` of ~/.cache/grillhouse/outil/, with its failure mark
|
|
74
|
+
// `<version>.echec` (or the mark alone), leaves unless one of these names it: a project of the
|
|
75
|
+
// machine (the pass's own, and those the WorkingDirectory of a worker unit names, while their
|
|
76
|
+
// folder stands) by the version of its main tree (its key, else the package it installed); a unit
|
|
77
|
+
// of the account (an applied instance, or a unit file whose text plays that version of the
|
|
78
|
+
// cache); a copy of a circuit not finished (listed by `git worktree list`, its circuit held by
|
|
79
|
+
// the server, or its `.travail` there and its ticket not closed); a living process whose command
|
|
80
|
+
// line names a path of it; a Worker Deployment of a project of the machine, or of the machine,
|
|
81
|
+
// where it is current, draining or of an unknown drainage. When the server, the processes, the
|
|
82
|
+
// copies or a key that counts do not read, no version leaves; tickets that do not read only keep
|
|
83
|
+
// every copy beside its `.travail`. A version leaves by a rename first
|
|
84
|
+
// (`<version>.retrait-<id>`), so that a removal interrupted or failed is never taken for a
|
|
85
|
+
// version installed; the next purge removes what is left. It calls no systemctl.
|
|
47
86
|
// - Played again on an installation up to date, it changes nothing: the program of the pinned
|
|
48
|
-
// version is not downloaded again, a unit
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
// - An account holds several projects: the server and the
|
|
54
|
-
// a project's
|
|
55
|
-
// the other projects. The
|
|
56
|
-
//
|
|
57
|
-
// the
|
|
87
|
+
// version is not downloaded again, a unit is written only when it differs, and systemd is told
|
|
88
|
+
// only of what it has not applied yet. What systemd applied is kept apart from what is written:
|
|
89
|
+
// the sum of each unit's text once systemctl succeeded
|
|
90
|
+
// (~/.local/state/grillhouse/temporal/unites-appliquees.json), an instance under the sum of the
|
|
91
|
+
// template it started under, so that a systemctl that failed is played again at the next run.
|
|
92
|
+
// - An account holds several projects: the server and the template of the machine are the
|
|
93
|
+
// account's, a project's template is the project's. An installation keeps the sums applied for
|
|
94
|
+
// the units of the other projects. The worker of the machine plays the highest version a project
|
|
95
|
+
// of the account installed on it: the highest its applied instances name, and the one of the unit
|
|
96
|
+
// of before the template while it stands. A project below it starts no instance of the machine.
|
|
97
|
+
// The template of the machine belongs to the project that wrote it, which answers for its whole
|
|
98
|
+
// text; another project takes it only to raise the version (`textesDuProjet`), or once that
|
|
99
|
+
// project is gone.
|
|
58
100
|
// - `poserLeProgramme` lays down the program alone, no unit, no package.json, no systemd: the mode
|
|
59
101
|
// `--programme-seul` of the command, by which the night gets the pinned program as a user does.
|
|
60
102
|
// - The home, the directory of the units and the project are parameters (`lieuxDe`), as systemctl,
|
|
61
|
-
// the download, the published version and the account's tools are: a test installs
|
|
62
|
-
// trial home, never in the account's systemd.
|
|
103
|
+
// the download, the published version, the server and the account's tools are: a test installs
|
|
104
|
+
// under a trial home, never in the account's systemd.
|
|
63
105
|
import { spawnSync } from 'node:child_process';
|
|
64
|
-
import { createHash } from 'node:crypto';
|
|
65
|
-
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync,
|
|
106
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
107
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync, lstatSync, readdirSync, realpathSync, } from 'node:fs';
|
|
66
108
|
import { createRequire } from 'node:module';
|
|
67
109
|
import os from 'node:os';
|
|
68
110
|
import path from 'node:path';
|
|
69
|
-
import {
|
|
70
|
-
import {
|
|
111
|
+
import { cacheDesOutils, installer as installerLOutil, versionDeLOutil, X_Y_Z, } from '../../scripts/aiguillage.mjs';
|
|
112
|
+
import { ticketsTenus } from '../../scripts/circuits-tenus.mjs';
|
|
71
113
|
import { trouverDansLePath } from '../../scripts/commandes-du-path.mjs';
|
|
114
|
+
import { copiesListees, ticketsDuStatut } from '../../scripts/copies-du-depot.mjs';
|
|
72
115
|
import { langagesDe } from '../../scripts/langages.mjs';
|
|
73
116
|
import { lireOutils } from '../../scripts/outils-cles.mjs';
|
|
117
|
+
import { lacherVerrou, prendreVerrou } from '../../scripts/verrou-de-fichier.mjs';
|
|
74
118
|
import { ATTRIBUTS_DE_RECHERCHE } from './attributs.js';
|
|
75
|
-
import { idDeLaFile, L_ETAT_DE_LA_FILE, RELANCER } from './file/contrat.js';
|
|
76
119
|
/** The pin: temporal 1.9.1 (Server 1.32.0), its sums from the release's checksums.txt. */
|
|
77
120
|
export const EPINGLE = {
|
|
78
121
|
version: '1.9.1',
|
|
@@ -102,10 +145,14 @@ const OUTILS_DU_COMPTE = ['node', 'npm', 'claude', 'bd', 'gh'];
|
|
|
102
145
|
const PATH_DU_SYSTEME = ['/usr/local/bin', '/usr/bin', '/bin'];
|
|
103
146
|
/** The unit of the server. */
|
|
104
147
|
export const UNITE_DU_SERVEUR = 'grillhouse-temporal.service';
|
|
105
|
-
/** The
|
|
106
|
-
|
|
148
|
+
/** The template of the units of the worker of the machine. */
|
|
149
|
+
const GABARIT_DE_LA_MACHINE = 'grillhouse-travailleur-machine@.service';
|
|
107
150
|
/** The task queue of the worker of the machine. */
|
|
108
151
|
export const FILE_DE_LA_MACHINE = 'grillhouse-machine';
|
|
152
|
+
// The instance of the template <gabarit> for the version <version>.
|
|
153
|
+
const instanceDe = (gabarit, version) => gabarit.replace('@.service', () => `@${version}.service`);
|
|
154
|
+
// The unit of before the template <gabarit>, which no instance marks.
|
|
155
|
+
const uniteDAvant = (gabarit) => gabarit.replace('@.service', '.service');
|
|
109
156
|
/** The platform of Node's <platform> and <arch>; refused by its name when the pin has none. */
|
|
110
157
|
export function plateformeDe(platform = process.platform, arch = process.arch) {
|
|
111
158
|
const os = { linux: 'linux', darwin: 'darwin' }[platform];
|
|
@@ -126,12 +173,16 @@ export function lieuxDe({ maison, unites, racine } = {}, env = process.env) {
|
|
|
126
173
|
racine: path.resolve(racine ?? process.cwd()),
|
|
127
174
|
};
|
|
128
175
|
}
|
|
129
|
-
/**
|
|
176
|
+
/**
|
|
177
|
+
* The program of <version>, the server's database file, the units applied and the lock of the
|
|
178
|
+
* installation, under the home of <lieux>.
|
|
179
|
+
*/
|
|
130
180
|
export function cheminsDe(lieux, version) {
|
|
131
181
|
return {
|
|
132
182
|
programme: path.join(lieux.maison, '.cache/grillhouse/temporal', version, 'temporal'),
|
|
133
183
|
donnees: path.join(lieux.maison, '.local/share/grillhouse/temporal/temporal.db'),
|
|
134
184
|
appliquees: path.join(lieux.maison, '.local/state/grillhouse/temporal/unites-appliquees.json'),
|
|
185
|
+
verrou: path.join(lieux.maison, '.local/state/grillhouse/temporal/installation.verrou'),
|
|
135
186
|
};
|
|
136
187
|
}
|
|
137
188
|
// The name of the project at <racine>, for a unit and a task queue: its package's name, else its
|
|
@@ -152,20 +203,39 @@ function nomDuProjet(racine) {
|
|
|
152
203
|
.replace(/[^a-z0-9]+/g, '-')
|
|
153
204
|
.replace(/^-+|-+$/g, '');
|
|
154
205
|
}
|
|
155
|
-
|
|
156
|
-
|
|
206
|
+
// The template of the units of the worker of the project at <racine>.
|
|
207
|
+
const gabaritDuProjet = (racine) => `grillhouse-travailleur-${nomDuProjet(racine)}@.service`;
|
|
157
208
|
/** The task queue of the worker of the project at <racine>. */
|
|
158
209
|
export const fileDuProjet = (racine) => `grillhouse-projet-${nomDuProjet(racine)}`;
|
|
159
|
-
/** The
|
|
210
|
+
/** The two templates of the workers, each with its task queue: the project's, the machine's. */
|
|
211
|
+
export const gabaritsDe = (racine) => [
|
|
212
|
+
{ gabarit: gabaritDuProjet(racine), file: fileDuProjet(racine) },
|
|
213
|
+
{ gabarit: GABARIT_DE_LA_MACHINE, file: FILE_DE_LA_MACHINE },
|
|
214
|
+
];
|
|
215
|
+
/** The three unit files, in their order: the server, the templates of the project and the machine. */
|
|
160
216
|
export const unitesDe = (racine) => [
|
|
161
217
|
UNITE_DU_SERVEUR,
|
|
162
|
-
|
|
163
|
-
UNITE_DE_LA_MACHINE,
|
|
218
|
+
...gabaritsDe(racine).map(g => g.gabarit),
|
|
164
219
|
];
|
|
220
|
+
/**
|
|
221
|
+
* The instances of the template <gabarit> among the units applied at the places <lieux>, each with
|
|
222
|
+
* the version it names.
|
|
223
|
+
*/
|
|
224
|
+
export function instancesAppliquees(lieux, gabarit, epingle = EPINGLE) {
|
|
225
|
+
return instancesDe(lireLesAppliquees(cheminsDe(lieux, epingle.version).appliquees), gabarit);
|
|
226
|
+
}
|
|
227
|
+
// The instances of <gabarit> among the units of <appliquees>.
|
|
228
|
+
function instancesDe(appliquees, gabarit) {
|
|
229
|
+
const prefixe = gabarit.slice(0, -'.service'.length);
|
|
230
|
+
return Object.keys(appliquees)
|
|
231
|
+
.filter(u => u.startsWith(prefixe) && u.endsWith('.service'))
|
|
232
|
+
.map(unite => ({ unite, version: unite.slice(prefixe.length, -'.service'.length) }))
|
|
233
|
+
.filter(i => i.version !== '');
|
|
234
|
+
}
|
|
165
235
|
// An argument of ExecStart, quoted as systemd reads it when it holds a space or a quote.
|
|
166
236
|
const arg = (s) => (/[\s"\\]/.test(s) ? `"${s.replace(/["\\]/g, c => `\\${c}`)}"` : s);
|
|
167
237
|
/** The text of each unit of the account, by its file's name. */
|
|
168
|
-
export function textesDesUnites(lieux, { version, node,
|
|
238
|
+
export function textesDesUnites(lieux, { version, node, chemin, outils }) {
|
|
169
239
|
const { programme, donnees } = cheminsDe(lieux, version);
|
|
170
240
|
const serveur = [
|
|
171
241
|
programme,
|
|
@@ -207,6 +277,8 @@ export function textesDesUnites(lieux, { version, node, travailleur, chemin, out
|
|
|
207
277
|
'',
|
|
208
278
|
].join('\n');
|
|
209
279
|
const apres = [`After=${UNITE_DU_SERVEUR}`, `Wants=${UNITE_DU_SERVEUR}`];
|
|
280
|
+
// The worker of the version the instance names (%i), from the cache of the home.
|
|
281
|
+
const travailleur = path.join(cacheDesOutils(lieux.maison), '%i', 'node_modules/@roomi-fields/grillhouse', TRAVAILLEUR);
|
|
210
282
|
const travailleurSur = (file) => [
|
|
211
283
|
`WorkingDirectory=${arg(lieux.racine)}`,
|
|
212
284
|
`Environment=TEMPORAL_ADDRESS=127.0.0.1:${PORT_DU_SERVEUR}`,
|
|
@@ -220,29 +292,74 @@ export function textesDesUnites(lieux, { version, node, travailleur, chemin, out
|
|
|
220
292
|
`ExecStart=${serveur.map(arg).join(' ')}`,
|
|
221
293
|
`ExecStartPost=/bin/sh -c ${arg(retenir)}`,
|
|
222
294
|
]),
|
|
223
|
-
[
|
|
224
|
-
[
|
|
295
|
+
[gabaritDuProjet(lieux.racine)]: service(`Grillhouse : le travailleur du projet ${nomDuProjet(lieux.racine)}, version %i`, travailleurSur(fileDuProjet(lieux.racine)), apres),
|
|
296
|
+
[GABARIT_DE_LA_MACHINE]: service('Grillhouse : le travailleur de la machine, version %i', travailleurSur(FILE_DE_LA_MACHINE), apres),
|
|
225
297
|
};
|
|
226
298
|
}
|
|
227
|
-
/** The package that runs: two levels above this module, in src/ as in dist/. */
|
|
228
|
-
const PAQUET = fileURLToPath(new URL('../..', import.meta.url));
|
|
229
299
|
const TRAVAILLEUR = 'dist/temporal/travailleur.js';
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
300
|
+
const PAQUET_INSTALLE = 'node_modules/@roomi-fields/grillhouse';
|
|
301
|
+
// The `version` of the package.json of the folder <paquet>, or null when none reads.
|
|
302
|
+
function versionDuPaquet(paquet) {
|
|
303
|
+
try {
|
|
304
|
+
const v = JSON.parse(readFileSync(path.join(paquet, 'package.json'), 'utf8')).version;
|
|
305
|
+
return typeof v === 'string' && v ? v : null;
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// The version of the frame the project at <racine> installs: its key `grillhouse.outil`, else that
|
|
312
|
+
// of the package it installed; refused without either.
|
|
313
|
+
function versionDuProjet(racine) {
|
|
314
|
+
const cle = versionDeLOutil(racine);
|
|
315
|
+
if (cle !== null) {
|
|
316
|
+
return { version: cle, nommee: true };
|
|
317
|
+
}
|
|
318
|
+
const version = versionDuPaquet(path.join(racine, PAQUET_INSTALLE));
|
|
319
|
+
if (version === null) {
|
|
320
|
+
throw new Error(`temporal : le projet ne nomme aucune version (grillhouse.outil) et ${PAQUET_INSTALLE} n'en déclare aucune ; aucune unité n'est écrite.`);
|
|
321
|
+
}
|
|
322
|
+
return { version, nommee: false };
|
|
323
|
+
}
|
|
324
|
+
// The integrity the first of the lock files <verrous> that gives one gives the frame's package.
|
|
325
|
+
function empreinte(...verrous) {
|
|
326
|
+
for (const f of verrous) {
|
|
327
|
+
try {
|
|
328
|
+
const i = JSON.parse(readFileSync(f, 'utf8')).packages?.[PAQUET_INSTALLE]?.integrity;
|
|
329
|
+
if (typeof i === 'string' && i) {
|
|
330
|
+
return i;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
// absent or unreadable: the next one
|
|
241
335
|
}
|
|
242
|
-
return f;
|
|
243
336
|
}
|
|
244
|
-
|
|
245
|
-
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
// Lays down by <outil> the version the project at <racine> installs, and refuses it, by its name,
|
|
340
|
+
// when it carries no worker or, for a project without the key, when its integrity in the cache is
|
|
341
|
+
// not that of the installed package.
|
|
342
|
+
function poserLaVersionDuProjet(racine, outil) {
|
|
343
|
+
const { version, nommee } = versionDuProjet(racine);
|
|
344
|
+
const nom = `@roomi-fields/grillhouse@${version}`;
|
|
345
|
+
const refuser = (raison) => {
|
|
346
|
+
throw new Error(`temporal : ${nom}, la version que le projet installe, ${raison}.`);
|
|
347
|
+
};
|
|
348
|
+
const installee = nommee ? null : empreinte(path.join(racine, 'package-lock.json'));
|
|
349
|
+
if (!nommee && installee === null) {
|
|
350
|
+
refuser('n’a aucune empreinte (integrity) au fichier de verrou du projet : un paquet lié, une archive locale ou une version non publiée n’installe aucune unité');
|
|
351
|
+
}
|
|
352
|
+
const dossier = outil(version);
|
|
353
|
+
if (!existsSync(path.join(dossier, PAQUET_INSTALLE, TRAVAILLEUR))) {
|
|
354
|
+
refuser(`ne porte pas de travailleur (${TRAVAILLEUR})`);
|
|
355
|
+
}
|
|
356
|
+
if (!nommee) {
|
|
357
|
+
const posee = empreinte(path.join(dossier, 'package-lock.json'), path.join(dossier, 'node_modules/.package-lock.json'));
|
|
358
|
+
if (posee !== installee) {
|
|
359
|
+
refuser(`a au cache (${dossier}) une empreinte (integrity) ${posee === null ? 'absente' : 'différente'} de celle du paquet installé`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return version;
|
|
246
363
|
}
|
|
247
364
|
/**
|
|
248
365
|
* The PATH of each worker's unit: the folder of Node <node>, then those of the account's tools
|
|
@@ -286,87 +403,49 @@ async function telecharger(url) {
|
|
|
286
403
|
}
|
|
287
404
|
return Buffer.from(await r.arrayBuffer());
|
|
288
405
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
* queue that is not there, or a server that does not answer within 5 s, is a failure, which the
|
|
292
|
-
* installation takes for no queue.
|
|
293
|
-
*/
|
|
294
|
-
function laFileDuServeur() {
|
|
406
|
+
// The Worker Deployments of the account's server (`deploiementsDuServeur`, ./client.ts).
|
|
407
|
+
function deploiementsDuCompte() {
|
|
295
408
|
const avec = async (f) => {
|
|
296
|
-
const {
|
|
297
|
-
|
|
298
|
-
let minuteur;
|
|
299
|
-
try {
|
|
300
|
-
return await Promise.race([
|
|
301
|
-
f(ouvert.client),
|
|
302
|
-
new Promise((_, rejet) => {
|
|
303
|
-
minuteur = setTimeout(() => rejet(new Error('le serveur ne répond pas')), 5000);
|
|
304
|
-
}),
|
|
305
|
-
]);
|
|
306
|
-
}
|
|
307
|
-
finally {
|
|
308
|
-
clearTimeout(minuteur);
|
|
309
|
-
await ouvert.fermer().catch(() => undefined);
|
|
310
|
-
}
|
|
409
|
+
const { adresseDuServeur, deploiementsDuServeur } = await import('./client.js');
|
|
410
|
+
return f(deploiementsDuServeur(adresseDuServeur()));
|
|
311
411
|
};
|
|
312
412
|
return {
|
|
313
|
-
|
|
314
|
-
|
|
413
|
+
lire: file => avec(s => s.lire(file)),
|
|
414
|
+
rendreCourante: (file, version) => avec(s => s.rendreCourante(file, version)),
|
|
415
|
+
activitesTenues: () => avec(s => s.activitesTenues()),
|
|
315
416
|
};
|
|
316
417
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
* The version of the tool of the package the worker <travailleur> belongs to: the `version` of its
|
|
321
|
-
* package.json, two levels above the worker's path, the file the queue's activity reads; null when
|
|
322
|
-
* it does not read.
|
|
323
|
-
*/
|
|
324
|
-
function versionInstallee(travailleur) {
|
|
325
|
-
try {
|
|
326
|
-
const v = JSON.parse(readFileSync(path.join(path.resolve(travailleur, '../../..'), 'package.json'), 'utf8')).version;
|
|
327
|
-
return typeof v === 'string' && v ? v : null;
|
|
328
|
-
}
|
|
329
|
-
catch {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
418
|
+
/** What the command writes of a report: its line, then those of the purge of the versions. */
|
|
419
|
+
export function texteDeLInstallation(r) {
|
|
420
|
+
return `${ligneDeLInstallation(r)}${lignesDeLaPurgeDesVersions(r.versions)}`;
|
|
332
421
|
}
|
|
333
|
-
/**
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
avantLeSignal();
|
|
353
|
-
await file.relancer(id);
|
|
354
|
-
const deVersion = `(${ancienne} → ${installee})`;
|
|
355
|
-
return {
|
|
356
|
-
file: vue.enCours === null
|
|
357
|
-
? `repartie ${deVersion}`
|
|
358
|
-
: `repart après l'entrée de ${vue.enCours} ${deVersion}`,
|
|
359
|
-
...versions,
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
catch {
|
|
363
|
-
return { file: AUCUNE_FILE };
|
|
364
|
-
}
|
|
422
|
+
/** The exit code of an installation: 1 when the purge could not read a source or remove a version. */
|
|
423
|
+
export const codeDeLInstallation = (r) => r.versions.illisibles.length || r.versions.echecs.length ? 1 : 0;
|
|
424
|
+
const REJOUER = 'à rejouer : npx grillhouse temporal installer';
|
|
425
|
+
// The lines of the purge of the versions: each version removed with the place it gave back, each
|
|
426
|
+
// version kept with what names it, each source unread and each removal failed.
|
|
427
|
+
function lignesDeLaPurgeDesVersions(p) {
|
|
428
|
+
const mo = (octets) => `${(octets / 1024 / 1024).toFixed(1).replace('.', ',')} Mo`;
|
|
429
|
+
return [
|
|
430
|
+
...p.retirees.map(v => {
|
|
431
|
+
const quoi = v.reste ? 'restes d’un retrait de la version' : 'version';
|
|
432
|
+
return `purge : ${quoi} ${v.version} ${v.reste ? 'retirés' : 'retirée'}, ${mo(v.octets)} rendus`;
|
|
433
|
+
}),
|
|
434
|
+
...p.gardees.map(v => `purge : version ${v.version} gardée : ${v.raisons.join(' ; ')}`),
|
|
435
|
+
...p.illisibles.map(l => `purge : ${l} ; ${REJOUER}`),
|
|
436
|
+
...p.echecs.map(e => `purge : le retrait de la version ${e.version} échoue (${enUneLigne(e.raison)}) ; ${REJOUER}`),
|
|
437
|
+
]
|
|
438
|
+
.map(l => `${l}\n`)
|
|
439
|
+
.join('');
|
|
365
440
|
}
|
|
366
|
-
|
|
367
|
-
|
|
441
|
+
// The line of the installation itself.
|
|
442
|
+
function ligneDeLInstallation(r) {
|
|
443
|
+
const liste = (titre, unites) => unites.length ? ` ; ${titre} : ${unites.join(', ')}` : '';
|
|
444
|
+
const retenues = liste('retenues par une activité en cours', r.retenues);
|
|
445
|
+
const { copies, deplaces, conflits } = r.complements;
|
|
446
|
+
const chemins = (titre, c, entre = ' → ') => liste(titre, c.map(({ depart, arrivee }) => `${depart}${entre}${arrivee}`));
|
|
368
447
|
if (!r.change) {
|
|
369
|
-
return
|
|
448
|
+
return `temporal : l’installation est à jour, rien ne change${retenues}.\n`;
|
|
370
449
|
}
|
|
371
450
|
return (`temporal : ${r.pose ? 'programme posé' : 'programme à jour'} (${r.programme}) ; ` +
|
|
372
451
|
`unités écrites : ${r.unites.join(', ') || 'aucune'} ; ` +
|
|
@@ -377,7 +456,14 @@ export function texteDeLInstallation(r) {
|
|
|
377
456
|
(r.serveurDiffere
|
|
378
457
|
? ` ; l'unité du serveur attend, le serveur n'étant ni arrêté ni compacté : circuits en vol (${r.serveurDiffere.join(', ')}), à rejouer quand ils sont arrêtés`
|
|
379
458
|
: '') +
|
|
380
|
-
|
|
459
|
+
liste('instances démarrées', r.demarrees) +
|
|
460
|
+
liste('rendues courantes', r.courantes) +
|
|
461
|
+
liste('retirées', r.retirees) +
|
|
462
|
+
retenues +
|
|
463
|
+
chemins('compléments copiés', copies.filter(c => !deplaces.some(d => d.depart === c.depart))) +
|
|
464
|
+
chemins('compléments déplacés', deplaces) +
|
|
465
|
+
chemins('compléments en conflit, laissés chacun à sa place', conflits, ' et ') +
|
|
466
|
+
liste('en marche sous l’ancien texte de leur gabarit', r.sousLAncienTexte) +
|
|
381
467
|
'.\n');
|
|
382
468
|
}
|
|
383
469
|
// Opens the database file <base> of the server by the runtime's `node:sqlite`, no tool of the PATH.
|
|
@@ -463,12 +549,13 @@ function retirerLesOrphelins(base) {
|
|
|
463
549
|
* <programme>, the workflows `circuitDuTicket` Running (their id `circuit:<racine>:<ticket>`). A
|
|
464
550
|
* server that does not answer, or an answer that does not read, is no circuit in flight.
|
|
465
551
|
*/
|
|
466
|
-
function circuitsEnVolDuServeur(programme) {
|
|
552
|
+
async function circuitsEnVolDuServeur(programme) {
|
|
553
|
+
const { adresseDuServeur } = await import('./client.js');
|
|
467
554
|
const r = spawnSync(programme, [
|
|
468
555
|
'workflow',
|
|
469
556
|
'list',
|
|
470
557
|
'--address',
|
|
471
|
-
|
|
558
|
+
adresseDuServeur(),
|
|
472
559
|
'--query',
|
|
473
560
|
"WorkflowType='circuitDuTicket' AND ExecutionStatus='Running'",
|
|
474
561
|
'--output',
|
|
@@ -565,12 +652,12 @@ function lireLesAppliquees(f) {
|
|
|
565
652
|
* `installer` and by the detection of a stale worker. Every refusal of the tools (an account's
|
|
566
653
|
* tool not found, a fault of `grillhouse.outils`) is thrown here, before any writing.
|
|
567
654
|
*/
|
|
568
|
-
function textesAttendus({ lieux, epingle = EPINGLE, node = process.execPath, trouver = nom => trouverDansLePath(nom),
|
|
655
|
+
function textesAttendus({ lieux, declarations = lieux.racine, epingle = EPINGLE, node = process.execPath, trouver = nom => trouverDansLePath(nom), }) {
|
|
569
656
|
const { programme } = cheminsDe(lieux, epingle.version);
|
|
570
|
-
const executables = langagesDe(
|
|
657
|
+
const executables = langagesDe(declarations).flatMap(m => m.executables);
|
|
571
658
|
const chemin = cheminDesUnites(node, trouver, executables);
|
|
572
659
|
const pkg = JSON.parse(readFileSync(path.join(lieux.racine, 'package.json'), 'utf8'));
|
|
573
|
-
// The tools as written, without a TEMPORAL key left in the package.json: the
|
|
660
|
+
// The tools as written, without a TEMPORAL key left in the package.json: the workers' templates take
|
|
574
661
|
// the program laid down. A faulty value is refused as it is written.
|
|
575
662
|
const brut = pkg.grillhouse?.outils;
|
|
576
663
|
const { outils: lus, fautes } = lireOutils({
|
|
@@ -589,7 +676,6 @@ function textesAttendus({ lieux, epingle = EPINGLE, node = process.execPath, tro
|
|
|
589
676
|
const textes = textesDesUnites(lieux, {
|
|
590
677
|
version: epingle.version,
|
|
591
678
|
node,
|
|
592
|
-
travailleur: travailleur(),
|
|
593
679
|
chemin,
|
|
594
680
|
outils,
|
|
595
681
|
});
|
|
@@ -612,19 +698,14 @@ function travailleurDeLUnite(texte) {
|
|
|
612
698
|
// (`…/<version>/node_modules/@roomi-fields/grillhouse/…`); null when neither reads.
|
|
613
699
|
function versionDuTravailleur(travailleur) {
|
|
614
700
|
const paquet = path.resolve(travailleur, '../../..');
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (typeof v === 'string' && v) {
|
|
619
|
-
return v;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
catch {
|
|
623
|
-
// no package.json: the folder of the published version
|
|
701
|
+
const v = versionDuPaquet(paquet);
|
|
702
|
+
if (v !== null) {
|
|
703
|
+
return v;
|
|
624
704
|
}
|
|
705
|
+
const cache = `${path.sep}node_modules${path.sep}@roomi-fields${path.sep}grillhouse`;
|
|
625
706
|
if (paquet.endsWith(cache)) {
|
|
626
|
-
const
|
|
627
|
-
return /^\d+\.\d+\.\d+/.test(
|
|
707
|
+
const d = path.basename(paquet.slice(0, -cache.length));
|
|
708
|
+
return /^\d+\.\d+\.\d+/.test(d) ? d : null;
|
|
628
709
|
}
|
|
629
710
|
return null;
|
|
630
711
|
}
|
|
@@ -653,43 +734,50 @@ function racineDeLUnite(texte) {
|
|
|
653
734
|
const v = ligne.slice('WorkingDirectory='.length);
|
|
654
735
|
return /^".*"$/.test(v) ? v.slice(1, -1).replace(/\\(.)/g, '$1') : v;
|
|
655
736
|
}
|
|
737
|
+
// The highest version the account installed on the machine, read without the server: of the
|
|
738
|
+
// versions the applied instances of the machine name and, while it stands, of the worker of the unit
|
|
739
|
+
// of before the template; null without any.
|
|
740
|
+
function plusHauteDeLaMachine(lieux, appliquees) {
|
|
741
|
+
const versions = instancesDe(appliquees, GABARIT_DE_LA_MACHINE).map(i => i.version);
|
|
742
|
+
const f = path.join(lieux.unites, uniteDAvant(GABARIT_DE_LA_MACHINE));
|
|
743
|
+
if (existsSync(f)) {
|
|
744
|
+
const t = travailleurDeLUnite(readFileSync(f, 'utf8'));
|
|
745
|
+
const v = t === null ? null : versionDuTravailleur(t);
|
|
746
|
+
if (v !== null) {
|
|
747
|
+
versions.push(v);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
return versions.reduce((h, v) => (h === null || auMoins(v, h) ? v : h), null);
|
|
751
|
+
}
|
|
656
752
|
/**
|
|
657
|
-
* The texts of <textes> the project at <lieux
|
|
658
|
-
* machine while
|
|
659
|
-
* project, as one agent of a cluster serves every job;
|
|
660
|
-
* it (its WorkingDirectory), which answers for its whole text (Node,
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
* it belongs to is gone. So the worker of the machine plays the highest version a project of the
|
|
664
|
-
* account installed, whatever the order of the installations.
|
|
753
|
+
* The texts of <textes> the project at <lieux>, which installs <version>, answers for: the server,
|
|
754
|
+
* its own template, and the template of the machine while it is its own. The template of the machine
|
|
755
|
+
* is the account's, one for every project, as one agent of a cluster serves every job; it belongs
|
|
756
|
+
* to the project that wrote it (its WorkingDirectory), which answers for its whole text (Node,
|
|
757
|
+
* PATH, tools). Another project takes it only to raise the version the machine plays (<plusHaute>),
|
|
758
|
+
* or once the project it belongs to is gone.
|
|
665
759
|
*/
|
|
666
|
-
function textesDuProjet(lieux, textes) {
|
|
667
|
-
const f = path.join(lieux.unites,
|
|
760
|
+
function textesDuProjet(lieux, textes, version, plusHaute) {
|
|
761
|
+
const f = path.join(lieux.unites, GABARIT_DE_LA_MACHINE);
|
|
668
762
|
if (!existsSync(f)) {
|
|
669
763
|
return textes;
|
|
670
764
|
}
|
|
671
|
-
const
|
|
672
|
-
const racine = racineDeLUnite(posee);
|
|
765
|
+
const racine = racineDeLUnite(readFileSync(f, 'utf8'));
|
|
673
766
|
if (racine === null || path.resolve(racine) === lieux.racine || !existsSync(racine)) {
|
|
674
767
|
return textes;
|
|
675
768
|
}
|
|
676
|
-
|
|
677
|
-
const t = travailleurDeLUnite(texte);
|
|
678
|
-
return t === null ? null : versionDuTravailleur(t);
|
|
679
|
-
};
|
|
680
|
-
const [tenue, voulue] = [version(posee), version(textes[UNITE_DE_LA_MACHINE] ?? '')];
|
|
681
|
-
if (tenue === null || voulue === null || !auMoins(tenue, voulue)) {
|
|
769
|
+
if (plusHaute === null || !auMoins(plusHaute, version)) {
|
|
682
770
|
return textes;
|
|
683
771
|
}
|
|
684
|
-
return Object.fromEntries(Object.entries(textes).filter(([n]) => n !==
|
|
772
|
+
return Object.fromEntries(Object.entries(textes).filter(([n]) => n !== GABARIT_DE_LA_MACHINE));
|
|
685
773
|
}
|
|
686
774
|
/**
|
|
687
|
-
* Whether the worker the account runs is stale:
|
|
688
|
-
* unites-appliquees.json)
|
|
689
|
-
* `grillhouse.outil
|
|
690
|
-
* laid down
|
|
691
|
-
*
|
|
692
|
-
*
|
|
775
|
+
* Whether the worker the account runs is stale: a unit applied by `installer` (the sums of
|
|
776
|
+
* unites-appliquees.json) differs from the text `installer` would write now, or the instance of the
|
|
777
|
+
* version the project installs (`grillhouse.outil`, else its installed package) is not among them;
|
|
778
|
+
* nothing laid down. Without an applied state, false: the initial deployment is not a rise. Any
|
|
779
|
+
* error of the computation (a tool not found) is stale, as `installer` refuses it by its name. It
|
|
780
|
+
* plays nothing and writes nothing.
|
|
693
781
|
*/
|
|
694
782
|
export function travailleurPerime({ lieux, epingle = EPINGLE, node, trouver, }) {
|
|
695
783
|
const deja = lireLesAppliquees(cheminsDe(lieux, epingle.version).appliquees);
|
|
@@ -697,14 +785,11 @@ export function travailleurPerime({ lieux, epingle = EPINGLE, node, trouver, })
|
|
|
697
785
|
return false;
|
|
698
786
|
}
|
|
699
787
|
try {
|
|
700
|
-
const { textes } = textesAttendus({
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
travailleur: () => travailleurDe(lieux.racine, v => path.join(cacheDesOutils(lieux.maison), v), false),
|
|
706
|
-
});
|
|
707
|
-
return Object.entries(textesDuProjet(lieux, textes)).some(([n, t]) => deja[n] !== sommeDe(t));
|
|
788
|
+
const { textes } = textesAttendus({ lieux, epingle, node, trouver });
|
|
789
|
+
const { version } = versionDuProjet(lieux.racine);
|
|
790
|
+
const duProjet = textesDuProjet(lieux, textes, version, plusHauteDeLaMachine(lieux, deja));
|
|
791
|
+
return (!(instanceDe(gabaritDuProjet(lieux.racine), version) in deja) ||
|
|
792
|
+
Object.entries(duProjet).some(([n, t]) => deja[n] !== sommeDe(t)));
|
|
708
793
|
}
|
|
709
794
|
catch {
|
|
710
795
|
return true;
|
|
@@ -728,8 +813,8 @@ function serveurArrete(systemctl, jouer, geste, suite) {
|
|
|
728
813
|
* not answer within 30 s is a failure.
|
|
729
814
|
*/
|
|
730
815
|
async function compterSurLeServeur(requete) {
|
|
731
|
-
const { ouvrirLeClient } = await import('./client.js');
|
|
732
|
-
const ouvert = ouvrirLeClient({ adresse:
|
|
816
|
+
const { adresseDuServeur, ouvrirLeClient } = await import('./client.js');
|
|
817
|
+
const ouvert = ouvrirLeClient({ adresse: adresseDuServeur(), espace: 'default' });
|
|
733
818
|
try {
|
|
734
819
|
const { client } = ouvert;
|
|
735
820
|
return await client.connection.withDeadline(Date.now() + 30_000, async () => {
|
|
@@ -764,23 +849,24 @@ export function texteDeLaPurge(r) {
|
|
|
764
849
|
*/
|
|
765
850
|
export async function purger({ lieux, systemctl, epingle = EPINGLE, circuitsEnVol = () => circuitsEnVolDuServeur(cheminsDe(lieux, epingle.version).programme), compter = compterSurLeServeur, temporal = jouerTemporal, retirer = retirerLesOrphelins, compacter = compacterLaBase, maintenant = Date.now, attendre = ms => new Promise(fin => setTimeout(fin, ms)), }) {
|
|
766
851
|
const { programme, donnees } = cheminsDe(lieux, epingle.version);
|
|
767
|
-
const refuserSousUnVol = (suite) => {
|
|
768
|
-
const vols = circuitsEnVol();
|
|
852
|
+
const refuserSousUnVol = async (suite) => {
|
|
853
|
+
const vols = await circuitsEnVol();
|
|
769
854
|
if (vols.length) {
|
|
770
855
|
throw new Error(`temporal : circuits en vol (${vols.join(', ')}) ; ${suite}, à rejouer quand ils sont arrêtés.`);
|
|
771
856
|
}
|
|
772
857
|
};
|
|
773
|
-
refuserSousUnVol('rien n’est purgé');
|
|
858
|
+
await refuserSousUnVol('rien n’est purgé');
|
|
774
859
|
// One cutoff for the whole purge: what closes meanwhile stays within the retention.
|
|
775
860
|
const limite = new Date(maintenant() - RETENTION_EN_HEURES * 3_600_000).toISOString();
|
|
776
861
|
const requete = `ExecutionStatus != 'Running' AND CloseTime < '${limite}'`;
|
|
777
862
|
const supprimes = await compter(requete);
|
|
778
863
|
if (supprimes > 0) {
|
|
864
|
+
const { adresseDuServeur } = await import('./client.js');
|
|
779
865
|
const r = temporal(programme, [
|
|
780
866
|
'workflow',
|
|
781
867
|
'delete',
|
|
782
868
|
'--address',
|
|
783
|
-
|
|
869
|
+
adresseDuServeur(),
|
|
784
870
|
'--namespace',
|
|
785
871
|
'default',
|
|
786
872
|
'--query',
|
|
@@ -809,7 +895,7 @@ export async function purger({ lieux, systemctl, epingle = EPINGLE, circuitsEnVo
|
|
|
809
895
|
if (!existsSync(donnees)) {
|
|
810
896
|
return { supprimes };
|
|
811
897
|
}
|
|
812
|
-
refuserSousUnVol('la suppression est faite, ni les orphelins retirés ni la base compactée');
|
|
898
|
+
await refuserSousUnVol('la suppression est faite, ni les orphelins retirés ni la base compactée');
|
|
813
899
|
let geste = `le retrait des historiques orphelins de la base ${donnees}`;
|
|
814
900
|
const retrait = serveurArrete(systemctl, () => {
|
|
815
901
|
const { orphelins, avant } = retirer(donnees);
|
|
@@ -819,34 +905,511 @@ export async function purger({ lieux, systemctl, epingle = EPINGLE, circuitsEnVo
|
|
|
819
905
|
systemd(systemctl, ['start', UNITE_DU_SERVEUR]);
|
|
820
906
|
return { supprimes, ...retrait };
|
|
821
907
|
}
|
|
822
|
-
|
|
823
|
-
|
|
908
|
+
// Whether the unit <unite> runs.
|
|
909
|
+
const tourne = (systemctl, unite) => systemctl(['is-active', unite]).stdout.trim() === 'active';
|
|
910
|
+
// A reading of the server, or null when it does not answer.
|
|
911
|
+
const lu = (lecture) => lecture.catch(() => null);
|
|
912
|
+
// Whether the process of the unit <unite> holds one of the activities <tenues>, by the identity a
|
|
913
|
+
// worker takes from the SDK (`<pid>@<host>`).
|
|
914
|
+
function tientUneActivite(systemctl, unite, tenues) {
|
|
915
|
+
const pid = Number(systemctl(['show', '--property=MainPID', '--value', unite]).stdout.trim());
|
|
916
|
+
return pid > 0 && tenues.includes(`${pid}@${os.hostname()}`);
|
|
917
|
+
}
|
|
918
|
+
// The drop-ins of the unit of before the template <gabarit>, each with its path in the folder of
|
|
919
|
+
// that unit (`depart`) and in the folder of the template (`arrivee`).
|
|
920
|
+
function complementsDe(lieux, gabarit) {
|
|
921
|
+
const depart = path.join(lieux.unites, `${uniteDAvant(gabarit)}.d`);
|
|
922
|
+
const arrivee = path.join(lieux.unites, `${gabarit}.d`);
|
|
923
|
+
if (!existsSync(depart)) {
|
|
924
|
+
return [];
|
|
925
|
+
}
|
|
926
|
+
return readdirSync(depart, { withFileTypes: true })
|
|
927
|
+
.filter(f => f.name.endsWith('.conf') && !f.isDirectory())
|
|
928
|
+
.map(f => ({ depart: path.join(depart, f.name), arrivee: path.join(arrivee, f.name) }))
|
|
929
|
+
.sort((a, b) => a.depart.localeCompare(b.depart));
|
|
930
|
+
}
|
|
931
|
+
const memeContenu = ({ depart, arrivee }) => readFileSync(depart).equals(readFileSync(arrivee));
|
|
932
|
+
// Copies to the folder of the template the drop-ins of each unit of before the template that stands,
|
|
933
|
+
// among the templates this pass plays. A file is laid down whole, by a rename: a copy cut short is
|
|
934
|
+
// never taken for another drop-in of the same name. A name already there is never overwritten.
|
|
935
|
+
function copierLesComplements(lieux, joueLaMachine) {
|
|
936
|
+
const copies = [];
|
|
937
|
+
const conflits = [];
|
|
938
|
+
for (const { gabarit, file } of gabaritsDe(lieux.racine)) {
|
|
939
|
+
if ((file === FILE_DE_LA_MACHINE && !joueLaMachine) ||
|
|
940
|
+
!existsSync(path.join(lieux.unites, uniteDAvant(gabarit)))) {
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
for (const c of complementsDe(lieux, gabarit)) {
|
|
944
|
+
if (existsSync(c.arrivee)) {
|
|
945
|
+
if (!memeContenu(c)) {
|
|
946
|
+
conflits.push(c);
|
|
947
|
+
}
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
mkdirSync(path.dirname(c.arrivee), { recursive: true });
|
|
951
|
+
const partiel = `${c.arrivee}.partiel`;
|
|
952
|
+
writeFileSync(partiel, readFileSync(c.depart));
|
|
953
|
+
renameSync(partiel, c.arrivee);
|
|
954
|
+
copies.push(c);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return { copies, conflits };
|
|
958
|
+
}
|
|
959
|
+
// Removes the former drop-ins of the unit of before the template <gabarit> whose copy the folder of
|
|
960
|
+
// the template holds, then their folder once empty; those it removed.
|
|
961
|
+
function retirerLesComplements(lieux, gabarit) {
|
|
962
|
+
const deplaces = complementsDe(lieux, gabarit).filter(c => existsSync(c.arrivee) && memeContenu(c));
|
|
963
|
+
for (const { depart } of deplaces) {
|
|
964
|
+
rmSync(depart);
|
|
965
|
+
}
|
|
966
|
+
const dossier = path.join(lieux.unites, `${uniteDAvant(gabarit)}.d`);
|
|
967
|
+
if (existsSync(dossier) && readdirSync(dossier).length === 0) {
|
|
968
|
+
rmdirSync(dossier);
|
|
969
|
+
}
|
|
970
|
+
return deplaces;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Stops, disables and removes from the units applied each instance that may leave, then the units of
|
|
974
|
+
* before the template with their drop-ins (see the header); the units retired, those a started
|
|
975
|
+
* activity retains, and the drop-ins moved.
|
|
976
|
+
*/
|
|
977
|
+
async function retirerLesInstances({ lieux, systemctl, serveur, version, joueLaMachine, appliquees, enregistrer, }) {
|
|
978
|
+
const retirees = [];
|
|
979
|
+
const retenues = [];
|
|
980
|
+
const deplaces = [];
|
|
981
|
+
let tenues;
|
|
982
|
+
// Retires <unite> unless its process holds an activity; kept when the server does not say them.
|
|
983
|
+
// A unit of before the template names its template and its file.
|
|
984
|
+
const retirer = async (unite, davant) => {
|
|
985
|
+
const activites = await (tenues ??= lu(serveur.activitesTenues()));
|
|
986
|
+
if (activites === null) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
if (tientUneActivite(systemctl, unite, activites)) {
|
|
990
|
+
retenues.push(unite);
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
systemd(systemctl, ['disable', '--now', unite]);
|
|
994
|
+
if (davant) {
|
|
995
|
+
// The drop-ins first: a failure leaves the file, which the next pass retires.
|
|
996
|
+
deplaces.push(...retirerLesComplements(lieux, davant.gabarit));
|
|
997
|
+
rmSync(davant.fichier, { force: true });
|
|
998
|
+
}
|
|
999
|
+
delete appliquees[unite];
|
|
1000
|
+
enregistrer();
|
|
1001
|
+
retirees.push(unite);
|
|
1002
|
+
};
|
|
1003
|
+
for (const { gabarit, file } of gabaritsDe(lieux.racine)) {
|
|
1004
|
+
const autres = instancesDe(appliquees, gabarit).filter(i => i.version !== version);
|
|
1005
|
+
const deploiement = autres.length ? await lu(serveur.lire(file)) : null;
|
|
1006
|
+
if (deploiement === null) {
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
const { courante, versions } = deploiement;
|
|
1010
|
+
for (const i of autres) {
|
|
1011
|
+
const etat = versions[i.version];
|
|
1012
|
+
// On the queue of the machine, a version never current leaves only when it is lower than the
|
|
1013
|
+
// current one: a higher one is a rise another project still has to make current.
|
|
1014
|
+
const jamais = etat === 'jamais-courante' &&
|
|
1015
|
+
(file !== FILE_DE_LA_MACHINE || (courante !== null && !auMoins(i.version, courante)));
|
|
1016
|
+
if (i.version !== courante && (etat === 'drainee' || jamais)) {
|
|
1017
|
+
await retirer(i.unite);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
let fichierRetire = false;
|
|
1022
|
+
for (const { gabarit, file } of gabaritsDe(lieux.racine)) {
|
|
1023
|
+
const unite = uniteDAvant(gabarit);
|
|
1024
|
+
const fichier = path.join(lieux.unites, unite);
|
|
1025
|
+
if ((file === FILE_DE_LA_MACHINE && !joueLaMachine) ||
|
|
1026
|
+
!existsSync(fichier) ||
|
|
1027
|
+
(await lu(serveur.lire(file)))?.courante !== version) {
|
|
1028
|
+
continue;
|
|
1029
|
+
}
|
|
1030
|
+
await retirer(unite, { gabarit, fichier });
|
|
1031
|
+
fichierRetire ||= !existsSync(fichier);
|
|
1032
|
+
}
|
|
1033
|
+
if (fichierRetire) {
|
|
1034
|
+
systemd(systemctl, ['daemon-reload']);
|
|
1035
|
+
}
|
|
1036
|
+
return { retirees, retenues, deplaces };
|
|
1037
|
+
}
|
|
1038
|
+
// The command line of each living process of the machine, from /proc; a process that ends during
|
|
1039
|
+
// the reading has none.
|
|
1040
|
+
function processusDeLaMachine() {
|
|
1041
|
+
return readdirSync('/proc')
|
|
1042
|
+
.filter(n => /^\d+$/.test(n))
|
|
1043
|
+
.flatMap(n => {
|
|
1044
|
+
try {
|
|
1045
|
+
return [readFileSync(`/proc/${n}/cmdline`, 'utf8').split('\0').filter(Boolean)];
|
|
1046
|
+
}
|
|
1047
|
+
catch (e) {
|
|
1048
|
+
if (['ENOENT', 'ESRCH'].includes(e.code ?? '')) {
|
|
1049
|
+
return [];
|
|
1050
|
+
}
|
|
1051
|
+
throw e;
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
// The tickets of the project at <racine> whose circuit the account's server holds.
|
|
1056
|
+
const circuitsTenusDuCompte = async (racine) => {
|
|
1057
|
+
const { adresseDuServeur } = await import('./client.js');
|
|
1058
|
+
return ticketsTenus(racine, { adresse: adresseDuServeur(), espace: 'default' });
|
|
1059
|
+
};
|
|
1060
|
+
// The closed tickets of the project at <racine>, by bd.
|
|
1061
|
+
function ticketsFermesDuProjet(racine) {
|
|
1062
|
+
const fermes = ticketsDuStatut(racine, 'closed');
|
|
1063
|
+
if (fermes === null) {
|
|
1064
|
+
throw new Error('bd list ne répond pas');
|
|
1065
|
+
}
|
|
1066
|
+
return [...fermes];
|
|
1067
|
+
}
|
|
1068
|
+
// A message as one line of the report.
|
|
1069
|
+
const enUneLigne = (e) => (e instanceof Error ? e.message : String(e)).replace(/\s+/g, ' ').trim();
|
|
1070
|
+
// What <lecture> gives, or null when the file or folder is not there; any other fault is thrown.
|
|
1071
|
+
function siLa(lecture) {
|
|
1072
|
+
try {
|
|
1073
|
+
return lecture();
|
|
1074
|
+
}
|
|
1075
|
+
catch (e) {
|
|
1076
|
+
if (['ENOENT', 'ENOTDIR'].includes(e.code ?? '')) {
|
|
1077
|
+
return null;
|
|
1078
|
+
}
|
|
1079
|
+
throw e;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
// The version of the frame the tree at <racine> names: its key, else the package it installed;
|
|
1083
|
+
// null without either; a faulty key is thrown.
|
|
1084
|
+
const versionNommee = (racine) => versionDeLOutil(racine) ?? versionDuPaquet(path.join(racine, PAQUET_INSTALLE));
|
|
1085
|
+
// Whether the folder <dossier> stands in a git repository.
|
|
1086
|
+
function sousGit(dossier) {
|
|
1087
|
+
return (existsSync(path.join(dossier, '.git')) ||
|
|
1088
|
+
(path.dirname(dossier) !== dossier && sousGit(path.dirname(dossier))));
|
|
1089
|
+
}
|
|
1090
|
+
// The units of the account: the versions they name, and the projects of the machine, the pass's
|
|
1091
|
+
// own and those the worker units lead to, while their folder stands.
|
|
1092
|
+
function lireLesUnites(lieux, appliquees, versionsDans, { nommer, bloquer }) {
|
|
1093
|
+
const racines = new Set([lieux.racine]);
|
|
1094
|
+
try {
|
|
1095
|
+
const texte = siLa(() => readFileSync(appliquees, 'utf8'));
|
|
1096
|
+
for (const unite of Object.keys(JSON.parse(texte ?? '{}'))) {
|
|
1097
|
+
const v = /@(.+)\.service$/.exec(unite)?.[1];
|
|
1098
|
+
if (v) {
|
|
1099
|
+
nommer(v, `unité appliquée ${unite}`);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
catch (e) {
|
|
1104
|
+
bloquer(`les unités appliquées (${appliquees}) ne se lisent pas (${enUneLigne(e)})`);
|
|
1105
|
+
}
|
|
1106
|
+
try {
|
|
1107
|
+
for (const f of siLa(() => readdirSync(lieux.unites, { withFileTypes: true })) ?? []) {
|
|
1108
|
+
if (f.isDirectory() || !f.name.endsWith('.service')) {
|
|
1109
|
+
continue;
|
|
1110
|
+
}
|
|
1111
|
+
const texte = siLa(() => readFileSync(path.join(lieux.unites, f.name), 'utf8'));
|
|
1112
|
+
if (texte === null) {
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
for (const v of versionsDans(texte.replace(/\\(.)/g, '$1'))) {
|
|
1116
|
+
nommer(v, `fichier d'unité ${f.name}`);
|
|
1117
|
+
}
|
|
1118
|
+
const racine = f.name.startsWith('grillhouse-travailleur-') ? racineDeLUnite(texte) : null;
|
|
1119
|
+
if (racine !== null) {
|
|
1120
|
+
racines.add(racine);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
catch (e) {
|
|
1125
|
+
bloquer(`les unités du compte (${lieux.unites}) ne se lisent pas (${enUneLigne(e)})`);
|
|
1126
|
+
}
|
|
1127
|
+
return [...racines].filter(racine => {
|
|
1128
|
+
try {
|
|
1129
|
+
return siLa(() => statSync(racine)) !== null;
|
|
1130
|
+
}
|
|
1131
|
+
catch (e) {
|
|
1132
|
+
bloquer(`le projet ${racine} ne se lit pas (${enUneLigne(e)})`);
|
|
1133
|
+
return false;
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
// The versions the copies of a circuit not finished name, among the copies of the project at
|
|
1138
|
+
// <racine>.
|
|
1139
|
+
async function lireLesCopies(racine, { circuitsTenus, ticketsFermes }, { nommer, bloquer, signaler }) {
|
|
1140
|
+
let copies;
|
|
1141
|
+
try {
|
|
1142
|
+
copies = sousGit(racine)
|
|
1143
|
+
? copiesListees(racine)
|
|
1144
|
+
.slice(1)
|
|
1145
|
+
.map(c => c.chemin)
|
|
1146
|
+
: [];
|
|
1147
|
+
}
|
|
1148
|
+
catch (e) {
|
|
1149
|
+
bloquer(`les copies du projet ${racine} ne se listent pas (${enUneLigne(e)})`);
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
if (!copies.length) {
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
let tenus;
|
|
1156
|
+
try {
|
|
1157
|
+
tenus = await circuitsTenus(racine);
|
|
1158
|
+
}
|
|
1159
|
+
catch (e) {
|
|
1160
|
+
bloquer(`le serveur Temporal ne dit pas les circuits qu'il tient du projet ${racine} (${enUneLigne(e)})`);
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
let fermes;
|
|
1164
|
+
const estFerme = (ticket) => {
|
|
1165
|
+
if (!fermes) {
|
|
1166
|
+
try {
|
|
1167
|
+
fermes = new Set(ticketsFermes(racine));
|
|
1168
|
+
}
|
|
1169
|
+
catch (e) {
|
|
1170
|
+
fermes = new Set();
|
|
1171
|
+
signaler(`les tickets du projet ${racine} ne se lisent pas (${enUneLigne(e)}), ses copies au dossier .travail gardent leurs versions`);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
return fermes.has(ticket);
|
|
1175
|
+
};
|
|
1176
|
+
for (const copie of copies) {
|
|
1177
|
+
const ticket = path.basename(copie);
|
|
1178
|
+
if (!tenus.includes(ticket) && !(existsSync(`${copie}.travail`) && !estFerme(ticket))) {
|
|
1179
|
+
continue;
|
|
1180
|
+
}
|
|
1181
|
+
try {
|
|
1182
|
+
const v = versionNommee(copie);
|
|
1183
|
+
if (v !== null) {
|
|
1184
|
+
nommer(v, `copie ${copie} (ticket ${ticket})`);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
catch (e) {
|
|
1188
|
+
bloquer(`la copie ${copie} du ticket ${ticket} ne dit pas sa version : ${enUneLigne(e)}`);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
// The size of the files under <chemin>, in bytes; what does not read counts for nothing.
|
|
1193
|
+
function tailleDe(chemin) {
|
|
1194
|
+
try {
|
|
1195
|
+
const s = lstatSync(chemin);
|
|
1196
|
+
return s.isDirectory()
|
|
1197
|
+
? readdirSync(chemin).reduce((t, n) => t + tailleDe(path.join(chemin, n)), 0)
|
|
1198
|
+
: s.size;
|
|
1199
|
+
}
|
|
1200
|
+
catch {
|
|
1201
|
+
return 0;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
/** The folder a version leaves under, and the folder of a removal that did not end. */
|
|
1205
|
+
const EN_RETRAIT = /^(\d+\.\d+\.\d+)\.retrait-/;
|
|
1206
|
+
// Removes from the cache <cache> the version <version> (its folder, renamed first, what an
|
|
1207
|
+
// earlier removal left of it, and its failure mark), or, with <restesSeuls>, what an earlier
|
|
1208
|
+
// removal left of a version something names; the size given back.
|
|
1209
|
+
function retirerLaVersion(cache, version, entrees, restesSeuls) {
|
|
1210
|
+
const dossier = path.join(cache, version);
|
|
1211
|
+
const restes = entrees
|
|
1212
|
+
.map(e => e.name)
|
|
1213
|
+
.filter(n => EN_RETRAIT.exec(n)?.[1] === version)
|
|
1214
|
+
.map(n => path.join(cache, n));
|
|
1215
|
+
if (!restesSeuls) {
|
|
1216
|
+
if (existsSync(dossier)) {
|
|
1217
|
+
const ecarte = `${dossier}.retrait-${randomUUID()}`;
|
|
1218
|
+
renameSync(dossier, ecarte);
|
|
1219
|
+
restes.push(ecarte);
|
|
1220
|
+
}
|
|
1221
|
+
rmSync(`${dossier}.echec`, { force: true });
|
|
1222
|
+
}
|
|
1223
|
+
let octets = 0;
|
|
1224
|
+
for (const reste of restes) {
|
|
1225
|
+
const taille = tailleDe(reste);
|
|
1226
|
+
rmSync(reste, { recursive: true, force: true });
|
|
1227
|
+
octets += taille;
|
|
1228
|
+
}
|
|
1229
|
+
return octets;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Removes from the cache of the home each version of the tool nothing names (see the header), as
|
|
1233
|
+
* `brew cleanup` removes the old versions of the installed formulae; its report.
|
|
1234
|
+
*/
|
|
1235
|
+
async function purgerLesVersions({ lieux, appliquees, serveur, processus, circuitsTenus, ticketsFermes, }) {
|
|
1236
|
+
const r = { retirees: [], gardees: [], illisibles: [], echecs: [] };
|
|
1237
|
+
const cache = cacheDesOutils(lieux.maison);
|
|
1238
|
+
const entrees = siLa(() => readdirSync(cache, { withFileTypes: true })) ?? [];
|
|
1239
|
+
// The versions installed or marked, and those an earlier removal left a folder of.
|
|
1240
|
+
const presentes = new Set();
|
|
1241
|
+
const aFinir = new Set();
|
|
1242
|
+
for (const e of entrees) {
|
|
1243
|
+
const v = e.isDirectory() ? e.name : /^(.*)\.echec$/.exec(e.name)?.[1];
|
|
1244
|
+
if (v !== undefined && X_Y_Z.test(v)) {
|
|
1245
|
+
presentes.add(v);
|
|
1246
|
+
}
|
|
1247
|
+
const reste = e.isDirectory() ? EN_RETRAIT.exec(e.name)?.[1] : undefined;
|
|
1248
|
+
if (reste !== undefined) {
|
|
1249
|
+
aFinir.add(reste);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
const raisons = new Map();
|
|
1253
|
+
let bloquee = false;
|
|
1254
|
+
const noms = {
|
|
1255
|
+
nommer: (v, raison) => raisons.set(v, (raisons.get(v) ?? new Set()).add(raison)),
|
|
1256
|
+
bloquer: ligne => {
|
|
1257
|
+
bloquee = true;
|
|
1258
|
+
r.illisibles.push(`${ligne} : aucune version retirée`);
|
|
1259
|
+
},
|
|
1260
|
+
};
|
|
1261
|
+
// The versions of the cache a text names by a path under it, the home as written or resolved.
|
|
1262
|
+
const caches = [...new Set([cache, siLa(() => realpathSync(cache)) ?? cache])];
|
|
1263
|
+
const sousLeCache = new RegExp(`(?:${caches.map(c => c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')})/(\\d+\\.\\d+\\.\\d+)/`, 'g');
|
|
1264
|
+
const versionsDans = (texte) => [...texte.matchAll(sousLeCache)].map(m => m[1]);
|
|
1265
|
+
const racines = lireLesUnites(lieux, appliquees, versionsDans, noms);
|
|
1266
|
+
const files = new Set([FILE_DE_LA_MACHINE]);
|
|
1267
|
+
for (const racine of racines) {
|
|
1268
|
+
files.add(fileDuProjet(racine));
|
|
1269
|
+
try {
|
|
1270
|
+
const v = versionNommee(racine);
|
|
1271
|
+
if (v !== null) {
|
|
1272
|
+
noms.nommer(v, `projet ${racine}`);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
catch (e) {
|
|
1276
|
+
noms.bloquer(`le projet ${racine} ne dit pas sa version : ${enUneLigne(e)}`);
|
|
1277
|
+
}
|
|
1278
|
+
await lireLesCopies(racine, { circuitsTenus, ticketsFermes }, { ...noms, signaler: ligne => r.illisibles.push(ligne) });
|
|
1279
|
+
}
|
|
1280
|
+
try {
|
|
1281
|
+
for (const argv of processus()) {
|
|
1282
|
+
for (const v of argv.flatMap(versionsDans)) {
|
|
1283
|
+
noms.nommer(v, 'processus vivant');
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
catch (e) {
|
|
1288
|
+
noms.bloquer(`la liste des processus ne se lit pas (${enUneLigne(e)})`);
|
|
1289
|
+
}
|
|
1290
|
+
for (const file of files) {
|
|
1291
|
+
try {
|
|
1292
|
+
const { courante, versions } = await serveur.lire(file);
|
|
1293
|
+
for (const [v, etat] of Object.entries(versions)) {
|
|
1294
|
+
if (etat !== 'drainee' && etat !== 'jamais-courante') {
|
|
1295
|
+
noms.nommer(v, `déploiement ${file} (${etat})`);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
if (courante !== null) {
|
|
1299
|
+
noms.nommer(courante, `déploiement ${file} (courante)`);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
catch (e) {
|
|
1303
|
+
noms.bloquer(`le serveur Temporal ne dit pas le déploiement ${file} (${enUneLigne(e)})`);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
for (const version of [...new Set([...presentes, ...aFinir])].sort()) {
|
|
1307
|
+
const nommee = raisons.get(version);
|
|
1308
|
+
if (presentes.has(version) && (nommee || bloquee)) {
|
|
1309
|
+
r.gardees.push({
|
|
1310
|
+
version,
|
|
1311
|
+
raisons: nommee ? [...nommee] : ['une source ne se lit pas'],
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
// What names a version keeps its folder and its mark; what a removal left of it goes.
|
|
1315
|
+
if (bloquee || (nommee && !aFinir.has(version))) {
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
try {
|
|
1319
|
+
const reste = nommee !== undefined;
|
|
1320
|
+
r.retirees.push({ version, reste, octets: retirerLaVersion(cache, version, entrees, reste) });
|
|
1321
|
+
}
|
|
1322
|
+
catch (e) {
|
|
1323
|
+
r.echecs.push({ version, raison: enUneLigne(e) });
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
return r;
|
|
1327
|
+
}
|
|
1328
|
+
// How long a pass waits between two tries of the lock another pass holds.
|
|
1329
|
+
const ENTRE_DEUX_PRISES_MS = 200;
|
|
1330
|
+
/** Installs the account's Temporal at the places <lieux>, one pass at a time (see the header). */
|
|
1331
|
+
export async function installer(options) {
|
|
1332
|
+
const { verrou } = cheminsDe(options.lieux, (options.epingle ?? EPINGLE).version);
|
|
1333
|
+
const dossier = path.dirname(verrou);
|
|
1334
|
+
// The first folder the lock had to create, which a pass that writes nothing else takes back.
|
|
1335
|
+
let cree;
|
|
1336
|
+
for (;;) {
|
|
1337
|
+
cree = mkdirSync(dossier, { recursive: true }) ?? cree;
|
|
1338
|
+
try {
|
|
1339
|
+
if (prendreVerrou(verrou, { attendre: false })) {
|
|
1340
|
+
break;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
catch (e) {
|
|
1344
|
+
// Another pass took back the folder between the two gestures.
|
|
1345
|
+
if (e.code !== 'ENOENT') {
|
|
1346
|
+
throw e;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
await new Promise(fin => setTimeout(fin, ENTRE_DEUX_PRISES_MS));
|
|
1350
|
+
}
|
|
1351
|
+
try {
|
|
1352
|
+
return await jouerLInstallation(options);
|
|
1353
|
+
}
|
|
1354
|
+
finally {
|
|
1355
|
+
lacherVerrou(verrou);
|
|
1356
|
+
if (cree !== undefined) {
|
|
1357
|
+
retirerLesDossiersVides(dossier, cree);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
// Removes <dossier> and its parents up to <premier>, each while it is empty.
|
|
1362
|
+
function retirerLesDossiersVides(dossier, premier) {
|
|
1363
|
+
try {
|
|
1364
|
+
rmdirSync(dossier);
|
|
1365
|
+
}
|
|
1366
|
+
catch {
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
if (dossier !== premier) {
|
|
1370
|
+
retirerLesDossiersVides(path.dirname(dossier), premier);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
// The gestures of one pass of installation, under its lock.
|
|
1374
|
+
async function jouerLInstallation({ lieux, systemctl, epingle = EPINGLE, plateforme = plateformeDe(), obtenir = telecharger, node = process.execPath, outil = v => installerLOutil(v, { cache: cacheDesOutils(lieux.maison) }).dossier, trouver = nom => trouverDansLePath(nom), declarations = lieux.racine, circuitsEnVol = () => circuitsEnVolDuServeur(cheminsDe(lieux, epingle.version).programme), compacter = compacterLaBase, serveur = deploiementsDuCompte(), processus = processusDeLaMachine, circuitsTenus = circuitsTenusDuCompte, ticketsFermes = ticketsFermesDuProjet, }) {
|
|
824
1375
|
const { donnees, appliquees: fichierDesAppliquees } = cheminsDe(lieux, epingle.version);
|
|
825
|
-
// Every refusal before any writing: the archive, the account's tools, the project's tools
|
|
826
|
-
// version down in its cache first.
|
|
1376
|
+
// Every refusal before any writing: the archive, the account's tools, the project's tools, then
|
|
1377
|
+
// the version the project installs, laid down in its cache first.
|
|
827
1378
|
const { programme, contenu } = await obtenirLeProgramme({ lieux, epingle, plateforme, obtenir });
|
|
828
|
-
const { textes: tous } = textesAttendus({
|
|
829
|
-
|
|
830
|
-
epingle,
|
|
831
|
-
node,
|
|
832
|
-
trouver,
|
|
833
|
-
travailleur: () => travailleur ?? travailleurDe(lieux.racine, outil),
|
|
834
|
-
});
|
|
835
|
-
const duProjet = textesDuProjet(lieux, tous);
|
|
1379
|
+
const { textes: tous } = textesAttendus({ lieux, declarations, epingle, node, trouver });
|
|
1380
|
+
const version = poserLaVersionDuProjet(declarations, outil);
|
|
836
1381
|
const deja = lireLesAppliquees(fichierDesAppliquees);
|
|
1382
|
+
const plusHaute = plusHauteDeLaMachine(lieux, deja);
|
|
1383
|
+
const joueLaMachine = plusHaute === null || auMoins(version, plusHaute);
|
|
1384
|
+
const duProjet = textesDuProjet(lieux, tous, version, plusHaute);
|
|
837
1385
|
const enAttenteDe = (t) => Object.keys(t).filter(n => deja[n] !== sommeDe(t[n]));
|
|
838
1386
|
// The server's unit is applied when a program is laid down, or when it is still to apply.
|
|
839
1387
|
// Before any writing: a circuit in flight defers the server's unit alone (its stop, its
|
|
840
1388
|
// compaction), which a later run applies; the program is laid down all the same, in a directory
|
|
841
|
-
// of its own version, and the
|
|
842
|
-
//
|
|
843
|
-
const differe = contenu !== null || enAttenteDe(duProjet).includes(UNITE_DU_SERVEUR)
|
|
1389
|
+
// of its own version, and the templates, which name it, are applied, since neither stops the
|
|
1390
|
+
// server.
|
|
1391
|
+
const differe = contenu !== null || enAttenteDe(duProjet).includes(UNITE_DU_SERVEUR)
|
|
1392
|
+
? await circuitsEnVol()
|
|
1393
|
+
: [];
|
|
844
1394
|
const textes = differe.length
|
|
845
1395
|
? Object.fromEntries(Object.entries(duProjet).filter(([n]) => n !== UNITE_DU_SERVEUR))
|
|
846
1396
|
: duProjet;
|
|
847
1397
|
const pose = contenu !== null;
|
|
848
1398
|
const enAttente = enAttenteDe(textes);
|
|
849
1399
|
const serveurApplique = (pose && differe.length === 0) || enAttente.includes(UNITE_DU_SERVEUR);
|
|
1400
|
+
const appliquees = serveurApplique ? [...new Set([UNITE_DU_SERVEUR, ...enAttente])] : enAttente;
|
|
1401
|
+
// The instances this pass installs, those still to start or to record, and the running ones a
|
|
1402
|
+
// changed template leaves under its former text; read before any gesture.
|
|
1403
|
+
const visees = gabaritsDe(lieux.racine)
|
|
1404
|
+
.filter(g => g.file !== FILE_DE_LA_MACHINE || joueLaMachine)
|
|
1405
|
+
.map(g => ({ ...g, unite: instanceDe(g.gabarit, version) }));
|
|
1406
|
+
const aDemarrer = visees
|
|
1407
|
+
.map(v => ({ ...v, marche: tourne(systemctl, v.unite) }))
|
|
1408
|
+
.filter(v => !v.marche || !(v.unite in deja));
|
|
1409
|
+
const sousLAncienTexte = gabaritsDe(lieux.racine)
|
|
1410
|
+
.filter(g => enAttente.includes(g.gabarit) && g.gabarit in deja)
|
|
1411
|
+
.flatMap(g => instancesDe(deja, g.gabarit).map(i => i.unite))
|
|
1412
|
+
.filter(u => tourne(systemctl, u));
|
|
850
1413
|
if (contenu) {
|
|
851
1414
|
poser(contenu, programme);
|
|
852
1415
|
}
|
|
@@ -861,49 +1424,91 @@ export async function installer({ lieux, systemctl, epingle = EPINGLE, plateform
|
|
|
861
1424
|
writeFileSync(f, texte);
|
|
862
1425
|
unites.push(nom);
|
|
863
1426
|
}
|
|
864
|
-
//
|
|
865
|
-
|
|
866
|
-
const
|
|
1427
|
+
// The sums of this project's units, beside those of the other projects of the account.
|
|
1428
|
+
const sommes = { ...deja };
|
|
1429
|
+
const enregistrer = () => {
|
|
1430
|
+
mkdirSync(path.dirname(fichierDesAppliquees), { recursive: true });
|
|
1431
|
+
writeFileSync(fichierDesAppliquees, `${JSON.stringify(sommes, null, 2)}\n`);
|
|
1432
|
+
};
|
|
1433
|
+
// Before any instance starts, and before systemd reads the units again.
|
|
1434
|
+
const { copies, conflits } = copierLesComplements(lieux, joueLaMachine);
|
|
1435
|
+
if (appliquees.length || copies.length) {
|
|
1436
|
+
systemd(systemctl, ['daemon-reload']);
|
|
1437
|
+
}
|
|
867
1438
|
let compactage;
|
|
868
1439
|
if (appliquees.length) {
|
|
869
|
-
systemd(systemctl, ['daemon-reload']);
|
|
870
|
-
systemd(systemctl, ['enable', ...unitesDe(lieux.racine).filter(n => appliquees.includes(n))]);
|
|
871
1440
|
if (serveurApplique) {
|
|
872
|
-
|
|
873
|
-
//
|
|
1441
|
+
systemd(systemctl, ['enable', UNITE_DU_SERVEUR]);
|
|
1442
|
+
// The server stopped, its database compacted, then started again; without a database file
|
|
1443
|
+
// there is nothing to compact, and the server is not stopped.
|
|
874
1444
|
if (existsSync(donnees)) {
|
|
875
1445
|
compactage = serveurArrete(systemctl, () => compacter(donnees), () => `le compactage de la base ${donnees}`, "l'unité sera appliquée au prochain passage");
|
|
876
1446
|
}
|
|
1447
|
+
systemd(systemctl, ['restart', UNITE_DU_SERVEUR]);
|
|
877
1448
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1449
|
+
for (const n of appliquees) {
|
|
1450
|
+
sommes[n] = sommeDe(textes[n]);
|
|
1451
|
+
}
|
|
1452
|
+
enregistrer();
|
|
1453
|
+
}
|
|
1454
|
+
for (const { gabarit, unite } of aDemarrer) {
|
|
1455
|
+
systemd(systemctl, ['enable', '--now', unite]);
|
|
1456
|
+
// An instance is recorded under the template it started under.
|
|
1457
|
+
sommes[unite] = sommeDe(readFileSync(path.join(lieux.unites, gabarit), 'utf8'));
|
|
1458
|
+
enregistrer();
|
|
886
1459
|
}
|
|
887
|
-
|
|
888
|
-
//
|
|
889
|
-
const
|
|
890
|
-
const { file
|
|
891
|
-
if (
|
|
892
|
-
|
|
1460
|
+
const demarrees = aDemarrer.filter(v => !v.marche).map(v => v.unite);
|
|
1461
|
+
// Current only once its instance started.
|
|
1462
|
+
const courantes = [];
|
|
1463
|
+
for (const { file, unite } of visees) {
|
|
1464
|
+
if ((await lu(serveur.lire(file)))?.courante === version) {
|
|
1465
|
+
continue;
|
|
893
1466
|
}
|
|
1467
|
+
await serveur.rendreCourante(file, version);
|
|
1468
|
+
courantes.push(unite);
|
|
1469
|
+
}
|
|
1470
|
+
const { retirees, retenues, deplaces } = await retirerLesInstances({
|
|
1471
|
+
lieux,
|
|
1472
|
+
systemctl,
|
|
1473
|
+
serveur,
|
|
1474
|
+
version,
|
|
1475
|
+
joueLaMachine,
|
|
1476
|
+
appliquees: sommes,
|
|
1477
|
+
enregistrer,
|
|
1478
|
+
});
|
|
1479
|
+
// The last gesture: the version installed is current and the instances are retired.
|
|
1480
|
+
const versions = await purgerLesVersions({
|
|
1481
|
+
lieux,
|
|
1482
|
+
appliquees: fichierDesAppliquees,
|
|
1483
|
+
serveur,
|
|
1484
|
+
processus,
|
|
1485
|
+
circuitsTenus,
|
|
1486
|
+
ticketsFermes,
|
|
894
1487
|
});
|
|
895
1488
|
return {
|
|
896
1489
|
programme,
|
|
897
1490
|
pose,
|
|
898
1491
|
unites,
|
|
899
1492
|
appliquees,
|
|
1493
|
+
demarrees,
|
|
1494
|
+
courantes,
|
|
1495
|
+
retirees,
|
|
1496
|
+
retenues,
|
|
1497
|
+
sousLAncienTexte,
|
|
1498
|
+
complements: { copies, deplaces, conflits },
|
|
900
1499
|
change: pose ||
|
|
901
|
-
unites.length > 0 ||
|
|
902
|
-
appliquees.length > 0 ||
|
|
903
1500
|
differe.length > 0 ||
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1501
|
+
[
|
|
1502
|
+
unites,
|
|
1503
|
+
appliquees,
|
|
1504
|
+
copies,
|
|
1505
|
+
demarrees,
|
|
1506
|
+
courantes,
|
|
1507
|
+
retirees,
|
|
1508
|
+
versions.retirees,
|
|
1509
|
+
versions.echecs,
|
|
1510
|
+
].some(l => l.length > 0),
|
|
1511
|
+
versions,
|
|
907
1512
|
...(compactage ? { compactage } : {}),
|
|
908
1513
|
...(differe.length ? { serveurDiffere: differe } : {}),
|
|
909
1514
|
};
|