Mise a jour automatique globale programmee par serveur
- planification crontab par serveur (hostauto.json) : toutes les stacks de la
derniere analyse, une par une, hors exclues, arretees et stacks ayant leur
propre planification (celle de la stack prime)
- attente d'une connexion occupee (30 min max), resultat par stack conserve
- API PUT /api/servers/{id}/auto {"schedule"} ; vue de fleet : servers[].auto
- interface : bouton horloge par serveur (dialogue de planification), badge,
section Serveurs dans la vue "Mises a jour auto", statut bleu pendant l'execution
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LNfwm6UCYFyvNQNSF5i9Gy
This commit is contained in:
1 parent
ef259ae27a
commit
eac873266c
10 files changed
+824
-109
No files matched your search
+282
-103
@@ -1,7 +1,7 @@
|
|||||||
// Mises a jour automatiques programmees (crontab) : badge, editeur dans le
|
// Mises a jour automatiques programmees (crontab) : par stack (detail de la
|
||||||
// detail d'une stack et vue de suivi de toutes les programmations.
|
// stack) et globale par serveur (dialogue du serveur), badges et vue de suivi.
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState, type ReactNode } from "react";
|
||||||
import { api, type AutoInfo, type Me, type Scan, type Server, type Stack, type Target } from "./api";
|
import { api, type AutoInfo, type HostAutoInfo, type Me, type Scan, type Server, type Stack, type Target } from "./api";
|
||||||
import { fmtDate, fmtRelative } from "./format";
|
import { fmtDate, fmtRelative } from "./format";
|
||||||
import { CheckIcon, ClockIcon, RefreshIcon, WarningIcon } from "./icons";
|
import { CheckIcon, ClockIcon, RefreshIcon, WarningIcon } from "./icons";
|
||||||
|
|
||||||
@@ -13,6 +13,58 @@ export const AUTO_PRESETS: [string, string][] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const norm = (s: string) => s.trim().split(/\s+/).join(" ");
|
const norm = (s: string) => s.trim().split(/\s+/).join(" ");
|
||||||
|
const base = (dir: string) => dir.split("/").pop() || dir;
|
||||||
|
|
||||||
|
/** Valide une planification cote serveur et renvoie ses prochaines executions. */
|
||||||
|
function useCronPreview(expr: string, active: boolean) {
|
||||||
|
const [preview, setPreview] = useState<{ next?: string[]; error?: string }>({});
|
||||||
|
useEffect(() => {
|
||||||
|
if (!active) return;
|
||||||
|
let live = true;
|
||||||
|
const h = setTimeout(() => {
|
||||||
|
api.cronPreview(expr).then(
|
||||||
|
(next) => live && setPreview({ next }),
|
||||||
|
(e: unknown) => live && setPreview({ error: e instanceof Error ? e.message : String(e) }),
|
||||||
|
);
|
||||||
|
}, 300);
|
||||||
|
return () => {
|
||||||
|
live = false;
|
||||||
|
clearTimeout(h);
|
||||||
|
};
|
||||||
|
}, [expr, active]);
|
||||||
|
return preview;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Planification predefinie ou expression crontab libre. */
|
||||||
|
function CronInputs({ expr, setExpr, children }: { expr: string; setExpr: (v: string) => void; children?: ReactNode }) {
|
||||||
|
const preset = AUTO_PRESETS.find(([p]) => p === norm(expr))?.[0] ?? "";
|
||||||
|
return (
|
||||||
|
<div className="auto-form">
|
||||||
|
<select value={preset} onChange={(e) => e.target.value && setExpr(e.target.value)} aria-label="Planification predefinie">
|
||||||
|
<option value="">Personnalisee</option>
|
||||||
|
{AUTO_PRESETS.map(([p, label]) => (
|
||||||
|
<option key={p} value={p}>
|
||||||
|
{label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<input className="mono" value={expr} onChange={(e) => setExpr(e.target.value)} placeholder="min heure jour mois jour-semaine" aria-label="Planification crontab" spellCheck={false} />
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CronPreview({ preview, tz }: { preview: { next?: string[]; error?: string }; tz?: string }) {
|
||||||
|
return (
|
||||||
|
<div className={`small-text auto-preview ${preview.error ? "error-text" : "muted"}`}>
|
||||||
|
{preview.error
|
||||||
|
? preview.error
|
||||||
|
: preview.next?.length
|
||||||
|
? `Prochaines executions : ${preview.next.map(fmtDate).join(", ")}${tz ? ` (heure ${tz})` : ""}`
|
||||||
|
: " "}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Badge (couleur sarcelle) a cote du nom d'une stack programmee. */
|
/** Badge (couleur sarcelle) a cote du nom d'une stack programmee. */
|
||||||
export function AutoBadge({ auto }: { auto: AutoInfo }) {
|
export function AutoBadge({ auto }: { auto: AutoInfo }) {
|
||||||
@@ -24,6 +76,16 @@ export function AutoBadge({ auto }: { auto: AutoInfo }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Badge a cote du nom d'un serveur a mise a jour globale programmee. */
|
||||||
|
export function HostAutoBadge({ auto }: { auto: HostAutoInfo }) {
|
||||||
|
const title = `Mise a jour globale programmee : ${auto.schedule}${auto.next ? `, prochaine le ${fmtDate(auto.next)}` : ""}`;
|
||||||
|
return (
|
||||||
|
<span className="auto-badge host" title={title} aria-label="Mise a jour globale programmee">
|
||||||
|
{auto.running ? <RefreshIcon size={12} className="spin" /> : <ClockIcon size={12} />}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Dernier resultat d'une execution programmee. */
|
/** Dernier resultat d'une execution programmee. */
|
||||||
export function AutoLast({ auto }: { auto: AutoInfo }) {
|
export function AutoLast({ auto }: { auto: AutoInfo }) {
|
||||||
if (auto.pending) return <span className="auto-last muted">en attente (connexion occupee)</span>;
|
if (auto.pending) return <span className="auto-last muted">en attente (connexion occupee)</span>;
|
||||||
@@ -39,40 +101,51 @@ export function AutoLast({ auto }: { auto: AutoInfo }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Dernier resultat (ou execution en cours) d'une planification de serveur. */
|
||||||
|
export function HostAutoLast({ auto }: { auto: HostAutoInfo }) {
|
||||||
|
if (auto.running) {
|
||||||
|
return (
|
||||||
|
<span className="status-pill st-applying">
|
||||||
|
<RefreshIcon size={13} className="spin" /> Mise a jour en cours{auto.current ? ` : ${base(auto.current)}` : ""}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (auto.pending) return <span className="auto-last muted">en attente</span>;
|
||||||
|
if (!auto.lastRun) return <span className="auto-last muted">jamais executee</span>;
|
||||||
|
const failed = (auto.results ?? []).filter((r) => !r.ok);
|
||||||
|
const title = failed.length ? failed.map((r) => `${r.name} : ${r.message}`).join("\n") : fmtDate(auto.lastRun);
|
||||||
|
return (
|
||||||
|
<span className={`auto-last ${auto.lastOk ? "ok" : "ko"}`} title={title}>
|
||||||
|
{auto.lastOk ? <CheckIcon size={13} /> : <WarningIcon size={13} />}
|
||||||
|
<span>
|
||||||
|
{fmtRelative(auto.lastRun)}
|
||||||
|
{auto.lastMessage ? ` : ${auto.lastMessage}` : ""}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
interface EditorProps {
|
interface EditorProps {
|
||||||
stack: Stack;
|
stack: Stack;
|
||||||
busy: boolean;
|
busy: boolean;
|
||||||
tz?: string;
|
tz?: string;
|
||||||
|
/** Planification globale du serveur, remplacee par celle de la stack. */
|
||||||
|
hostSchedule?: string;
|
||||||
onSave: (schedule: string) => Promise<unknown>;
|
onSave: (schedule: string) => Promise<unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Case « Mise a jour automatique programmee » et sa planification crontab. */
|
/** Case « Mise a jour automatique programmee » et sa planification crontab. */
|
||||||
export function AutoEditor({ stack, busy, tz, onSave }: EditorProps) {
|
export function AutoEditor({ stack, busy, tz, hostSchedule, onSave }: EditorProps) {
|
||||||
const current = stack.auto?.schedule ?? "";
|
const current = stack.auto?.schedule ?? "";
|
||||||
const [on, setOn] = useState(!!current);
|
const [on, setOn] = useState(!!current);
|
||||||
const [expr, setExpr] = useState(current || AUTO_PRESETS[0][0]);
|
const [expr, setExpr] = useState(current || AUTO_PRESETS[0][0]);
|
||||||
const [preview, setPreview] = useState<{ next?: string[]; error?: string }>({});
|
const preview = useCronPreview(expr, on);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOn(!!current);
|
setOn(!!current);
|
||||||
if (current) setExpr(current);
|
if (current) setExpr(current);
|
||||||
}, [current]);
|
}, [current]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!on) return;
|
|
||||||
let live = true;
|
|
||||||
const h = setTimeout(() => {
|
|
||||||
api.cronPreview(expr).then(
|
|
||||||
(next) => live && setPreview({ next }),
|
|
||||||
(e: unknown) => live && setPreview({ error: e instanceof Error ? e.message : String(e) }),
|
|
||||||
);
|
|
||||||
}, 300);
|
|
||||||
return () => {
|
|
||||||
live = false;
|
|
||||||
clearTimeout(h);
|
|
||||||
};
|
|
||||||
}, [expr, on]);
|
|
||||||
|
|
||||||
if (stack.excluded) {
|
if (stack.excluded) {
|
||||||
return (
|
return (
|
||||||
<label className="check-row muted">
|
<label className="check-row muted">
|
||||||
@@ -87,7 +160,6 @@ export function AutoEditor({ stack, busy, tz, onSave }: EditorProps) {
|
|||||||
if (!v && current) void onSave(""); // desactivation immediate
|
if (!v && current) void onSave(""); // desactivation immediate
|
||||||
};
|
};
|
||||||
const dirty = on && norm(expr) !== current;
|
const dirty = on && norm(expr) !== current;
|
||||||
const preset = AUTO_PRESETS.find(([p]) => p === norm(expr))?.[0] ?? "";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="auto-editor">
|
<div className="auto-editor">
|
||||||
@@ -95,32 +167,22 @@ export function AutoEditor({ stack, busy, tz, onSave }: EditorProps) {
|
|||||||
<input type="checkbox" checked={on} disabled={busy} onChange={(e) => toggle(e.target.checked)} />
|
<input type="checkbox" checked={on} disabled={busy} onChange={(e) => toggle(e.target.checked)} />
|
||||||
<span>Mise a jour automatique programmee (pull, puis down + up -d seulement si une image a change)</span>
|
<span>Mise a jour automatique programmee (pull, puis down + up -d seulement si une image a change)</span>
|
||||||
</label>
|
</label>
|
||||||
|
{hostSchedule && (
|
||||||
|
<div className="small-text muted auto-preview">
|
||||||
|
{current
|
||||||
|
? `Cette planification remplace, pour cette stack, celle du serveur (${hostSchedule}).`
|
||||||
|
: `Couverte par la planification du serveur (${hostSchedule}) ; une planification propre a la stack la remplacerait.`}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{on && (
|
{on && (
|
||||||
<div className="auto-form">
|
<CronInputs expr={expr} setExpr={setExpr}>
|
||||||
<select value={preset} onChange={(e) => e.target.value && setExpr(e.target.value)} aria-label="Planification predefinie">
|
|
||||||
<option value="">Personnalisee</option>
|
|
||||||
{AUTO_PRESETS.map(([p, label]) => (
|
|
||||||
<option key={p} value={p}>
|
|
||||||
{label}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
<input className="mono" value={expr} onChange={(e) => setExpr(e.target.value)} placeholder="min heure jour mois jour-semaine" aria-label="Planification crontab" spellCheck={false} />
|
|
||||||
<button className="primary" disabled={!dirty || busy || !!preview.error} onClick={() => void onSave(norm(expr))}>
|
<button className="primary" disabled={!dirty || busy || !!preview.error} onClick={() => void onSave(norm(expr))}>
|
||||||
<ClockIcon />
|
<ClockIcon />
|
||||||
{current ? "Modifier" : "Programmer"}
|
{current ? "Modifier" : "Programmer"}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</CronInputs>
|
||||||
)}
|
|
||||||
{on && (
|
|
||||||
<div className={`small-text ${preview.error ? "error-text" : "muted"}`}>
|
|
||||||
{preview.error
|
|
||||||
? preview.error
|
|
||||||
: preview.next?.length
|
|
||||||
? `Prochaines executions : ${preview.next.map(fmtDate).join(", ")}${tz ? ` (heure ${tz})` : ""}`
|
|
||||||
: " "}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
{on && <CronPreview preview={preview} tz={tz} />}
|
||||||
{stack.auto && (
|
{stack.auto && (
|
||||||
<div className="small-text muted">
|
<div className="small-text muted">
|
||||||
Derniere execution programmee : <AutoLast auto={stack.auto} />
|
Derniere execution programmee : <AutoLast auto={stack.auto} />
|
||||||
@@ -130,6 +192,72 @@ export function AutoEditor({ stack, busy, tz, onSave }: EditorProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface HostDialogProps {
|
||||||
|
server: Server;
|
||||||
|
tz?: string;
|
||||||
|
onSave: (schedule: string) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Planification de la mise a jour globale d'un serveur. */
|
||||||
|
export function HostAutoDialog({ server, tz, onSave, onClose }: HostDialogProps) {
|
||||||
|
const current = server.auto?.schedule ?? "";
|
||||||
|
const [on, setOn] = useState(!!current);
|
||||||
|
const [expr, setExpr] = useState(current || AUTO_PRESETS[0][0]);
|
||||||
|
const preview = useCronPreview(expr, on);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onKey = (e: KeyboardEvent) => e.key === "Escape" && onClose();
|
||||||
|
window.addEventListener("keydown", onKey);
|
||||||
|
return () => window.removeEventListener("keydown", onKey);
|
||||||
|
}, [onClose]);
|
||||||
|
|
||||||
|
const value = on ? norm(expr) : "";
|
||||||
|
const changed = value !== current;
|
||||||
|
const results = server.auto?.results ?? [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="modal-backdrop" onClick={onClose}>
|
||||||
|
<div className="modal" role="dialog" aria-modal="true" aria-label="Mise a jour automatique du serveur" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<h3>Mise a jour automatique : {server.name}</h3>
|
||||||
|
<div className="modal-text">
|
||||||
|
<p className="muted small-text">
|
||||||
|
A chaque echeance, les stacks du serveur sont mises a jour une par une (pull, puis down + up -d seulement si une image a change). Sont ignorees : les stacks exclues, les stacks arretees et les
|
||||||
|
stacks qui ont leur propre planification (celle de la stack prime).
|
||||||
|
</p>
|
||||||
|
<label className="check-row">
|
||||||
|
<input type="checkbox" checked={on} onChange={(e) => setOn(e.target.checked)} />
|
||||||
|
<span>Mettre a jour automatiquement toutes les stacks de ce serveur</span>
|
||||||
|
</label>
|
||||||
|
{on && <CronInputs expr={expr} setExpr={setExpr} />}
|
||||||
|
{on && <CronPreview preview={preview} tz={tz} />}
|
||||||
|
{server.auto && (
|
||||||
|
<div className="small-text">
|
||||||
|
Derniere execution : <HostAutoLast auto={server.auto} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{results.length > 0 && !server.auto?.running && (
|
||||||
|
<ul className="auto-results small-text">
|
||||||
|
{results.map((r) => (
|
||||||
|
<li key={`${r.target}:${r.dir}`} className={r.ok ? (r.skipped ? "muted" : "ok") : "ko"}>
|
||||||
|
{r.ok ? <CheckIcon size={12} /> : <WarningIcon size={12} />} <strong>{r.name}</strong> <span className="muted">({r.user})</span> : {r.message}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="modal-actions">
|
||||||
|
<span className="spacer" />
|
||||||
|
<button onClick={onClose}>Annuler</button>
|
||||||
|
<button className="primary" disabled={!changed || (on && !!preview.error)} onClick={() => onSave(value)}>
|
||||||
|
Enregistrer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
interface Row {
|
interface Row {
|
||||||
server: Server;
|
server: Server;
|
||||||
target: Target;
|
target: Target;
|
||||||
@@ -144,86 +272,137 @@ interface PanelProps {
|
|||||||
query: string;
|
query: string;
|
||||||
tz?: string;
|
tz?: string;
|
||||||
onDisable: (server: Server, target: Target, stack: Stack) => void;
|
onDisable: (server: Server, target: Target, stack: Stack) => void;
|
||||||
|
onDisableHost: (server: Server) => void;
|
||||||
|
onEditHost: (server: Server) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Espace de suivi : toutes les stacks programmees, triees par prochaine execution. */
|
const byNext = (a?: string, b?: string) => (a ?? "9").localeCompare(b ?? "9");
|
||||||
export function AutoPanel({ me, servers, query, tz, onDisable }: PanelProps) {
|
|
||||||
|
/** Espace de suivi : planifications des serveurs puis des stacks, triees par prochaine execution. */
|
||||||
|
export function AutoPanel({ me, servers, query, tz, onDisable, onDisableHost, onEditHost }: PanelProps) {
|
||||||
|
const q = query.trim().toLowerCase();
|
||||||
|
const hosts = servers.filter((s) => s.auto && (!q || s.name.toLowerCase().includes(q))).sort((a, b) => byNext(a.auto?.next, b.auto?.next));
|
||||||
const rows: Row[] = servers.flatMap((server) =>
|
const rows: Row[] = servers.flatMap((server) =>
|
||||||
server.targets.flatMap((target) => {
|
server.targets.flatMap((target) => {
|
||||||
const scan = server.scans[target.id];
|
const scan = server.scans[target.id];
|
||||||
return (scan?.stacks ?? []).flatMap((stack) => (stack.auto ? [{ server, target, scan, stack, auto: stack.auto }] : []));
|
return (scan?.stacks ?? []).flatMap((stack) => (stack.auto ? [{ server, target, scan, stack, auto: stack.auto }] : []));
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const q = query.trim().toLowerCase();
|
|
||||||
const shown = rows
|
const shown = rows
|
||||||
.filter((r) => !q || r.stack.name.toLowerCase().includes(q) || r.stack.dir.toLowerCase().includes(q) || r.server.name.toLowerCase().includes(q))
|
.filter((r) => !q || r.stack.name.toLowerCase().includes(q) || r.stack.dir.toLowerCase().includes(q) || r.server.name.toLowerCase().includes(q))
|
||||||
.sort((a, b) => (a.auto.next ?? "9").localeCompare(b.auto.next ?? "9"));
|
.sort((a, b) => byNext(a.auto.next, b.auto.next));
|
||||||
|
|
||||||
if (!rows.length) {
|
if (!rows.length && !servers.some((s) => s.auto)) {
|
||||||
return (
|
return (
|
||||||
<p className="muted pad">
|
<p className="muted pad">
|
||||||
Aucune stack en mise a jour automatique. Pour en programmer une, ouvrir son detail et cocher « Mise a jour automatique programmee ».
|
Aucune mise a jour automatique. Pour une stack : ouvrir son detail et cocher « Mise a jour automatique programmee ». Pour tout un serveur : bouton horloge a cote de « Modifier ».
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="auto-panel">
|
<div className="auto-panel">
|
||||||
<p className="muted small-text">
|
<p className="muted small-text">Heures exprimees dans le fuseau du serveur stackwatch{tz ? ` (${tz})` : ""}. La planification d'une stack prime sur celle de son serveur.</p>
|
||||||
{rows.length} stack{rows.length > 1 ? "s" : ""} programmee{rows.length > 1 ? "s" : ""}. Heures exprimees dans le fuseau du serveur stackwatch{tz ? ` (${tz})` : ""}.
|
|
||||||
</p>
|
{hosts.length > 0 && (
|
||||||
<table className="services auto-table">
|
<>
|
||||||
<thead>
|
<h4 className="auto-h">Serveurs (toutes les stacks, hors exclues, arretees et planifiees individuellement)</h4>
|
||||||
<tr>
|
<table className="services auto-table">
|
||||||
<th>Stack</th>
|
<thead>
|
||||||
<th>Serveur</th>
|
<tr>
|
||||||
<th>Planification</th>
|
<th>Serveur</th>
|
||||||
<th>Prochaine</th>
|
<th>Planification</th>
|
||||||
<th>Derniere execution</th>
|
<th>Prochaine</th>
|
||||||
{me.admin && <th />}
|
<th>Derniere execution</th>
|
||||||
</tr>
|
{me.admin && <th />}
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{shown.map(({ server, target, scan, stack, auto }) => {
|
|
||||||
const running = scan.running && scan.task === "apply" && scan.current === stack.dir;
|
|
||||||
return (
|
|
||||||
<tr key={`${server.id}/${target.id}:${stack.dir}`}>
|
|
||||||
<td>
|
|
||||||
<strong>{stack.name}</strong>
|
|
||||||
<br />
|
|
||||||
<small className="muted">{stack.dir}</small>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{server.name}
|
|
||||||
{!server.enabled && <span className="muted"> (desactive)</span>}
|
|
||||||
<br />
|
|
||||||
<small className="muted">{target.user}</small>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<code>{auto.schedule}</code>
|
|
||||||
</td>
|
|
||||||
<td>{auto.next ? fmtDate(auto.next) : <span className="muted">jamais</span>}</td>
|
|
||||||
<td>
|
|
||||||
{running ? (
|
|
||||||
<span className="status-pill st-applying">
|
|
||||||
<RefreshIcon size={13} className="spin" /> Mise a jour en cours
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<AutoLast auto={auto} />
|
|
||||||
)}
|
|
||||||
</td>
|
|
||||||
{me.admin && (
|
|
||||||
<td>
|
|
||||||
<button onClick={() => onDisable(server, target, stack)} disabled={running}>
|
|
||||||
Desactiver
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
)}
|
|
||||||
</tr>
|
</tr>
|
||||||
);
|
</thead>
|
||||||
})}
|
<tbody>
|
||||||
</tbody>
|
{hosts.map((s) => (
|
||||||
</table>
|
<tr key={s.id}>
|
||||||
{shown.length === 0 && <p className="muted pad">Aucune programmation ne correspond a la recherche.</p>}
|
<td>
|
||||||
|
<strong>{s.name}</strong>
|
||||||
|
{!s.enabled && <span className="muted"> (desactive)</span>}
|
||||||
|
<br />
|
||||||
|
<small className="muted">{s.host}</small>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<code>{s.auto!.schedule}</code>
|
||||||
|
</td>
|
||||||
|
<td>{s.auto!.next ? fmtDate(s.auto!.next) : <span className="muted">jamais</span>}</td>
|
||||||
|
<td>
|
||||||
|
<HostAutoLast auto={s.auto!} />
|
||||||
|
</td>
|
||||||
|
{me.admin && (
|
||||||
|
<td className="auto-actions">
|
||||||
|
<button onClick={() => onEditHost(s)}>Modifier</button>
|
||||||
|
<button onClick={() => onDisableHost(s)}>Desactiver</button>
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{rows.length > 0 && (
|
||||||
|
<>
|
||||||
|
<h4 className="auto-h">Stacks</h4>
|
||||||
|
<table className="services auto-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Stack</th>
|
||||||
|
<th>Serveur</th>
|
||||||
|
<th>Planification</th>
|
||||||
|
<th>Prochaine</th>
|
||||||
|
<th>Derniere execution</th>
|
||||||
|
{me.admin && <th />}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{shown.map(({ server, target, scan, stack, auto }) => {
|
||||||
|
const running = scan.running && scan.task === "apply" && scan.current === stack.dir;
|
||||||
|
return (
|
||||||
|
<tr key={`${server.id}/${target.id}:${stack.dir}`}>
|
||||||
|
<td>
|
||||||
|
<strong>{stack.name}</strong>
|
||||||
|
<br />
|
||||||
|
<small className="muted">{stack.dir}</small>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{server.name}
|
||||||
|
{!server.enabled && <span className="muted"> (desactive)</span>}
|
||||||
|
<br />
|
||||||
|
<small className="muted">{target.user}</small>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<code>{auto.schedule}</code>
|
||||||
|
</td>
|
||||||
|
<td>{auto.next ? fmtDate(auto.next) : <span className="muted">jamais</span>}</td>
|
||||||
|
<td>
|
||||||
|
{running ? (
|
||||||
|
<span className="status-pill st-applying">
|
||||||
|
<RefreshIcon size={13} className="spin" /> Mise a jour en cours
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<AutoLast auto={auto} />
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
{me.admin && (
|
||||||
|
<td>
|
||||||
|
<button onClick={() => onDisable(server, target, stack)} disabled={running}>
|
||||||
|
Desactiver
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{shown.length === 0 && <p className="muted pad">Aucune programmation ne correspond a la recherche.</p>}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { api, type Me, type Fleet, type Scan, type Server, type Stack, type StackStatus, type Target } from "./api";
|
import { api, type Me, type Fleet, type Scan, type Server, type Stack, type StackStatus, type Target } from "./api";
|
||||||
import { AutoBadge, AutoEditor, AutoPanel } from "./AutoUpdate";
|
import { AutoBadge, AutoEditor, AutoPanel, HostAutoBadge, HostAutoDialog } from "./AutoUpdate";
|
||||||
import { ConfirmDialog } from "./Dialogs";
|
import { ConfirmDialog } from "./Dialogs";
|
||||||
import { fmtRelative, plural } from "./format";
|
import { fmtRelative, plural } from "./format";
|
||||||
import { ArrowUpIcon, BanIcon, CheckIcon, ChevronDownIcon, ChevronRightIcon, ClockIcon, EditIcon, KeyIcon, PlusIcon, RefreshIcon, SearchIcon, ServerIcon, WarningIcon } from "./icons";
|
import { ArrowUpIcon, BanIcon, CheckIcon, ChevronDownIcon, ChevronRightIcon, ClockIcon, EditIcon, KeyIcon, PlusIcon, RefreshIcon, SearchIcon, ServerIcon, WarningIcon } from "./icons";
|
||||||
@@ -30,6 +30,7 @@ export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Pro
|
|||||||
const [filter, setFilter] = useState<Filter>("all");
|
const [filter, setFilter] = useState<Filter>("all");
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [applying, setApplying] = useState<{ server: Server; target: Target; stack: Stack } | null>(null);
|
const [applying, setApplying] = useState<{ server: Server; target: Target; stack: Stack } | null>(null);
|
||||||
|
const [hostAuto, setHostAuto] = useState<Server | null>(null);
|
||||||
|
|
||||||
const servers = useMemo(() => (current ? [current] : (fleet?.servers ?? [])), [current, fleet]);
|
const servers = useMemo(() => (current ? [current] : (fleet?.servers ?? [])), [current, fleet]);
|
||||||
|
|
||||||
@@ -84,7 +85,10 @@ export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Pro
|
|||||||
<div className="fleet">
|
<div className="fleet">
|
||||||
<div className="head">
|
<div className="head">
|
||||||
<div className="head-title">
|
<div className="head-title">
|
||||||
<h2>{current ? current.name : "Tous les serveurs"}</h2>
|
<h2>
|
||||||
|
{current ? current.name : "Tous les serveurs"}
|
||||||
|
{current?.auto && <HostAutoBadge auto={current.auto} />}
|
||||||
|
</h2>
|
||||||
{current && (
|
{current && (
|
||||||
<span className="muted">
|
<span className="muted">
|
||||||
{current.host}
|
{current.host}
|
||||||
@@ -135,13 +139,19 @@ export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Pro
|
|||||||
Modifier
|
Modifier
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
{me.admin && (
|
||||||
|
<button onClick={() => setHostAuto(current)} title="Mise a jour automatique de toutes les stacks du serveur">
|
||||||
|
<ClockIcon />
|
||||||
|
Mise a jour auto
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="scroll">
|
<div className="scroll">
|
||||||
{filter === "auto" ? (
|
{filter === "auto" ? (
|
||||||
<AutoPanel me={me} servers={servers} query={search} tz={fleet.tz} onDisable={(srv, t, st) => run(() => api.autoStack(srv.id, t.id, st.dir, ""))} />
|
<AutoPanel me={me} servers={servers} query={search} tz={fleet.tz} onDisable={(srv, t, st) => run(() => api.autoStack(srv.id, t.id, st.dir, ""))} onDisableHost={(srv) => run(() => api.autoServer(srv.id, ""))} onEditHost={setHostAuto} />
|
||||||
) : servers.map((s) => (
|
) : servers.map((s) => (
|
||||||
<ServerBlock
|
<ServerBlock
|
||||||
key={s.id}
|
key={s.id}
|
||||||
@@ -155,6 +165,7 @@ export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Pro
|
|||||||
onApply={(target, stack) => setApplying({ server: s, target, stack })}
|
onApply={(target, stack) => setApplying({ server: s, target, stack })}
|
||||||
onExclude={(target, stack, on) => run(() => api.excludeStack(s.id, target.id, stack.dir, on))}
|
onExclude={(target, stack, on) => run(() => api.excludeStack(s.id, target.id, stack.dir, on))}
|
||||||
onAuto={(target, stack, schedule) => run(() => api.autoStack(s.id, target.id, stack.dir, schedule))}
|
onAuto={(target, stack, schedule) => run(() => api.autoStack(s.id, target.id, stack.dir, schedule))}
|
||||||
|
onHostAuto={() => setHostAuto(s)}
|
||||||
tz={fleet.tz}
|
tz={fleet.tz}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
@@ -177,6 +188,19 @@ export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Pro
|
|||||||
</p>
|
</p>
|
||||||
</ConfirmDialog>
|
</ConfirmDialog>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{hostAuto && (
|
||||||
|
<HostAutoDialog
|
||||||
|
server={hostAuto}
|
||||||
|
tz={fleet.tz}
|
||||||
|
onClose={() => setHostAuto(null)}
|
||||||
|
onSave={(schedule) => {
|
||||||
|
const id = hostAuto.id;
|
||||||
|
setHostAuto(null);
|
||||||
|
run(() => api.autoServer(id, schedule));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -192,10 +216,11 @@ interface BlockProps {
|
|||||||
onApply: (t: Target, s: Stack) => void;
|
onApply: (t: Target, s: Stack) => void;
|
||||||
onExclude: (t: Target, s: Stack, on: boolean) => void;
|
onExclude: (t: Target, s: Stack, on: boolean) => void;
|
||||||
onAuto: (t: Target, s: Stack, schedule: string) => Promise<void>;
|
onAuto: (t: Target, s: Stack, schedule: string) => Promise<void>;
|
||||||
|
onHostAuto: () => void;
|
||||||
tz?: string;
|
tz?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ServerBlock({ server, single, me, keep, filtering, onEdit, onCheck, onApply, onExclude, onAuto, tz }: BlockProps) {
|
function ServerBlock({ server, single, me, keep, filtering, onEdit, onCheck, onApply, onExclude, onAuto, onHostAuto, tz }: BlockProps) {
|
||||||
const scans = Object.values(server.scans);
|
const scans = Object.values(server.scans);
|
||||||
const running = scans.some((s) => s.running);
|
const running = scans.some((s) => s.running);
|
||||||
const last = scans.map((s) => s.finished).filter(Boolean).sort().pop();
|
const last = scans.map((s) => s.finished).filter(Boolean).sort().pop();
|
||||||
@@ -207,6 +232,7 @@ function ServerBlock({ server, single, me, keep, filtering, onEdit, onCheck, onA
|
|||||||
<header className="server-head">
|
<header className="server-head">
|
||||||
<ServerIcon size={18} />
|
<ServerIcon size={18} />
|
||||||
<h3>{server.name}</h3>
|
<h3>{server.name}</h3>
|
||||||
|
{server.auto && <HostAutoBadge auto={server.auto} />}
|
||||||
<span className="muted">{server.host}</span>
|
<span className="muted">{server.host}</span>
|
||||||
{!server.enabled && <span className="pill">désactivé</span>}
|
{!server.enabled && <span className="pill">désactivé</span>}
|
||||||
{updates > 0 && <span className="pill warn">{plural(updates, "mise")} à jour</span>}
|
{updates > 0 && <span className="pill warn">{plural(updates, "mise")} à jour</span>}
|
||||||
@@ -219,6 +245,11 @@ function ServerBlock({ server, single, me, keep, filtering, onEdit, onCheck, onA
|
|||||||
<button className="icon-btn" onClick={() => onCheck()} disabled={running} aria-label={`Vérifier ${server.name}`} title="Vérifier ce serveur">
|
<button className="icon-btn" onClick={() => onCheck()} disabled={running} aria-label={`Vérifier ${server.name}`} title="Vérifier ce serveur">
|
||||||
<RefreshIcon className={running ? "spin" : ""} />
|
<RefreshIcon className={running ? "spin" : ""} />
|
||||||
</button>
|
</button>
|
||||||
|
{me.admin && (
|
||||||
|
<button className="icon-btn" onClick={onHostAuto} aria-label={`Mise a jour auto de ${server.name}`} title="Mise a jour automatique de toutes les stacks du serveur">
|
||||||
|
<ClockIcon />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
{me.admin && (
|
{me.admin && (
|
||||||
<button className="icon-btn" onClick={onEdit} aria-label={`Modifier ${server.name}`} title="Modifier">
|
<button className="icon-btn" onClick={onEdit} aria-label={`Modifier ${server.name}`} title="Modifier">
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
@@ -341,7 +372,7 @@ function TargetBlock({ server, target, scan, me, keep, filtering, onCheck, onApp
|
|||||||
<span>Exclure cette stack des mises à jour (elle reste analysée et affichée, sans bouton « Mettre à jour »)</span>
|
<span>Exclure cette stack des mises à jour (elle reste analysée et affichée, sans bouton « Mettre à jour »)</span>
|
||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
{me.admin && <AutoEditor stack={st} busy={applying} tz={tz} onSave={(x) => onAuto(st, x)} />}
|
{me.admin && <AutoEditor stack={st} busy={applying} tz={tz} hostSchedule={server.auto?.schedule} onSave={(x) => onAuto(st, x)} />}
|
||||||
{!me.admin && st.auto && (
|
{!me.admin && st.auto && (
|
||||||
<div className="small-text muted">
|
<div className="small-text muted">
|
||||||
Mise a jour automatique : <code>{st.auto.schedule}</code>
|
Mise a jour automatique : <code>{st.auto.schedule}</code>
|
||||||
|
|||||||
@@ -88,6 +88,34 @@ export interface AutoInfo {
|
|||||||
pending?: boolean;
|
pending?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Resultat d'une stack lors d'une mise a jour globale programmee. */
|
||||||
|
export interface HostStackResult {
|
||||||
|
target: string;
|
||||||
|
user: string;
|
||||||
|
dir: string;
|
||||||
|
name: string;
|
||||||
|
ok: boolean;
|
||||||
|
/** Rien a faire (deja a jour, stack arretee). */
|
||||||
|
skipped?: boolean;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mise a jour globale programmee d'un serveur. */
|
||||||
|
export interface HostAutoInfo {
|
||||||
|
schedule: string;
|
||||||
|
by?: string;
|
||||||
|
since: string;
|
||||||
|
next?: string;
|
||||||
|
lastRun?: string;
|
||||||
|
lastOk: boolean;
|
||||||
|
lastMessage?: string;
|
||||||
|
results?: HostStackResult[];
|
||||||
|
pending?: boolean;
|
||||||
|
running?: boolean;
|
||||||
|
/** Stack en cours pendant une execution. */
|
||||||
|
current?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Scan {
|
export interface Scan {
|
||||||
running: boolean;
|
running: boolean;
|
||||||
task?: "scan" | "apply";
|
task?: "scan" | "apply";
|
||||||
@@ -116,6 +144,8 @@ export interface Server extends ServerInput {
|
|||||||
targets: Target[];
|
targets: Target[];
|
||||||
/** Résultat de chaque connexion, par identifiant de connexion. */
|
/** Résultat de chaque connexion, par identifiant de connexion. */
|
||||||
scans: Record<string, Scan>;
|
scans: Record<string, Scan>;
|
||||||
|
/** Mise a jour globale programmee du serveur. */
|
||||||
|
auto?: HostAutoInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Summary {
|
export interface Summary {
|
||||||
@@ -236,6 +266,11 @@ export const api = {
|
|||||||
await request(`/api/servers/${q(serverId)}/targets/${q(targetId)}/auto`, json({ dir, schedule }, "PUT"));
|
await request(`/api/servers/${q(serverId)}/targets/${q(targetId)}/auto`, json({ dir, schedule }, "PUT"));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** Programme la mise a jour globale d'un serveur (crontab) ; schedule vide : la desactive. */
|
||||||
|
autoServer: async (serverId: string, schedule: string): Promise<void> => {
|
||||||
|
await request(`/api/servers/${q(serverId)}/auto`, json({ schedule }, "PUT"));
|
||||||
|
},
|
||||||
|
|
||||||
/** Valide une planification et renvoie ses prochaines executions. */
|
/** Valide une planification et renvoie ses prochaines executions. */
|
||||||
cronPreview: async (expr: string): Promise<string[]> => (await (await request(`/api/cron?expr=${q(expr)}`)).json()).next,
|
cronPreview: async (expr: string): Promise<string[]> => (await (await request(`/api/cron?expr=${q(expr)}`)).json()).next,
|
||||||
|
|
||||||
|
|||||||
@@ -1348,3 +1348,45 @@ button.copy-ko {
|
|||||||
.auto-table td {
|
.auto-table td {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
/* Planification globale d'un serveur : meme couleur, badge carre */
|
||||||
|
.auto-badge.host {
|
||||||
|
border-radius: 0.3rem;
|
||||||
|
}
|
||||||
|
h2 .auto-badge,
|
||||||
|
.server-head .auto-badge {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
.auto-h {
|
||||||
|
margin: 1rem 0 0.4rem;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
.auto-actions {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.auto-actions button + button {
|
||||||
|
margin-left: 0.3rem;
|
||||||
|
}
|
||||||
|
.modal .auto-form,
|
||||||
|
.modal .auto-preview {
|
||||||
|
padding-left: 0;
|
||||||
|
margin: 0.4rem 0;
|
||||||
|
}
|
||||||
|
.auto-results {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0.4rem 0 0;
|
||||||
|
padding: 0;
|
||||||
|
max-height: 12rem;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
.auto-results li {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.3rem;
|
||||||
|
padding: 0.1rem 0;
|
||||||
|
}
|
||||||
|
.auto-results li.ok svg {
|
||||||
|
color: var(--ok);
|
||||||
|
}
|
||||||
|
.auto-results li.ko svg {
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
// POST /api/servers/{id}/targets/{t}/apply {"dir"} mise à jour d'une stack : pull, down, up -d (administrateur)
|
// POST /api/servers/{id}/targets/{t}/apply {"dir"} mise à jour d'une stack : pull, down, up -d (administrateur)
|
||||||
// PUT /api/servers/{id}/targets/{t}/exclude {"dir","excluded"} exclut une stack des mises à jour ou la réactive (administrateur)
|
// PUT /api/servers/{id}/targets/{t}/exclude {"dir","excluded"} exclut une stack des mises à jour ou la réactive (administrateur)
|
||||||
// PUT /api/servers/{id}/targets/{t}/auto {"dir","schedule"} programme (crontab) ou desactive ("") la mise a jour auto d'une stack (administrateur)
|
// PUT /api/servers/{id}/targets/{t}/auto {"dir","schedule"} programme (crontab) ou desactive ("") la mise a jour auto d'une stack (administrateur)
|
||||||
|
// PUT /api/servers/{id}/auto {"schedule"} mise a jour auto globale d'un serveur, hors stacks exclues ou planifiees a part (administrateur)
|
||||||
// GET /api/cron?expr=... validation d'une planification et prochaines executions
|
// GET /api/cron?expr=... validation d'une planification et prochaines executions
|
||||||
// POST /api/account/password, PATCH /api/account compte local
|
// POST /api/account/password, PATCH /api/account compte local
|
||||||
// GET|POST /api/admin/users, PATCH|DELETE /api/admin/users/{id} comptes (administrateur)
|
// GET|POST /api/admin/users, PATCH|DELETE /api/admin/users/{id} comptes (administrateur)
|
||||||
@@ -101,6 +102,7 @@ func (h *Handler) Register(mux *http.ServeMux) {
|
|||||||
mux.HandleFunc("POST /api/servers/{id}/targets/{target}/apply", h.apply)
|
mux.HandleFunc("POST /api/servers/{id}/targets/{target}/apply", h.apply)
|
||||||
mux.HandleFunc("PUT /api/servers/{id}/targets/{target}/exclude", h.exclude)
|
mux.HandleFunc("PUT /api/servers/{id}/targets/{target}/exclude", h.exclude)
|
||||||
mux.HandleFunc("PUT /api/servers/{id}/targets/{target}/auto", h.autoUpdate)
|
mux.HandleFunc("PUT /api/servers/{id}/targets/{target}/auto", h.autoUpdate)
|
||||||
|
mux.HandleFunc("PUT /api/servers/{id}/auto", h.autoServer)
|
||||||
mux.HandleFunc("GET /api/cron", h.cronPreview)
|
mux.HandleFunc("GET /api/cron", h.cronPreview)
|
||||||
if h.Accounts != nil {
|
if h.Accounts != nil {
|
||||||
mux.HandleFunc("POST /api/account/password", h.changePassword)
|
mux.HandleFunc("POST /api/account/password", h.changePassword)
|
||||||
|
|||||||
@@ -39,6 +39,26 @@ func (h *Handler) autoUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, map[string]string{"schedule": req.Schedule})
|
writeJSON(w, http.StatusOK, map[string]string{"schedule": req.Schedule})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// autoServer programme (schedule) ou desactive (schedule vide) la mise a jour
|
||||||
|
// automatique globale d'un serveur.
|
||||||
|
func (h *Handler) autoServer(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !h.admin(w, r) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var req struct {
|
||||||
|
Schedule string `json:"schedule"`
|
||||||
|
}
|
||||||
|
if !h.decode(w, r, &req) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := h.Fleet.SetHostAuto(r.PathValue("id"), req.Schedule, UserID(r)); err != nil {
|
||||||
|
fail(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
slog.Info("mise a jour automatique du serveur", "server", r.PathValue("id"), "schedule", req.Schedule, "by", UserID(r))
|
||||||
|
writeJSON(w, http.StatusOK, map[string]string{"schedule": req.Schedule})
|
||||||
|
}
|
||||||
|
|
||||||
// cronPreview valide une planification et renvoie ses prochaines executions.
|
// cronPreview valide une planification et renvoie ses prochaines executions.
|
||||||
func (h *Handler) cronPreview(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) cronPreview(w http.ResponseWriter, r *http.Request) {
|
||||||
c, err := fleet.ParseCron(r.URL.Query().Get("expr"))
|
c, err := fleet.ParseCron(r.URL.Query().Get("expr"))
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ func (m *Manager) runAuto(ctx context.Context) {
|
|||||||
|
|
||||||
func (m *Manager) autoTick(now time.Time) {
|
func (m *Manager) autoTick(now time.Time) {
|
||||||
now = now.Truncate(time.Minute)
|
now = now.Truncate(time.Minute)
|
||||||
|
m.hostTick(now)
|
||||||
var due []string
|
var due []string
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
for key, e := range m.auto {
|
for key, e := range m.auto {
|
||||||
|
|||||||
@@ -0,0 +1,298 @@
|
|||||||
|
package fleet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Mise a jour automatique globale d'un serveur : une planification crontab
|
||||||
|
// par serveur met a jour, une par une, toutes ses stacks connues de la
|
||||||
|
// derniere analyse, sauf les stacks exclues, arretees, et celles qui ont leur
|
||||||
|
// propre planification (la planification de la stack prime). Persistee dans
|
||||||
|
// hostauto.json.
|
||||||
|
|
||||||
|
// AutoHostBy : auteur des mises a jour lancees par la planification d'un serveur.
|
||||||
|
const AutoHostBy = AutoBy + " serveur"
|
||||||
|
|
||||||
|
// Delais (variables pour les tests).
|
||||||
|
var (
|
||||||
|
hostPoll = 2 * time.Second // attente de la fin d'une mise a jour
|
||||||
|
hostBusyMax = 30 * time.Minute // attente maximale d'une connexion occupee
|
||||||
|
)
|
||||||
|
|
||||||
|
// HostStackResult : resultat d'une stack lors d'une execution globale.
|
||||||
|
type HostStackResult struct {
|
||||||
|
Target string `json:"target"`
|
||||||
|
User string `json:"user"`
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
OK bool `json:"ok"`
|
||||||
|
Skipped bool `json:"skipped,omitempty"` // rien a faire (deja a jour, arretee)
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HostAuto : planification globale d'un serveur.
|
||||||
|
type HostAuto struct {
|
||||||
|
Schedule string `json:"schedule"`
|
||||||
|
By string `json:"by,omitempty"`
|
||||||
|
Since time.Time `json:"since"`
|
||||||
|
LastRun time.Time `json:"lastRun,omitzero"`
|
||||||
|
LastOK bool `json:"lastOk"`
|
||||||
|
LastMessage string `json:"lastMessage,omitempty"`
|
||||||
|
Results []HostStackResult `json:"results,omitempty"`
|
||||||
|
|
||||||
|
pending, running bool
|
||||||
|
current string
|
||||||
|
}
|
||||||
|
|
||||||
|
// HostAutoInfo : planification d'un serveur telle qu'affichee.
|
||||||
|
type HostAutoInfo struct {
|
||||||
|
Schedule string `json:"schedule"`
|
||||||
|
By string `json:"by,omitempty"`
|
||||||
|
Since time.Time `json:"since"`
|
||||||
|
Next time.Time `json:"next,omitzero"`
|
||||||
|
LastRun time.Time `json:"lastRun,omitzero"`
|
||||||
|
LastOK bool `json:"lastOk"`
|
||||||
|
LastMessage string `json:"lastMessage,omitempty"`
|
||||||
|
Results []HostStackResult `json:"results,omitempty"`
|
||||||
|
Pending bool `json:"pending,omitempty"`
|
||||||
|
Running bool `json:"running,omitempty"`
|
||||||
|
Current string `json:"current,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *HostAuto) info(now time.Time) *HostAutoInfo {
|
||||||
|
i := &HostAutoInfo{Schedule: h.Schedule, By: h.By, Since: h.Since, LastRun: h.LastRun, LastOK: h.LastOK, LastMessage: h.LastMessage,
|
||||||
|
Results: append([]HostStackResult(nil), h.Results...), Pending: h.pending, Running: h.running, Current: h.current}
|
||||||
|
if c, err := ParseCron(h.Schedule); err == nil {
|
||||||
|
i.Next = c.Next(now)
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
// applyOutcome : dernier resultat de runApply pour une stack.
|
||||||
|
type applyOutcome struct {
|
||||||
|
res Applied
|
||||||
|
skipped bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// noteOutcomeLocked est appele par runApply a la fin de chaque mise a jour.
|
||||||
|
func (m *Manager) noteOutcomeLocked(key string, res Applied, skipped bool) {
|
||||||
|
if m.outcomes == nil {
|
||||||
|
m.outcomes = map[string]applyOutcome{}
|
||||||
|
}
|
||||||
|
m.outcomes[key] = applyOutcome{res, skipped}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) saveHostAutoLocked() error {
|
||||||
|
return writeJSON(filepath.Join(m.dir, "hostauto.json"), m.hostAuto)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) loadHostAuto() error {
|
||||||
|
if err := readJSON(filepath.Join(m.dir, "hostauto.json"), &m.hostAuto); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if m.hostAuto == nil {
|
||||||
|
m.hostAuto = map[string]*HostAuto{}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// dropHostAutoLocked oublie la planification d'un serveur supprime.
|
||||||
|
func (m *Manager) dropHostAutoLocked(serverID string) {
|
||||||
|
if _, ok := m.hostAuto[serverID]; !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
delete(m.hostAuto, serverID)
|
||||||
|
if err := m.saveHostAutoLocked(); err != nil {
|
||||||
|
slog.Error("planifications serveur non enregistrees", "err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHostAuto programme la mise a jour globale d'un serveur (schedule vide :
|
||||||
|
// la desactive).
|
||||||
|
func (m *Manager) SetHostAuto(serverID, schedule, by string) error {
|
||||||
|
schedule = strings.Join(strings.Fields(schedule), " ")
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
if m.indexLocked(serverID) < 0 {
|
||||||
|
return ErrNotFound
|
||||||
|
}
|
||||||
|
old := m.hostAuto[serverID]
|
||||||
|
if schedule == "" {
|
||||||
|
if old == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
delete(m.hostAuto, serverID)
|
||||||
|
if err := m.saveHostAutoLocked(); err != nil {
|
||||||
|
m.hostAuto[serverID] = old
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(schedule) > 100 {
|
||||||
|
return fmt.Errorf("%w : planification trop longue", ErrInvalid)
|
||||||
|
}
|
||||||
|
if _, err := ParseCron(schedule); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
h := &HostAuto{Schedule: schedule, By: by, Since: time.Now()}
|
||||||
|
if old != nil { // on garde le dernier resultat et l'execution en cours
|
||||||
|
h.LastRun, h.LastOK, h.LastMessage, h.Results = old.LastRun, old.LastOK, old.LastMessage, old.Results
|
||||||
|
h.running, h.current = old.running, old.current
|
||||||
|
}
|
||||||
|
m.hostAuto[serverID] = h
|
||||||
|
if err := m.saveHostAutoLocked(); err != nil {
|
||||||
|
if old != nil {
|
||||||
|
m.hostAuto[serverID] = old
|
||||||
|
} else {
|
||||||
|
delete(m.hostAuto, serverID)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// hostTick lance les executions globales arrivees a echeance.
|
||||||
|
func (m *Manager) hostTick(now time.Time) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
for id, h := range m.hostAuto {
|
||||||
|
if c, err := ParseCron(h.Schedule); err == nil && c.Match(now) {
|
||||||
|
h.pending = true
|
||||||
|
}
|
||||||
|
if !h.pending || h.running { // une execution en cours absorbe l'echeance
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
h.pending = false
|
||||||
|
i := m.indexLocked(id)
|
||||||
|
if i < 0 {
|
||||||
|
delete(m.hostAuto, id)
|
||||||
|
_ = m.saveHostAutoLocked()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !m.servers[i].Enabled {
|
||||||
|
h.LastRun, h.LastOK, h.LastMessage, h.Results = now, false, "ignoree : serveur desactive", nil
|
||||||
|
_ = m.saveHostAutoLocked()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
h.running = true
|
||||||
|
go m.runHostAuto(id, now)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type hostJob struct {
|
||||||
|
t Target
|
||||||
|
stack Stack
|
||||||
|
}
|
||||||
|
|
||||||
|
// hostJobsLocked : stacks a mettre a jour lors d'une execution globale.
|
||||||
|
func (m *Manager) hostJobsLocked(srv Server) []hostJob {
|
||||||
|
var jobs []hostJob
|
||||||
|
for _, t := range srv.Targets {
|
||||||
|
sc := m.scans[Key(srv.ID, t.ID)]
|
||||||
|
if sc == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, st := range sc.Stacks {
|
||||||
|
key := ExclusionKey(srv.ID, t.ID, st.Dir)
|
||||||
|
if m.excluded[key] || m.auto[key] != nil || st.Status == StatusStopped {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
jobs = append(jobs, hostJob{t, st})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jobs
|
||||||
|
}
|
||||||
|
|
||||||
|
// runHostAuto met a jour les stacks d'un serveur, une par une.
|
||||||
|
func (m *Manager) runHostAuto(serverID string, at time.Time) {
|
||||||
|
m.mu.Lock()
|
||||||
|
var jobs []hostJob
|
||||||
|
if i := m.indexLocked(serverID); i >= 0 {
|
||||||
|
jobs = m.hostJobsLocked(m.servers[i])
|
||||||
|
}
|
||||||
|
m.mu.Unlock()
|
||||||
|
|
||||||
|
results := make([]HostStackResult, 0, len(jobs))
|
||||||
|
for _, j := range jobs {
|
||||||
|
r := HostStackResult{Target: j.t.ID, User: j.t.User, Dir: j.stack.Dir, Name: j.stack.Name}
|
||||||
|
m.mu.Lock()
|
||||||
|
if h := m.hostAuto[serverID]; h != nil {
|
||||||
|
h.current = j.stack.Dir
|
||||||
|
} else { // planification supprimee entre-temps
|
||||||
|
m.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.mu.Unlock()
|
||||||
|
r.OK, r.Skipped, r.Message = m.applyAndWait(serverID, j.t.ID, j.stack.Dir)
|
||||||
|
results = append(results, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, restarted, skipped, failed := true, 0, 0, 0
|
||||||
|
for _, r := range results {
|
||||||
|
switch {
|
||||||
|
case !r.OK:
|
||||||
|
ok = false
|
||||||
|
failed++
|
||||||
|
case r.Skipped:
|
||||||
|
skipped++
|
||||||
|
default:
|
||||||
|
restarted++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg := fmt.Sprintf("%d stack(s) : %d relancee(s), %d sans changement, %d en echec", len(results), restarted, skipped, failed)
|
||||||
|
if len(results) == 0 {
|
||||||
|
msg = "aucune stack a mettre a jour (lancer une analyse ?)"
|
||||||
|
}
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
if h := m.hostAuto[serverID]; h != nil {
|
||||||
|
h.running, h.current = false, ""
|
||||||
|
h.LastRun, h.LastOK, h.LastMessage, h.Results = at, ok, msg, results
|
||||||
|
if err := m.saveHostAutoLocked(); err != nil {
|
||||||
|
slog.Error("planifications serveur non enregistrees", "err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slog.Info("mise a jour globale programmee", "server", serverID, "result", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// applyAndWait lance la mise a jour d'une stack et attend son resultat ; une
|
||||||
|
// connexion occupee (analyse en cours) est attendue jusqu'a hostBusyMax.
|
||||||
|
func (m *Manager) applyAndWait(serverID, targetID, dir string) (ok, skipped bool, msg string) {
|
||||||
|
key := ExclusionKey(serverID, targetID, dir)
|
||||||
|
m.mu.Lock()
|
||||||
|
delete(m.outcomes, key)
|
||||||
|
m.mu.Unlock()
|
||||||
|
deadline := time.Now().Add(hostBusyMax)
|
||||||
|
for {
|
||||||
|
err := m.Apply(serverID, targetID, dir, AutoHostBy)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if !errors.Is(err, ErrBusy) || time.Now().After(deadline) {
|
||||||
|
return false, false, err.Error()
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-m.base.Done():
|
||||||
|
return false, false, "arret de stackwatch"
|
||||||
|
case <-time.After(hostPoll):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
m.mu.Lock()
|
||||||
|
o, done := m.outcomes[key]
|
||||||
|
m.mu.Unlock()
|
||||||
|
if done {
|
||||||
|
return o.res.OK, o.skipped, o.res.Message
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-m.base.Done():
|
||||||
|
return false, false, "arret de stackwatch"
|
||||||
|
case <-time.After(hostPoll):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package fleet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHostAuto(t *testing.T) {
|
||||||
|
hostPoll = 5 * time.Millisecond
|
||||||
|
dir := t.TempDir()
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
m, err := Open(ctx, dir, exclTestRunner{}, 1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
srv, err := m.Add(Server{Name: "s1", Host: "h1", Enabled: true, Targets: []Target{{User: "root"}}})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
tid := srv.Targets[0].ID
|
||||||
|
m.scans[Key(srv.ID, tid)] = &Scan{Stacks: []Stack{
|
||||||
|
{Dir: "/home/a", Name: "a", Status: StatusUpdates},
|
||||||
|
{Dir: "/home/b", Name: "b", Status: StatusUpToDate},
|
||||||
|
{Dir: "/home/c", Name: "c", Status: StatusUpdates},
|
||||||
|
{Dir: "/home/d", Name: "d", Status: StatusStopped},
|
||||||
|
}}
|
||||||
|
if err := m.SetExcluded(srv.ID, tid, "/home/b", true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := m.SetAuto(srv.ID, tid, "/home/c", "0 0 1 1 *", "test"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := m.SetHostAuto(srv.ID, "* 25 * * *", "test"); !errors.Is(err, ErrInvalid) {
|
||||||
|
t.Fatalf("planification invalide : %v", err)
|
||||||
|
}
|
||||||
|
if err := m.SetHostAuto("inconnu", "@daily", "test"); !errors.Is(err, ErrNotFound) {
|
||||||
|
t.Fatalf("serveur inconnu : %v", err)
|
||||||
|
}
|
||||||
|
if err := m.SetHostAuto(srv.ID, "0 3 * * *", "test"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if v := m.Snapshot()[0]; v.Auto == nil || v.Auto.Schedule != "0 3 * * *" || v.Auto.Next.IsZero() {
|
||||||
|
t.Fatalf("planification non affichee : %+v", v.Auto)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Echeance : seule /home/a est traitee (b exclue, c planifiee a part, d arretee).
|
||||||
|
m.hostTick(time.Date(2026, 1, 1, 3, 0, 0, 0, time.Local))
|
||||||
|
deadline := time.Now().Add(5 * time.Second)
|
||||||
|
var h HostAuto
|
||||||
|
for {
|
||||||
|
m.mu.Lock()
|
||||||
|
h = *m.hostAuto[srv.ID]
|
||||||
|
m.mu.Unlock()
|
||||||
|
if !h.running {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if time.Now().After(deadline) {
|
||||||
|
t.Fatal("execution non terminee")
|
||||||
|
}
|
||||||
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
}
|
||||||
|
if len(h.Results) != 1 || h.Results[0].Dir != "/home/a" || h.LastRun.IsZero() {
|
||||||
|
t.Fatalf("resultats : %+v", h)
|
||||||
|
}
|
||||||
|
if h.LastOK || h.Results[0].OK { // exclTestRunner ne repond rien
|
||||||
|
t.Fatalf("echec attendu : %+v", h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Persistance.
|
||||||
|
m2, err := Open(ctx, dir, exclTestRunner{}, 1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if e := m2.hostAuto[srv.ID]; e == nil || e.Schedule != "0 3 * * *" || len(e.Results) != 1 {
|
||||||
|
t.Fatal("planification non relue")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desactivation, puis suppression du serveur.
|
||||||
|
if err := m.SetHostAuto(srv.ID, "", "test"); err != nil || m.hostAuto[srv.ID] != nil {
|
||||||
|
t.Fatalf("desactivation : %v", err)
|
||||||
|
}
|
||||||
|
if err := m.SetHostAuto(srv.ID, "@daily", "test"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := m.Delete(srv.ID); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(m.hostAuto) != 0 {
|
||||||
|
t.Fatalf("planifications restantes : %v", m.hostAuto)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,8 @@ type Manager struct {
|
|||||||
scans map[string]*Scan
|
scans map[string]*Scan
|
||||||
excluded map[string]bool // ExclusionKey -> stack exclue des mises à jour
|
excluded map[string]bool // ExclusionKey -> stack exclue des mises à jour
|
||||||
auto map[string]*AutoEntry
|
auto map[string]*AutoEntry
|
||||||
|
hostAuto map[string]*HostAuto
|
||||||
|
outcomes map[string]applyOutcome
|
||||||
watchers sync.WaitGroup
|
watchers sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +55,9 @@ func Open(ctx context.Context, dir string, r Runner, parallel int) (*Manager, er
|
|||||||
if err := m.loadAuto(); err != nil {
|
if err := m.loadAuto(); err != nil {
|
||||||
return nil, fmt.Errorf("autoupdate.json : %w", err)
|
return nil, fmt.Errorf("autoupdate.json : %w", err)
|
||||||
}
|
}
|
||||||
|
if err := m.loadHostAuto(); err != nil {
|
||||||
|
return nil, fmt.Errorf("hostauto.json : %w", err)
|
||||||
|
}
|
||||||
if err := readJSON(filepath.Join(dir, "state.json"), &m.scans); err != nil {
|
if err := readJSON(filepath.Join(dir, "state.json"), &m.scans); err != nil {
|
||||||
slog.Warn("state.json illisible, résultats ignorés", "err", err)
|
slog.Warn("state.json illisible, résultats ignorés", "err", err)
|
||||||
m.scans = map[string]*Scan{}
|
m.scans = map[string]*Scan{}
|
||||||
@@ -105,6 +110,8 @@ func (m *Manager) saveStateLocked() {
|
|||||||
type View struct {
|
type View struct {
|
||||||
Server
|
Server
|
||||||
Scans map[string]Scan `json:"scans"`
|
Scans map[string]Scan `json:"scans"`
|
||||||
|
// Auto : mise a jour globale programmee du serveur.
|
||||||
|
Auto *HostAutoInfo `json:"auto,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyScan(s *Scan) Scan {
|
func copyScan(s *Scan) Scan {
|
||||||
@@ -121,6 +128,9 @@ func (m *Manager) Snapshot() []View {
|
|||||||
out := make([]View, 0, len(m.servers))
|
out := make([]View, 0, len(m.servers))
|
||||||
for _, s := range m.servers {
|
for _, s := range m.servers {
|
||||||
v := View{Server: s, Scans: map[string]Scan{}}
|
v := View{Server: s, Scans: map[string]Scan{}}
|
||||||
|
if h := m.hostAuto[s.ID]; h != nil {
|
||||||
|
v.Auto = h.info(time.Now())
|
||||||
|
}
|
||||||
v.Targets = append([]Target(nil), s.Targets...)
|
v.Targets = append([]Target(nil), s.Targets...)
|
||||||
for _, t := range s.Targets {
|
for _, t := range s.Targets {
|
||||||
if sc, ok := m.scans[Key(s.ID, t.ID)]; ok {
|
if sc, ok := m.scans[Key(s.ID, t.ID)]; ok {
|
||||||
@@ -271,6 +281,7 @@ func (m *Manager) Delete(id string) error {
|
|||||||
delete(m.scans, Key(id, t.ID))
|
delete(m.scans, Key(id, t.ID))
|
||||||
m.dropExclusionsLocked(Key(id, t.ID))
|
m.dropExclusionsLocked(Key(id, t.ID))
|
||||||
}
|
}
|
||||||
|
m.dropHostAutoLocked(id)
|
||||||
m.saveStateLocked()
|
m.saveStateLocked()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -493,7 +504,7 @@ func (m *Manager) runApply(srv Server, t Target, dir, by string) {
|
|||||||
// Planification : autoapply ne relance la stack que si une image a change
|
// Planification : autoapply ne relance la stack que si une image a change
|
||||||
// ("skip" sinon : stack laissee telle quelle).
|
// ("skip" sinon : stack laissee telle quelle).
|
||||||
mode, skipped := "apply", false
|
mode, skipped := "apply", false
|
||||||
if by == AutoBy {
|
if strings.HasPrefix(by, AutoBy) { // stack ou serveur
|
||||||
mode = "autoapply"
|
mode = "autoapply"
|
||||||
}
|
}
|
||||||
err := m.Runner.Run(ctx, srv.Host, srv.Port, t.User, []string{mode, dir}, func(line string) {
|
err := m.Runner.Run(ctx, srv.Host, srv.Port, t.User, []string{mode, dir}, func(line string) {
|
||||||
@@ -533,6 +544,7 @@ func (m *Manager) runApply(srv Server, t Target, dir, by string) {
|
|||||||
if by == AutoBy {
|
if by == AutoBy {
|
||||||
m.recordAutoLocked(ExclusionKey(srv.ID, t.ID, dir), res.At, res.OK, res.Message)
|
m.recordAutoLocked(ExclusionKey(srv.ID, t.ID, dir), res.At, res.OK, res.Message)
|
||||||
}
|
}
|
||||||
|
m.noteOutcomeLocked(ExclusionKey(srv.ID, t.ID, dir), res, skipped)
|
||||||
sc.Running, sc.Task, sc.Current = false, "", ""
|
sc.Running, sc.Task, sc.Current = false, "", ""
|
||||||
m.saveStateLocked()
|
m.saveStateLocked()
|
||||||
slog.Info("mise à jour de stack", "server", srv.Name, "user", t.User, "dir", dir, "by", by, "ok", res.OK, "msg", res.Message)
|
slog.Info("mise à jour de stack", "server", srv.Name, "user", t.User, "dir", dir, "by", by, "ok", res.OK, "msg", res.Message)
|
||||||
|
|||||||
Reference in new issue
Block a user