Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
cmd: route root command server start through checkServerHeartbeat (#17245)
Parth Sareen6f3b997decc0
diff --git a/cmd/background_unix.go b/cmd/background_unix.godeleted file mode 100644index a4eea48c5..000000000--- a/cmd/background_unix.go+++ /dev/null@@ -1,13 +0,0 @@-//go:build !windows--package cmd--import "syscall"--// backgroundServerSysProcAttr returns SysProcAttr for running the server in the background on Unix.-// Setpgid prevents the server from being killed when the parent process exits.-func backgroundServerSysProcAttr() *syscall.SysProcAttr {- return &syscall.SysProcAttr{- Setpgid: true,- }-}diff --git a/cmd/background_windows.go b/cmd/background_windows.godeleted file mode 100644index fa43b7400..000000000--- a/cmd/background_windows.go+++ /dev/null@@ -1,12 +0,0 @@-package cmd--import "syscall"--// backgroundServerSysProcAttr returns SysProcAttr for running the server in the background on Windows.-// CREATE_NO_WINDOW (0x08000000) prevents a console window from appearing.-func backgroundServerSysProcAttr() *syscall.SysProcAttr {- return &syscall.SysProcAttr{- CreationFlags: 0x08000000,- HideWindow: true,- }-}diff --git a/cmd/cmd.go b/cmd/cmd.goindex d30eb1a5b..4a91eb450 100644--- a/cmd/cmd.go+++ b/cmd/cmd.go@@ -16,7 +16,6 @@ import ("net""net/http""os"- "os/exec""os/signal""path""path/filepath"@@ -2099,40 +2098,6 @@ Environment Variables:cmd.SetUsageTemplate(cmd.UsageTemplate() + envUsage)}-// ensureServerRunning checks if the ollama server is running and starts it in the background if not.-func ensureServerRunning(ctx context.Context) error {- client, err := api.ClientFromEnvironment()- if err != nil {- return err- }-- // Check if server is already running- if err := client.Heartbeat(ctx); err == nil {- return nil // server is already running- }-- // Server not running, start it in the background- exe, err := os.Executable()- if err != nil {- return fmt.Errorf("could not find executable: %w", err)- }-- serverCmd := exec.CommandContext(ctx, exe, "serve")- serverCmd.Env = os.Environ()- serverCmd.SysProcAttr = backgroundServerSysProcAttr()- if err := serverCmd.Start(); err != nil {- return fmt.Errorf("failed to start server: %w", err)- }-- // Wait for the server to be ready- for {- time.Sleep(500 * time.Millisecond)- if err := client.Heartbeat(ctx); err == nil {- return nil // server has started- }- }-}-func launchInteractiveModel(cmd *cobra.Command, modelName string) error {client, err := api.ClientFromEnvironment()if err != nil {@@ -2166,9 +2131,9 @@ func launchInteractiveModel(cmd *cobra.Command, modelName string) error {// runInteractiveTUI runs the main interactive TUI menu.func runInteractiveTUI(cmd *cobra.Command) {- // Ensure the server is running before showing the TUI- if err := ensureServerRunning(cmd.Context()); err != nil {- fmt.Fprintf(os.Stderr, "Error starting server: %v\n", err)+ // Ensure the server is running via the shared checkServerHeartbeat path.+ if err := checkServerHeartbeat(cmd, nil); err != nil {+ fmt.Fprintf(os.Stderr, "Error: %v\n", err)return}