mirror of
https://github.com/mudler/LocalAI.git
synced 2026-01-06 02:29:54 -06:00
chore: update cogito and simplify MCP logics (#6413)
* chore: update cogito and simplify MCP logics Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Refine signal handling Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
committed by
GitHub
parent
459b6ab86d
commit
27c4161401
@@ -4,14 +4,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/hpcloud/tail"
|
||||
"github.com/mudler/LocalAI/pkg/signals"
|
||||
process "github.com/mudler/go-processmanager"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
@@ -130,16 +129,13 @@ func (ml *ModelLoader) startProcess(grpcProcess, id string, serverAddress string
|
||||
}
|
||||
|
||||
log.Debug().Msgf("GRPC Service state dir: %s", grpcControlProcess.StateDir())
|
||||
// clean up process
|
||||
go func() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
<-c
|
||||
|
||||
signals.RegisterGracefulTerminationHandler(func() {
|
||||
err := grpcControlProcess.Stop()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error while shutting down grpc process")
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
go func() {
|
||||
t, err := tail.TailFile(grpcControlProcess.StderrPath(), tail.Config{Follow: true})
|
||||
|
||||
40
pkg/signals/handler.go
Normal file
40
pkg/signals/handler.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package signals
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
signalHandlers []func()
|
||||
signalHandlersMutex sync.Mutex
|
||||
signalHandlersOnce sync.Once
|
||||
)
|
||||
|
||||
func RegisterGracefulTerminationHandler(fn func()) {
|
||||
signalHandlersMutex.Lock()
|
||||
defer signalHandlersMutex.Unlock()
|
||||
signalHandlers = append(signalHandlers, fn)
|
||||
}
|
||||
|
||||
func init() {
|
||||
signalHandlersOnce.Do(func() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||
go signalHandler(c)
|
||||
})
|
||||
}
|
||||
|
||||
func signalHandler(c chan os.Signal) {
|
||||
<-c
|
||||
|
||||
signalHandlersMutex.Lock()
|
||||
defer signalHandlersMutex.Unlock()
|
||||
for _, fn := range signalHandlers {
|
||||
fn()
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
Reference in New Issue
Block a user