mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 09:04:27 +00:00
Add MaxRunningInstances to InstancesConfig and implement IsRunning method
This commit is contained in:
@@ -55,6 +55,9 @@ type InstancesConfig struct {
|
|||||||
// Maximum number of instances that can be created
|
// Maximum number of instances that can be created
|
||||||
MaxInstances int `yaml:"max_instances"`
|
MaxInstances int `yaml:"max_instances"`
|
||||||
|
|
||||||
|
// Maximum number of instances that can be running at the same time
|
||||||
|
MaxRunningInstances int `yaml:"max_running_instances,omitempty"`
|
||||||
|
|
||||||
// Path to llama-server executable
|
// Path to llama-server executable
|
||||||
LlamaExecutable string `yaml:"llama_executable"`
|
LlamaExecutable string `yaml:"llama_executable"`
|
||||||
|
|
||||||
@@ -113,6 +116,7 @@ func LoadConfig(configPath string) (AppConfig, error) {
|
|||||||
LogsDir: filepath.Join(getDefaultDataDirectory(), "logs"),
|
LogsDir: filepath.Join(getDefaultDataDirectory(), "logs"),
|
||||||
AutoCreateDirs: true,
|
AutoCreateDirs: true,
|
||||||
MaxInstances: -1, // -1 means unlimited
|
MaxInstances: -1, // -1 means unlimited
|
||||||
|
MaxRunningInstances: -1, // -1 means unlimited
|
||||||
LlamaExecutable: "llama-server",
|
LlamaExecutable: "llama-server",
|
||||||
DefaultAutoRestart: true,
|
DefaultAutoRestart: true,
|
||||||
DefaultMaxRestarts: 3,
|
DefaultMaxRestarts: 3,
|
||||||
@@ -211,6 +215,11 @@ func loadEnvVars(cfg *AppConfig) {
|
|||||||
cfg.Instances.MaxInstances = m
|
cfg.Instances.MaxInstances = m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if maxRunning := os.Getenv("LLAMACTL_MAX_RUNNING_INSTANCES"); maxRunning != "" {
|
||||||
|
if m, err := strconv.Atoi(maxRunning); err == nil {
|
||||||
|
cfg.Instances.MaxRunningInstances = m
|
||||||
|
}
|
||||||
|
}
|
||||||
if llamaExec := os.Getenv("LLAMACTL_LLAMA_EXECUTABLE"); llamaExec != "" {
|
if llamaExec := os.Getenv("LLAMACTL_LLAMA_EXECUTABLE"); llamaExec != "" {
|
||||||
cfg.Instances.LlamaExecutable = llamaExec
|
cfg.Instances.LlamaExecutable = llamaExec
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (i *Process) IsRunning() bool {
|
||||||
|
i.mu.RLock()
|
||||||
|
defer i.mu.RUnlock()
|
||||||
|
return i.Running
|
||||||
|
}
|
||||||
|
|
||||||
// Start starts the llama server instance and returns an error if it fails.
|
// Start starts the llama server instance and returns an error if it fails.
|
||||||
func (i *Process) Start() error {
|
func (i *Process) Start() error {
|
||||||
i.mu.Lock()
|
i.mu.Lock()
|
||||||
|
|||||||
@@ -28,10 +28,11 @@ type InstanceManager interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type instanceManager struct {
|
type instanceManager struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
instances map[string]*instance.Process
|
instances map[string]*instance.Process
|
||||||
ports map[int]bool
|
runningInstances map[*instance.Process]struct{}
|
||||||
instancesConfig config.InstancesConfig
|
ports map[int]bool
|
||||||
|
instancesConfig config.InstancesConfig
|
||||||
|
|
||||||
// Timeout checker
|
// Timeout checker
|
||||||
timeoutChecker *time.Ticker
|
timeoutChecker *time.Ticker
|
||||||
@@ -46,9 +47,10 @@ func NewInstanceManager(instancesConfig config.InstancesConfig) InstanceManager
|
|||||||
instancesConfig.TimeoutCheckInterval = 5 // Default to 5 minutes if not set
|
instancesConfig.TimeoutCheckInterval = 5 // Default to 5 minutes if not set
|
||||||
}
|
}
|
||||||
im := &instanceManager{
|
im := &instanceManager{
|
||||||
instances: make(map[string]*instance.Process),
|
instances: make(map[string]*instance.Process),
|
||||||
ports: make(map[int]bool),
|
runningInstances: make(map[*instance.Process]struct{}),
|
||||||
instancesConfig: instancesConfig,
|
ports: make(map[int]bool),
|
||||||
|
instancesConfig: instancesConfig,
|
||||||
|
|
||||||
timeoutChecker: time.NewTicker(time.Duration(instancesConfig.TimeoutCheckInterval) * time.Minute),
|
timeoutChecker: time.NewTicker(time.Duration(instancesConfig.TimeoutCheckInterval) * time.Minute),
|
||||||
shutdownChan: make(chan struct{}),
|
shutdownChan: make(chan struct{}),
|
||||||
|
|||||||
Reference in New Issue
Block a user