Delegate update to install/install.sh

This commit is contained in:
Chris Wanstrath 2026-03-05 07:58:27 -08:00
parent e119aed205
commit 61c0c90695

View File

@ -298,27 +298,15 @@ router.get('/update', async c => {
}
})
// Apply update and restart
router.post('/update', async c => {
// Apply update and restart (delegates to install/install.sh)
// The script ends with `systemctl restart toes`, killing this process,
// so we respond immediately and run it detached.
router.post('/update', c => {
if (isUpdating) return c.json({ ok: false, error: 'update already in progress' }, 409)
isUpdating = true
try {
const pull = await Bun.spawn(['git', 'pull', 'origin', 'main'], { cwd: projectRoot }).exited
if (pull !== 0) return c.json({ ok: false, error: 'git pull failed' }, 500)
const install = await Bun.spawn(['bun', 'install'], { cwd: projectRoot }).exited
if (install !== 0) return c.json({ ok: false, error: 'bun install failed' }, 500)
const build = await Bun.spawn(['bun', 'run', 'build'], { cwd: projectRoot }).exited
if (build !== 0) return c.json({ ok: false, error: 'build failed' }, 500)
setTimeout(() => process.exit(0), 100)
const script = join(projectRoot, 'install/install.sh')
Bun.spawn(['bash', script], { cwd: projectRoot, stdout: 'ignore', stderr: 'ignore' })
return c.json({ ok: true })
} catch {
return c.json({ ok: false, error: 'update failed' }, 500)
} finally {
isUpdating = false
}
})
export default router