ollama

Форк
0
/
updater_windows.go 
80 строк · 2.5 Кб
1
package lifecycle
2

3
import (
4
	"context"
5
	"fmt"
6
	"log/slog"
7
	"os"
8
	"os/exec"
9
	"path/filepath"
10
)
11

12
func DoUpgrade(cancel context.CancelFunc, done chan int) error {
13
	files, err := filepath.Glob(filepath.Join(UpdateStageDir, "*", "*.exe")) // TODO generalize for multiplatform
14
	if err != nil {
15
		return fmt.Errorf("failed to lookup downloads: %s", err)
16
	}
17
	if len(files) == 0 {
18
		return fmt.Errorf("no update downloads found")
19
	} else if len(files) > 1 {
20
		// Shouldn't happen
21
		slog.Warn(fmt.Sprintf("multiple downloads found, using first one %v", files))
22
	}
23
	installerExe := files[0]
24

25
	slog.Info("starting upgrade with " + installerExe)
26
	slog.Info("upgrade log file " + UpgradeLogFile)
27

28
	// When running in debug mode, we'll be "verbose" and let the installer pop up and prompt
29
	installArgs := []string{
30
		"/CLOSEAPPLICATIONS",                    // Quit the tray app if it's still running
31
		"/LOG=" + filepath.Base(UpgradeLogFile), // Only relative seems reliable, so set pwd
32
		"/FORCECLOSEAPPLICATIONS",               // Force close the tray app - might be needed
33
	}
34
	// When we're not in debug mode, make the upgrade as quiet as possible (no GUI, no prompts)
35
	// TODO - temporarily disable since we're pinning in debug mode for the preview
36
	// if debug := os.Getenv("OLLAMA_DEBUG"); debug == "" {
37
	installArgs = append(installArgs,
38
		"/SP", // Skip the "This will install... Do you wish to continue" prompt
39
		"/SUPPRESSMSGBOXES",
40
		"/SILENT",
41
		"/VERYSILENT",
42
	)
43
	// }
44

45
	// Safeguard in case we have requests in flight that need to drain...
46
	slog.Info("Waiting for server to shutdown")
47
	cancel()
48
	if done != nil {
49
		<-done
50
	} else {
51
		// Shouldn't happen
52
		slog.Warn("done chan was nil, not actually waiting")
53
	}
54

55
	slog.Debug(fmt.Sprintf("starting installer: %s %v", installerExe, installArgs))
56
	os.Chdir(filepath.Dir(UpgradeLogFile)) //nolint:errcheck
57
	cmd := exec.Command(installerExe, installArgs...)
58

59
	if err := cmd.Start(); err != nil {
60
		return fmt.Errorf("unable to start ollama app %w", err)
61
	}
62

63
	if cmd.Process != nil {
64
		err = cmd.Process.Release()
65
		if err != nil {
66
			slog.Error(fmt.Sprintf("failed to release server process: %s", err))
67
		}
68
	} else {
69
		// TODO - some details about why it didn't start, or is this a pedantic error case?
70
		return fmt.Errorf("installer process did not start")
71
	}
72

73
	// TODO should we linger for a moment and check to make sure it's actually running by checking the pid?
74

75
	slog.Info("Installer started in background, exiting")
76

77
	os.Exit(0)
78
	// Not reached
79
	return nil
80
}
81

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.