add reloading and stopping from tsctl

This commit is contained in:
2025-11-30 11:26:22 +02:00
parent c51dfce9ec
commit ea7358a35f
6 changed files with 205 additions and 68 deletions

View File

@@ -94,17 +94,17 @@ type LiveServer struct {
handler http.Handler
active atomic.Value // *instance
mu sync.Mutex
mu sync.Mutex
statusMu sync.Mutex
status Status
status Status
initDone bool
}
type instance struct {
srv *http.Server
ln net.Listener
ln net.Listener
addr string
}
@@ -198,10 +198,10 @@ func (ls *LiveServer) Start(addr string) error {
return err
}
srv := &http.Server{Handler: ls.handler}
ls.active.Store(&instance{
srv: srv,
ln: ln,
srv: srv,
ln: ln,
addr: addr,
})
@@ -249,7 +249,6 @@ func (ls *LiveServer) Stop() error {
return ls.stop(inst)
}
func (ls *LiveServer) Reload(newAddr string) error {
ls.mu.Lock()
oldInstAny := ls.active.Load()
@@ -258,7 +257,7 @@ func (ls *LiveServer) Reload(newAddr string) error {
oldAddr = oldInstAny.(*instance).addr
}
ls.mu.Unlock()
if oldAddr == newAddr {
return nil
}
@@ -447,7 +446,6 @@ func (ls *LiveServer) Reload(newAddr string) error {
// // }
// ls.setStatus(Status{ID: StatusStarting})
// err := ls.Start()
// if err != nil {