diff --git a/src/server/api/system.ts b/src/server/api/system.ts index b6da71d..0d50119 100644 --- a/src/server/api/system.ts +++ b/src/server/api/system.ts @@ -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) - return c.json({ ok: true }) - } catch { - return c.json({ ok: false, error: 'update failed' }, 500) - } finally { - isUpdating = false - } + const script = join(projectRoot, 'install/install.sh') + Bun.spawn(['bash', script], { cwd: projectRoot, stdout: 'ignore', stderr: 'ignore' }) + return c.json({ ok: true }) }) export default router