multiserver/end.go

42 lines
581 B
Go
Raw Normal View History

2021-01-24 05:00:26 -08:00
package main
import (
"log"
"os"
2021-01-09 03:26:30 -08:00
"time"
2021-04-03 10:25:02 -07:00
"github.com/tncardoso/gocurses"
)
2021-01-17 12:43:23 -08:00
// End disconnects (from) all Peers and stops the process
func End(crash, reconnect bool) {
log.Print("Ending")
2021-01-09 03:26:30 -08:00
2021-04-02 04:39:35 -07:00
var reason uint8 = AccessDeniedShutdown
if crash {
2021-04-02 04:39:35 -07:00
reason = AccessDeniedCrash
}
2021-03-29 09:57:30 -07:00
for _, clt := range Conns() {
2021-04-02 04:39:35 -07:00
clt.CloseWith(reason, "", reconnect)
}
2021-01-09 03:26:30 -08:00
2021-05-02 03:55:42 -07:00
time.Sleep(time.Second)
2021-03-09 09:06:05 -08:00
rpcSrvMu.Lock()
for srv := range rpcSrvs {
srv.Close()
}
rpcSrvMu.Unlock()
2021-03-06 11:33:25 -08:00
Announce(AnnounceDelete)
2021-04-06 06:10:36 -07:00
log.Writer().(*Logger).Close()
2021-04-03 10:25:02 -07:00
gocurses.End()
if crash {
os.Exit(1)
}
2021-04-02 04:39:35 -07:00
os.Exit(0)
}