automatic-update when running as mac service

Massimo Melina committed Apr 8, 2026 at 10:00 UTC 2e543cf0ca6342e5b18fde5afc2f9925715131de
2 files changed +10 -9
src/update.ts
+9 -8
@@ -10,7 +10,7 @@ import { pluginsWatcher } from './plugins'
10 import { chmod, rename, writeFile, rm } from 'fs/promises'
11 import open from 'open'
12 import { configReady, currentVersion, defineConfig, versionToScalar } from './config'
13 -import { cmdEscape, RUNNING_AS_SERVICE } from './util-os'
13 +import { cmdEscape, runningAsWindowsService } from './util-os'
14 import { onProcessExit } from './first'
15 import { storedMap } from './persistence'
16 import _ from 'lodash'
@@ -109,7 +109,7 @@ export function previousAvailable() {
109 }
110
111 export async function updateSupported() {
112 - return !process.env.DISABLE_UPDATE && (argv.forceupdate || IS_BINARY && !await RUNNING_AS_SERVICE)
112 + return !process.env.DISABLE_UPDATE && (argv.forceupdate || IS_BINARY && !await runningAsWindowsService)
113 }
114
115 export async function update(tagOrUrl: string='') {
@@ -181,6 +181,11 @@ export async function update(tagOrUrl: string='') {
181 try { unlinkSync(oldBin) }
182 catch {}
183 renameSync(bin, oldBin)
184 + if (!IS_WINDOWS && !process.stdin.isTTY) { // non-interactive (service): rename in place and let the supervisor restart
185 + renameSync(newBin, join(binPath, binFile))
186 + console.log("Updated binary in place, exiting for process supervisor to restart")
187 + return
188 + }
189 console.log("Launching new version in background", newBinFile)
190 spawnSync(cmdEscape(newBin), ['--updating', binFile, '--cwd .'], { shell: true, stdio: [0,1,2] }) // sync necessary to work on Mac by double-click
191 })
@@ -212,11 +217,7 @@ if (argv.updating) { // we were launched with a temporary name, restore original
217 console.log('Open-ing')
218 void open(dest)
219 }
215 - else { // linux and other *nix
216 - if (process.stdin.isTTY && process.stdout.isTTY) // in interactive terminals, block this bridge process on the restarted hfs so the terminal session stays attached
217 - spawnSync(dest, ['--updated', '--cwd', process.cwd()], { stdio: [0, 1, 2] })
218 - else
219 - spawn(dest, ['--updated', '--cwd', process.cwd()], { detached: true, stdio: 'ignore' }).unref()
220 - }
220 + else // linux and *nix on terminal: in interactive terminals, block this bridge process on the restarted hfs so the terminal session stays attached
221 + spawnSync(dest, ['--updated', '--cwd', process.cwd()], { stdio: [0, 1, 2] })
222 process.exit()
223 }
src/util-os.ts
+1 -1
@@ -79,7 +79,7 @@ async function getWindowsServicePids() {
79 return Object.fromEntries(parsed.slice(2).filter(x => x[2] !== no).map(x => [x[1], x[2]]))
80 }
81
82 -export const RUNNING_AS_SERVICE = IS_WINDOWS && getWindowsServicePids().then(x => {
82 +export const runningAsWindowsService = IS_WINDOWS && getWindowsServicePids().then(x => {
83 const ret = x[pid] || x[ppid]
84 if (ret)
85 console.log("running as service", ret)