8e49d2b300
Adds POST /api/updates/apply (pull, rebuild, restart) plus an "Update now" button and hourly auto-check in the UI, for checkouts that are safely fast-forwardable. Reintroduces self-restart (previously removed in edc25ca for cross-environment reliability concerns) per explicit user request.
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
/**
|
|
* @file Triggers the one self-restart path this dashboard has: after
|
|
* `POST /api/updates/apply` fast-forwards and rebuilds the checkout, the
|
|
* running process needs to relaunch itself on the new code. Reuses the
|
|
* existing SIGTERM graceful-shutdown path in `server/index.js` (closes
|
|
* websockets, drains the HTTP server, closes the DB) instead of duplicating
|
|
* it, and hands the "wait for the old PID to actually die, then spawn the
|
|
* replacement" job to a detached helper script — the dying process can't do
|
|
* that itself without racing its own replacement for the port.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const path = require("path");
|
|
const { spawn } = require("child_process");
|
|
|
|
/**
|
|
* @param {string} [root] repo root the helper should run from.
|
|
*/
|
|
function scheduleRestart(root = path.join(__dirname, "..", "..")) {
|
|
const helperPath = path.join(root, "scripts", "restart-helper.js");
|
|
const entry = process.argv[1] || path.join(root, "server", "index.js");
|
|
const helper = spawn(process.execPath, [helperPath, String(process.pid), entry], {
|
|
cwd: root,
|
|
detached: true,
|
|
stdio: "ignore",
|
|
env: process.env,
|
|
});
|
|
helper.unref();
|
|
process.kill(process.pid, "SIGTERM");
|
|
}
|
|
|
|
module.exports = { scheduleRestart };
|