From 407a5cabf4c4a8ae1fe401d0c59785091117f998 Mon Sep 17 00:00:00 2001 From: Eva Ho Date: Mon, 10 Jul 2023 17:13:16 -0400 Subject: [PATCH] when app is running, server restarts when it exits or disconnects --- app/src/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/index.ts b/app/src/index.ts index b0428f2a..ed782321 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -40,8 +40,8 @@ const ollama = path.join(process.resourcesPath, 'ollama') function server() { const binary = app.isPackaged - ? path.join(process.resourcesPath, 'ollama') - : path.resolve(process.cwd(), '..', 'ollama') + ? path.join(process.resourcesPath, 'ollama') + : path.resolve(process.cwd(), '..', 'ollama') console.log(`Starting server`) const proc = spawn(binary, ['serve']) @@ -52,11 +52,22 @@ function server() { console.error(`server: ${data}`) }) + proc.on('exit', () => { + console.log('Restarting...'); + server(); + }) + + proc.on('disconnect', () => { + console.log('Restarting...'); + server(); + }) + process.on('exit', () => { proc.kill() }) } + function installCLI() { const symlinkPath = '/usr/local/bin/ollama'