Restart a server after its updates, and check that it came back
An update run can name a second Semaphore playbook that restarts the server once the updates are in and it says a restart is due. The run keeps the maintenance window up, follows the restart, waits for the server to report again and checks from its uptime (or its restart flag clearing) that it did start again. A server that only needs a restart has a Restart button on the Updates page, and a patch plan can carry the restart playbook too. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
97df28c6dc
commit
e4f3a54189
19 files changed
+10275
-87
No files matched your search
+19
-1
@@ -858,7 +858,7 @@ export interface UpdateRun {
|
||||
taskId: number | null;
|
||||
/** Semaphore's own word for the run. */
|
||||
taskStatus: string | null;
|
||||
status: "running" | "waiting_for_host" | "done" | "failed" | "cancelled";
|
||||
status: "running" | "waiting_for_host" | "restarting" | "waiting_for_restart" | "done" | "failed" | "cancelled";
|
||||
active: boolean;
|
||||
message: string | null;
|
||||
startedBy: string | null;
|
||||
@@ -868,6 +868,16 @@ export interface UpdateRun {
|
||||
updatesBefore: number | null;
|
||||
updatesAfter: number | null;
|
||||
rebootRequired: boolean;
|
||||
/** "restart": a restart on its own (the template is the restart playbook). */
|
||||
kind: "update" | "restart";
|
||||
/** The playbook that restarts the server once its updates are in, if one was chosen. */
|
||||
restartTemplate: string | null;
|
||||
restartTaskId: number | null;
|
||||
restartTaskStatus: string | null;
|
||||
/** ISO — when the restart playbook was started (after the updates). */
|
||||
restartedAt: string | null;
|
||||
/** The server was seen to have started again. */
|
||||
restarted: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateRunInput {
|
||||
@@ -879,6 +889,10 @@ export interface UpdateRunInput {
|
||||
windowMinutes: number;
|
||||
/** Somebody is streaming from the machine and the person has seen the warning. */
|
||||
startAnyway?: boolean;
|
||||
/** "restart": the template is a playbook that only restarts the server. */
|
||||
kind?: "update" | "restart";
|
||||
/** Restart the server with this playbook (same Semaphore) once the updates are in, if it says a restart is due. */
|
||||
restart?: { projectId: number; templateId: number };
|
||||
}
|
||||
|
||||
export interface UpdatesServer {
|
||||
@@ -1216,6 +1230,10 @@ export interface PatchPlan {
|
||||
onlyWithUpdates: boolean;
|
||||
silenceDependents: boolean;
|
||||
windowMinutes: number;
|
||||
/** The playbook that restarts a server that says a restart is due after its updates (in the same Semaphore); null = none. */
|
||||
restartProjectId: number | null;
|
||||
restartTemplateId: number | null;
|
||||
restartTemplateName: string | null;
|
||||
createdBy: string | null;
|
||||
/** The servers it covers right now. */
|
||||
servers: { id: number; name: string }[];
|
||||
|
||||
@@ -85,9 +85,14 @@ interface Draft {
|
||||
onlyWithUpdates: boolean;
|
||||
silenceDependents: boolean;
|
||||
windowMinutes: number;
|
||||
/** The playbook that restarts a server that says a restart is due after its updates ("" = none); a template key like the update one. */
|
||||
restart: string;
|
||||
}
|
||||
|
||||
const EMPTY: Draft = { id: null, name: "", enabled: true, days: [0], startTime: "02:00", timezone: browserZone(), tags: [], serverIds: [], template: "", limitFrom: "name", stopOnFailure: true, onlyWithUpdates: true, silenceDependents: true, windowMinutes: 90 };
|
||||
const EMPTY: Draft = { id: null, name: "", enabled: true, days: [0], startTime: "02:00", timezone: browserZone(), tags: [], serverIds: [], template: "", limitFrom: "name", stopOnFailure: true, onlyWithUpdates: true, silenceDependents: true, windowMinutes: 90, restart: "" };
|
||||
|
||||
/** A plan's restart playbook as a template key ("" = none). */
|
||||
const restartKeyOf = (p: PatchPlan): string => (p.restartTemplateId !== null && p.restartProjectId !== null ? `${p.integrationId}:${p.restartProjectId}:${p.restartTemplateId}` : "");
|
||||
|
||||
function Progress({ run, canStop, onStop }: { run: PatchPlanRun; canStop: boolean; onStop: () => void }) {
|
||||
return (
|
||||
@@ -176,7 +181,7 @@ export default function PatchPlans({ user }: { user: CurrentUser }) {
|
||||
}, [draft, data]);
|
||||
|
||||
function edit(p: PatchPlan) {
|
||||
setDraft({ id: p.id, name: p.name, enabled: p.enabled, days: p.days, startTime: p.startTime, timezone: p.timezone, tags: p.tags, serverIds: p.serverIds, template: `${p.integrationId}:${p.projectId}:${p.templateId}`, limitFrom: p.limitFrom, stopOnFailure: p.stopOnFailure, onlyWithUpdates: p.onlyWithUpdates, silenceDependents: p.silenceDependents, windowMinutes: p.windowMinutes });
|
||||
setDraft({ id: p.id, name: p.name, enabled: p.enabled, days: p.days, startTime: p.startTime, timezone: p.timezone, tags: p.tags, serverIds: p.serverIds, template: `${p.integrationId}:${p.projectId}:${p.templateId}`, limitFrom: p.limitFrom, stopOnFailure: p.stopOnFailure, onlyWithUpdates: p.onlyWithUpdates, silenceDependents: p.silenceDependents, windowMinutes: p.windowMinutes, restart: restartKeyOf(p) });
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
@@ -185,10 +190,26 @@ export default function PatchPlans({ user }: { user: CurrentUser }) {
|
||||
// Editing a plan whose playbook was not looked up still keeps what it has.
|
||||
const picked = templates?.find((t) => t.key === draft.template);
|
||||
const existing = draft.id !== null ? data?.plans.find((p) => p.id === draft.id) : undefined;
|
||||
// The restart playbook: none, one picked from the list, or the one the plan already has (when the list could not be read).
|
||||
const restartPicked = draft.restart ? templates?.find((t) => t.key === draft.restart) : undefined;
|
||||
const restartKept = existing && draft.restart !== "" && draft.restart === restartKeyOf(existing) ? existing : undefined;
|
||||
if (draft.restart !== "" && !restartPicked && !restartKept) {
|
||||
setError("Choose the restart playbook again, or none.");
|
||||
return;
|
||||
}
|
||||
if (restartPicked && restartPicked.integration.id !== (picked?.integration.id ?? existing?.integrationId)) {
|
||||
setError("The restart playbook has to be in the same Semaphore as the one that applies updates.");
|
||||
return;
|
||||
}
|
||||
const restartFields = restartPicked
|
||||
? { restartProjectId: restartPicked.template.projectId, restartTemplateId: restartPicked.template.id, restartTemplateName: restartPicked.template.name }
|
||||
: restartKept
|
||||
? { restartProjectId: restartKept.restartProjectId, restartTemplateId: restartKept.restartTemplateId, restartTemplateName: restartKept.restartTemplateName }
|
||||
: { restartProjectId: null, restartTemplateId: null, restartTemplateName: null };
|
||||
const input: PatchPlanInput | null = picked
|
||||
? { name: draft.name.trim(), enabled: draft.enabled, days: draft.days, startTime: draft.startTime, timezone: draft.timezone, tags: draft.tags, serverIds: draft.serverIds, integrationId: picked.integration.id, projectId: picked.template.projectId, templateId: picked.template.id, templateName: picked.template.name, limitFrom: draft.limitFrom, stopOnFailure: draft.stopOnFailure, onlyWithUpdates: draft.onlyWithUpdates, silenceDependents: draft.silenceDependents, windowMinutes: draft.windowMinutes }
|
||||
? { ...restartFields, name: draft.name.trim(), enabled: draft.enabled, days: draft.days, startTime: draft.startTime, timezone: draft.timezone, tags: draft.tags, serverIds: draft.serverIds, integrationId: picked.integration.id, projectId: picked.template.projectId, templateId: picked.template.id, templateName: picked.template.name, limitFrom: draft.limitFrom, stopOnFailure: draft.stopOnFailure, onlyWithUpdates: draft.onlyWithUpdates, silenceDependents: draft.silenceDependents, windowMinutes: draft.windowMinutes }
|
||||
: existing && draft.template === `${existing.integrationId}:${existing.projectId}:${existing.templateId}`
|
||||
? { name: draft.name.trim(), enabled: draft.enabled, days: draft.days, startTime: draft.startTime, timezone: draft.timezone, tags: draft.tags, serverIds: draft.serverIds, integrationId: existing.integrationId, projectId: existing.projectId, templateId: existing.templateId, templateName: existing.templateName, limitFrom: draft.limitFrom, stopOnFailure: draft.stopOnFailure, onlyWithUpdates: draft.onlyWithUpdates, silenceDependents: draft.silenceDependents, windowMinutes: draft.windowMinutes }
|
||||
? { ...restartFields, name: draft.name.trim(), enabled: draft.enabled, days: draft.days, startTime: draft.startTime, timezone: draft.timezone, tags: draft.tags, serverIds: draft.serverIds, integrationId: existing.integrationId, projectId: existing.projectId, templateId: existing.templateId, templateName: existing.templateName, limitFrom: draft.limitFrom, stopOnFailure: draft.stopOnFailure, onlyWithUpdates: draft.onlyWithUpdates, silenceDependents: draft.silenceDependents, windowMinutes: draft.windowMinutes }
|
||||
: null;
|
||||
if (!input) {
|
||||
setError("Choose the playbook that applies updates.");
|
||||
@@ -211,7 +232,7 @@ export default function PatchPlans({ user }: { user: CurrentUser }) {
|
||||
|
||||
async function runNow(p: PatchPlan) {
|
||||
const names = p.servers.map((s) => s.name);
|
||||
if (!(await confirmDialog({ title: `Run ${p.name} now?`, message: `It updates ${names.length === 1 ? names[0] : `${names.length} servers (${names.slice(0, 5).join(", ")}${names.length > 5 ? " …" : ""})`}, one at a time${p.stopOnFailure ? ", and stops at the first failure" : ""}. ${p.onlyWithUpdates ? "Servers with nothing waiting are left alone. " : ""}Each is put under maintenance while it is updated and may restart.`, confirmLabel: "Run it now" }))) return;
|
||||
if (!(await confirmDialog({ title: `Run ${p.name} now?`, message: `It updates ${names.length === 1 ? names[0] : `${names.length} servers (${names.slice(0, 5).join(", ")}${names.length > 5 ? " …" : ""})`}, one at a time${p.stopOnFailure ? ", and stops at the first failure" : ""}. ${p.onlyWithUpdates ? "Servers with nothing waiting are left alone. " : ""}Each is put under maintenance while it is updated${p.restartTemplateName ? `, and restarted (with "${p.restartTemplateName}") if it says a restart is due` : " and may restart"}.`, confirmLabel: "Run it now" }))) return;
|
||||
try {
|
||||
await api.patchPlans.run(p.id);
|
||||
toast.success(`Started ${p.name}.`);
|
||||
@@ -381,6 +402,26 @@ export default function PatchPlans({ user }: { user: CurrentUser }) {
|
||||
<div className="form-hint text-secondary small mt-1">Must match the host name in the Semaphore inventory.</div>
|
||||
</div>
|
||||
|
||||
{templates !== null && (
|
||||
<div className="col-md-8">
|
||||
<label className="form-label" htmlFor="pp-restart">
|
||||
Restart a server afterwards, if it says a restart is due, with
|
||||
</label>
|
||||
<select id="pp-restart" className="form-select" value={draft.restart} onChange={(e) => set("restart", e.target.value)}>
|
||||
<option value="">No second playbook (the update playbook may restart it itself)</option>
|
||||
{draft.id !== null && draft.restart !== "" && !templates.some((t) => t.key === draft.restart) && <option value={draft.restart}>{data.plans.find((p) => p.id === draft.id)?.restartTemplateName ?? "the current one"} (as it is now)</option>}
|
||||
{templates
|
||||
.filter((t) => t.key !== draft.template && t.integration.id === Number(draft.template.split(":")[0]))
|
||||
.map((t) => (
|
||||
<option key={t.key} value={t.key}>
|
||||
{t.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="form-hint text-secondary small mt-1">A playbook that only restarts the server, in the same Semaphore. It runs once a server's updates are in; a server with nothing waiting that still says a restart is due is restarted too. Each restart is checked: the server must report that it started again. The window below counts for the update and the restart together.</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="col-12 d-flex flex-column gap-2">
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={draft.stopOnFailure} onChange={(e) => set("stopOnFailure", e.target.checked)} />
|
||||
@@ -448,7 +489,8 @@ export default function PatchPlans({ user }: { user: CurrentUser }) {
|
||||
<td className="stack-wide">
|
||||
<strong>{p.name}</strong> {!p.enabled && <span className="badge bg-secondary-lt text-secondary">Switched off</span>} {p.running && <span className="badge bg-blue-lt text-blue">Running</span>}
|
||||
<div className="text-secondary small">
|
||||
{p.templateName} · {p.stopOnFailure ? "stops at the first failure" : "carries on after a failure"}
|
||||
{p.templateName}
|
||||
{p.restartTemplateName ? ` · restarts with ${p.restartTemplateName} if one is due` : ""} · {p.stopOnFailure ? "stops at the first failure" : "carries on after a failure"}
|
||||
</div>
|
||||
</td>
|
||||
<td className="stack-label" data-label="When">
|
||||
|
||||
@@ -22,25 +22,37 @@ const WINDOWS = [
|
||||
];
|
||||
|
||||
const LAST_KEY = "hlm.updateRun.template";
|
||||
const remembered = () => {
|
||||
const RESTART_KEY = "hlm.updateRun.restartTemplate";
|
||||
const remembered = (key: string) => {
|
||||
try {
|
||||
return localStorage.getItem(LAST_KEY) ?? "";
|
||||
return localStorage.getItem(key) ?? "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
const remember = (key: string, value: string) => {
|
||||
try {
|
||||
localStorage.setItem(key, value);
|
||||
} catch {
|
||||
// a remembered choice is only a convenience
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* "Update this server now": pick the playbook that applies updates, and Homelab Manager puts the server under maintenance, runs it for this
|
||||
* server only, follows it, waits for the server to report again and says what is left and whether a restart is due. It asks before it
|
||||
* starts, and says what it will do.
|
||||
* "Update this server now" (mode "update"): pick the playbook that applies updates, and Homelab Manager puts the server under maintenance, runs it for this
|
||||
* server only, follows it, waits for the server to report again and says what is left and whether a restart is due. A second playbook can be chosen to
|
||||
* restart the server afterwards, if it says a restart is due; it is then checked that the server started again. Mode "restart" does only the restart, for a
|
||||
* server that already says one is due. It asks before it starts, and says what it will do.
|
||||
*/
|
||||
export default function UpdateRunDrawer({ server, onClose, onStarted }: { server: UpdatesServer; onClose: () => void; onStarted: () => void }) {
|
||||
export default function UpdateRunDrawer({ server, mode = "update", onClose, onStarted }: { server: UpdatesServer; mode?: "update" | "restart"; onClose: () => void; onStarted: () => void }) {
|
||||
const restartOnly = mode === "restart";
|
||||
const [loaded, setLoaded] = useState<Loaded[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [choice, setChoice] = useState(remembered);
|
||||
const [choice, setChoice] = useState(() => remembered(restartOnly ? RESTART_KEY : LAST_KEY));
|
||||
// The playbook that restarts afterwards (an update only): "" is none.
|
||||
const [restartChoice, setRestartChoice] = useState(() => remembered(RESTART_KEY));
|
||||
const [limit, setLimit] = useState(server.name);
|
||||
const [minutes, setMinutes] = useState(90);
|
||||
const [minutes, setMinutes] = useState(restartOnly ? 45 : 90);
|
||||
const [busy, setBusy] = useState(false);
|
||||
// People streaming from a Jellyfin on this machine: the update may restart it, so they are named first and the person asked.
|
||||
const [watching, setWatching] = useState("");
|
||||
@@ -75,25 +87,47 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
l.templates.map((t) => ({ key: `${l.integration.id}:${t.projectId}:${t.id}`, integration: l.integration, template: t, label: `${t.name} — ${t.projectName}${(loaded ?? []).length > 1 ? ` (${l.integration.name})` : ""}` })),
|
||||
);
|
||||
const picked = options.find((o) => o.key === choice);
|
||||
// The restart playbook has to be in the same Semaphore as the update's.
|
||||
const restartOptions = picked ? options.filter((o) => o.integration.id === picked.integration.id && o.key !== picked.key) : [];
|
||||
const restartPicked = !restartOnly ? restartOptions.find((o) => o.key === restartChoice) : undefined;
|
||||
const count = server.updates?.count ?? null;
|
||||
const windowWords = WINDOWS.find((w) => w.minutes === minutes)?.label ?? `${minutes} minutes`;
|
||||
|
||||
async function start() {
|
||||
if (!picked) return;
|
||||
const ok = await confirmDialog({
|
||||
title: `Update ${server.name} now?`,
|
||||
message: `${watching ? `${watching[0].toUpperCase()}${watching.slice(1)}, and the update may restart the machine. ` : ""}This silences alerts for ${server.name} for up to ${WINDOWS.find((w) => w.minutes === minutes)?.label ?? `${minutes} minutes`}, runs "${picked.template.name}" in ${picked.integration.name} limited to ${limit.trim()}, and waits for the server to report again. The playbook may restart it.`,
|
||||
confirmLabel: watching ? "Update anyway" : "Start the update",
|
||||
});
|
||||
const lead = watching ? `${watching[0].toUpperCase()}${watching.slice(1)}, and ${restartOnly ? "the restart" : "the update may restart the machine"}. ` : "";
|
||||
const ok = await confirmDialog(
|
||||
restartOnly
|
||||
? {
|
||||
title: `Restart ${server.name} now?`,
|
||||
message: `${lead}This silences alerts for ${server.name} for up to ${windowWords}, runs "${picked.template.name}" in ${picked.integration.name} limited to ${limit.trim()} — which restarts it — and waits for the server to report again, then checks that it did start again. What runs on it, and what depends on it, will be down for a while.`,
|
||||
confirmLabel: watching ? "Restart anyway" : "Restart it",
|
||||
danger: true,
|
||||
}
|
||||
: {
|
||||
title: `Update ${server.name} now?`,
|
||||
message: `${lead}This silences alerts for ${server.name} for up to ${windowWords}, runs "${picked.template.name}" in ${picked.integration.name} limited to ${limit.trim()}, and waits for the server to report again. ${
|
||||
restartPicked ? `If it then says a restart is due, "${restartPicked.template.name}" restarts it — the machine will be down for a while — and Homelab Manager checks that it came back.` : "The playbook may restart it."
|
||||
}`,
|
||||
confirmLabel: watching ? "Update anyway" : restartPicked ? "Start the update and restart" : "Start the update",
|
||||
},
|
||||
);
|
||||
if (!ok) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.updateRuns.start({ serverId: server.id, integrationId: picked.integration.id, projectId: picked.template.projectId, templateId: picked.template.id, limit: limit.trim(), windowMinutes: minutes, startAnyway: watching !== "" });
|
||||
try {
|
||||
localStorage.setItem(LAST_KEY, picked.key);
|
||||
} catch {
|
||||
// a remembered choice is only a convenience
|
||||
}
|
||||
toast.success(`Started updating ${server.name}.`);
|
||||
await api.updateRuns.start({
|
||||
serverId: server.id,
|
||||
integrationId: picked.integration.id,
|
||||
projectId: picked.template.projectId,
|
||||
templateId: picked.template.id,
|
||||
limit: limit.trim(),
|
||||
windowMinutes: minutes,
|
||||
startAnyway: watching !== "",
|
||||
...(restartOnly ? { kind: "restart" as const } : restartPicked ? { restart: { projectId: restartPicked.template.projectId, templateId: restartPicked.template.id } } : {}),
|
||||
});
|
||||
remember(restartOnly ? RESTART_KEY : LAST_KEY, picked.key);
|
||||
if (!restartOnly) remember(RESTART_KEY, restartPicked ? restartPicked.key : "");
|
||||
toast.success(restartOnly ? `Started restarting ${server.name}.` : `Started updating ${server.name}.`);
|
||||
onStarted();
|
||||
onClose();
|
||||
} catch (err) {
|
||||
@@ -104,7 +138,7 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
}
|
||||
|
||||
return (
|
||||
<DetailDrawer title={`Update ${server.name}`} subtitle={server.osType === "windows" ? "Windows" : "Linux"} onClose={onClose}>
|
||||
<DetailDrawer title={`${restartOnly ? "Restart" : "Update"} ${server.name}`} subtitle={server.osType === "windows" ? "Windows" : "Linux"} onClose={onClose}>
|
||||
<div className="mb-3">
|
||||
<UpdatesBadge updates={server.updates} />
|
||||
{count !== null && count > 0 && server.updates && server.updates.security !== null && <span className="text-secondary small ms-2">{server.updates.security} of them security</span>}
|
||||
@@ -116,7 +150,7 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
<BlockSkeleton lines={3} />
|
||||
) : loaded.length === 0 ? (
|
||||
<div className="text-secondary">
|
||||
There is no Semaphore connected. Add one under <Link to="/integrations">Integrations</Link>, with a playbook that applies updates, and this server can be updated from here.
|
||||
There is no Semaphore connected. Add one under <Link to="/integrations">Integrations</Link>, with a playbook that {restartOnly ? "restarts a server" : "applies updates"}, and this server can be {restartOnly ? "restarted" : "updated"} from here.
|
||||
</div>
|
||||
) : options.length === 0 ? (
|
||||
<div className="text-secondary">No templates found in Semaphore.</div>
|
||||
@@ -128,18 +162,25 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
{watching && (
|
||||
<div className="alert alert-warning" role="status">
|
||||
<strong>Somebody is watching.</strong> {watching[0].toUpperCase()}
|
||||
{watching.slice(1)}. The update may restart this machine; you will be asked once more.
|
||||
{watching.slice(1)}. {restartOnly ? "The restart will cut them off" : "The update may restart this machine"}; you will be asked once more.
|
||||
</div>
|
||||
)}
|
||||
<ol className="text-secondary small ps-3 mb-3">
|
||||
<li>Alerts for this server are silenced (a maintenance window).</li>
|
||||
<li>The playbook runs in Semaphore, for this server only.</li>
|
||||
<li>Homelab Manager waits for the server to report again — it may be restarting.</li>
|
||||
<li>It tells you what is still waiting and whether a restart is due, and the window ends.</li>
|
||||
{restartOnly ? (
|
||||
<li>It checks that the server did start again (from its uptime), and the window ends.</li>
|
||||
) : (
|
||||
<>
|
||||
{restartPicked && <li>If the server then says a restart is due, the restart playbook runs, and the server is checked to have started again.</li>}
|
||||
<li>It tells you what is still waiting{restartPicked ? "" : " and whether a restart is due"}, and the window ends.</li>
|
||||
</>
|
||||
)}
|
||||
</ol>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ur-template">
|
||||
Playbook that applies updates
|
||||
{restartOnly ? "Playbook that restarts the server" : "Playbook that applies updates"}
|
||||
</label>
|
||||
<select id="ur-template" className="form-select" value={choice} onChange={(e) => setChoice(e.target.value)}>
|
||||
<option value="">Choose a template…</option>
|
||||
@@ -150,12 +191,28 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
{!restartOnly && (
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ur-restart">
|
||||
Restart it afterwards, if it says a restart is due, with
|
||||
</label>
|
||||
<select id="ur-restart" className="form-select" value={restartPicked ? restartChoice : ""} onChange={(e) => setRestartChoice(e.target.value)} disabled={!picked}>
|
||||
<option value="">No second playbook (the update playbook may restart it itself)</option>
|
||||
{restartOptions.map((o) => (
|
||||
<option key={o.key} value={o.key}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="form-hint text-secondary small mt-1">A playbook that only restarts the server. It runs once the updates are in and the server has reported again.</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ur-limit">
|
||||
Run it on — the host name as it is in the Semaphore inventory
|
||||
</label>
|
||||
<input id="ur-limit" className="form-control" value={limit} maxLength={200} onChange={(e) => setLimit(e.target.value)} placeholder="e.g. web01" />
|
||||
<div className="form-hint text-secondary small mt-1">An update run is always for this one server, never the whole inventory.</div>
|
||||
<div className="form-hint text-secondary small mt-1">{restartOnly ? "A restart" : "An update run"} is always for this one server, never the whole inventory.</div>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ur-window">
|
||||
@@ -168,10 +225,10 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="form-hint text-secondary small mt-1">The window ends sooner, as soon as the run does.</div>
|
||||
<div className="form-hint text-secondary small mt-1">The window ends sooner, as soon as the run does.{restartPicked ? " If a restart follows, the quiet is kept up for it as well." : ""}</div>
|
||||
</div>
|
||||
<button type="button" className="btn btn-primary" disabled={!picked || busy || limit.trim() === ""} onClick={() => void start()}>
|
||||
{busy ? "Starting…" : "Update now"}
|
||||
<button type="button" className={`btn ${restartOnly ? "btn-warning" : "btn-primary"}`} disabled={!picked || busy || limit.trim() === ""} onClick={() => void start()}>
|
||||
{busy ? "Starting…" : restartOnly ? "Restart now" : restartPicked ? "Update and restart" : "Update now"}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -21,7 +21,11 @@ export function describeRun(run: UpdateRun): { label: string; badge: string } {
|
||||
case "running":
|
||||
return { label: TASK_WORDS[run.taskStatus ?? ""] ?? "playbook running", badge: "bg-blue-lt text-blue" };
|
||||
case "waiting_for_host":
|
||||
return { label: "waiting for the server to report again", badge: "bg-blue-lt text-blue" };
|
||||
return { label: run.kind === "restart" ? "waiting for the server to come back" : "waiting for the server to report again", badge: "bg-blue-lt text-blue" };
|
||||
case "restarting":
|
||||
return { label: TASK_WORDS[run.restartTaskStatus ?? ""] ? `restart: ${TASK_WORDS[run.restartTaskStatus ?? ""]}` : "restart playbook running", badge: "bg-blue-lt text-blue" };
|
||||
case "waiting_for_restart":
|
||||
return { label: "waiting for the server to come back from its restart", badge: "bg-blue-lt text-blue" };
|
||||
case "done":
|
||||
return { label: "finished", badge: run.rebootRequired ? "bg-yellow-lt text-yellow" : "bg-green-lt text-green" };
|
||||
case "failed":
|
||||
@@ -99,8 +103,9 @@ export default function UpdateRunsCard({ canEdit, reloadKey, onFinished }: { can
|
||||
<Link to={`/servers/${r.serverId}`}>
|
||||
<strong>{r.serverName ?? `server #${r.serverId}`}</strong>
|
||||
</Link>
|
||||
<span className="text-secondary">{r.template}</span>
|
||||
<span className="text-secondary">{r.kind === "restart" ? "Restart · " : ""}{r.template}{r.restartTemplate && r.kind === "update" ? ` (then ${r.restartTemplate} if a restart is due)` : ""}</span>
|
||||
<span className={`badge ${w.badge}`}>{w.label}</span>
|
||||
{r.status === "done" && r.restarted && <span className="badge bg-green-lt text-green">restarted</span>}
|
||||
{r.status === "done" && r.rebootRequired && <span className="badge bg-yellow-lt text-yellow">restart needed</span>}
|
||||
<span className="text-secondary small ms-auto">
|
||||
started <TimeAgo value={r.startedAt} /> by {r.startedBy ?? "someone"}
|
||||
@@ -117,7 +122,12 @@ export default function UpdateRunsCard({ canEdit, reloadKey, onFinished }: { can
|
||||
<div className="progress-bar progress-bar-indeterminate" />
|
||||
</div>
|
||||
)}
|
||||
{r.taskId !== null && <div className="text-secondary small">Run #{r.taskId} in Semaphore — the playbook's output is there.</div>}
|
||||
{r.taskId !== null && (
|
||||
<div className="text-secondary small">
|
||||
Run #{r.taskId} in Semaphore — the playbook's output is there.
|
||||
{r.restartTaskId !== null && <> The restart is run #{r.restartTaskId}.</>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -88,7 +88,7 @@ export default function Updates({ user }: { user: CurrentUser }) {
|
||||
function WaitingNow({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
|
||||
const canRun = user.role === "admin" || user.role === "operator";
|
||||
// The server being updated now (its drawer is open), and a counter that makes the runs card look again after one was started.
|
||||
const [updating, setUpdating] = useState<UpdatesServer | null>(null);
|
||||
const [updating, setUpdating] = useState<{ server: UpdatesServer; mode: "update" | "restart" } | null>(null);
|
||||
const [runsKey, setRunsKey] = useState(0);
|
||||
const [servers, setServers] = useState<UpdatesServer[] | null>(null);
|
||||
const [agentLatest, setAgentLatest] = useState<AgentLatest | null>(null);
|
||||
@@ -101,7 +101,7 @@ function WaitingNow({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
|
||||
useEffect(() => {
|
||||
if (!wantedUpdate || !servers || !canRun) return;
|
||||
const server = servers.find((s) => String(s.id) === wantedUpdate);
|
||||
if (server) setUpdating(server);
|
||||
if (server) setUpdating({ server, mode: "update" });
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
@@ -188,7 +188,7 @@ function WaitingNow({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
|
||||
</div>
|
||||
{tabs}
|
||||
<p className="text-secondary">
|
||||
What the agents say is waiting to be installed on each server, and the Docker containers that have a newer image. {canRun ? "Update… applies a server's updates through a Semaphore playbook: it silences the server, runs the playbook, waits for the server to report again and tells you what is left." : "Operators can apply a server's updates from here."}
|
||||
What the agents say is waiting to be installed on each server, and the Docker containers that have a newer image. {canRun ? "Update… applies a server's updates through a Semaphore playbook: it silences the server, runs the playbook, waits for the server to report again and tells you what is left — and can restart it afterwards, with a second playbook, if it says a restart is due. Restart… does only the restart." : "Operators can apply a server's updates, and restart a server that needs it, from here."}
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
@@ -266,9 +266,16 @@ function WaitingNow({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
|
||||
</td>
|
||||
{canRun && (
|
||||
<td className="stack-wide">
|
||||
<button type="button" className="btn btn-sm btn-outline-primary" disabled={r.count === null || r.count === 0 || r.server.lastSeenAt === null} title={r.count ? "Apply this server's updates through a Semaphore playbook" : "Nothing is waiting, or the agent hasn't said"} onClick={() => setUpdating(r.server)}>
|
||||
Update…
|
||||
</button>
|
||||
<div className="btn-list flex-nowrap">
|
||||
<button type="button" className="btn btn-sm btn-outline-primary" disabled={r.count === null || r.count === 0 || r.server.lastSeenAt === null} title={r.count ? "Apply this server's updates through a Semaphore playbook" : "Nothing is waiting, or the agent hasn't said"} onClick={() => setUpdating({ server: r.server, mode: "update" })}>
|
||||
Update…
|
||||
</button>
|
||||
{r.restart && (
|
||||
<button type="button" className="btn btn-sm btn-outline-warning" disabled={r.server.lastSeenAt === null} title="This server says a restart is due: restart it through a Semaphore playbook" onClick={() => setUpdating({ server: r.server, mode: "restart" })}>
|
||||
Restart…
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
@@ -332,7 +339,7 @@ function WaitingNow({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{updating && <UpdateRunDrawer server={updating} onClose={() => setUpdating(null)} onStarted={() => setRunsKey((k) => k + 1)} />}
|
||||
{updating && <UpdateRunDrawer server={updating.server} mode={updating.mode} onClose={() => setUpdating(null)} onStarted={() => setRunsKey((k) => k + 1)} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user