craban/cmd/rmsn/rmsn.go

43 lines
808 B
Go
Raw Normal View History

2021-09-11 23:32:07 +01:00
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"git.ctrlz.es/mgdelacroix/rmsn/server"
)
func main() {
configFlag := flag.String("config", "rmsn.yml", "the configuration path")
flag.Parse()
srv, err := server.NewServerWithConfigPath(*configFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "cannot create server: %s", err)
os.Exit(1)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
closed := make(chan bool, 1)
go func() {
fmt.Println("Starting rmsn")
2021-09-12 17:27:49 +01:00
if err := srv.Start(); err != nil {
fmt.Fprintf(os.Stderr, "error running server: %s", err)
os.Exit(1)
}
2021-09-11 23:32:07 +01:00
closed <- true
}()
s := <-c
fmt.Printf("Got signal %s, exiting...\n", s)
2021-09-12 17:28:49 +01:00
if err := srv.Close(); err != nil {
fmt.Fprintf(os.Stderr, "error closing server: %s", err)
os.Exit(1)
}
2021-09-11 23:32:07 +01:00
<-closed
}