rebound/cmd/server/main.go

54 lines
1.1 KiB
Go
Raw Permalink Normal View History

2023-09-09 04:00:00 +02:00
package main
import (
"log"
"os"
"os/signal"
"forge.cadoles.com/wpetit/rebound"
"forge.cadoles.com/wpetit/rebound/http"
"forge.cadoles.com/wpetit/rebound/ssh"
2023-09-09 04:00:00 +02:00
"github.com/pkg/errors"
)
2023-09-24 20:21:44 +02:00
var Version string = "unknown"
2023-09-09 04:00:00 +02:00
func main() {
opts := rebound.DefaultOptions()
if err := opts.ParseEnv(); err != nil {
2023-09-09 04:00:00 +02:00
log.Fatalf("[ERROR] %+v", errors.WithStack(err))
}
2023-09-24 20:21:44 +02:00
opts.HTTP.TemplateData.Version = Version
2023-09-09 04:00:00 +02:00
server := rebound.NewServer(
rebound.WithAddress(opts.Address),
2023-09-24 20:21:44 +02:00
rebound.WithStatsFile(opts.StatsFile),
rebound.WithStatsFileSaveInterval(opts.StatsFileSaveInterval),
rebound.WithSSHOption(
ssh.WithSockDir(opts.SSH.SockDir),
ssh.WithPublicHost(opts.SSH.PublicHost),
ssh.WithPublicPort(opts.SSH.PublicPort),
ssh.WithHostKey(opts.SSH.HostKey),
),
rebound.WitHTTPOption(
http.WithCustomDir(opts.HTTP.CustomDir),
http.WithTemplateData(opts.HTTP.TemplateData),
),
2023-09-09 04:00:00 +02:00
)
if err := server.Start(); err != nil {
log.Fatalf("[FATAL] %+v", errors.WithStack(err))
}
2023-09-09 04:00:00 +02:00
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
if err := server.Stop(); err != nil {
log.Fatalf("[FATAL] %+v", errors.WithStack(err))
}
}