2024-05-17 20:24:06 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2024-05-27 09:42:27 +02:00
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2024-05-23 13:24:02 +02:00
|
|
|
|
2024-05-17 20:24:06 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2024-06-19 17:40:16 +02:00
|
|
|
"github.com/spf13/cobra"
|
2024-05-17 20:24:06 +02:00
|
|
|
|
|
|
|
"github.com/netbirdio/netbird/relay/server"
|
2024-05-27 09:42:27 +02:00
|
|
|
"github.com/netbirdio/netbird/util"
|
2024-05-17 20:24:06 +02:00
|
|
|
)
|
|
|
|
|
2024-06-19 17:40:16 +02:00
|
|
|
var (
|
|
|
|
listenAddress string
|
|
|
|
|
|
|
|
rootCmd = &cobra.Command{
|
|
|
|
Use: "relay",
|
|
|
|
Short: "Relay service",
|
|
|
|
Long: "Relay service for Netbird agents",
|
|
|
|
Run: execute,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-05-17 20:24:06 +02:00
|
|
|
func init() {
|
2024-06-19 17:40:16 +02:00
|
|
|
_ = util.InitLog("trace", "console")
|
|
|
|
rootCmd.PersistentFlags().StringVarP(&listenAddress, "listen-address", "l", ":1235", "listen address")
|
|
|
|
|
2024-05-17 20:24:06 +02:00
|
|
|
}
|
|
|
|
|
2024-05-27 09:42:27 +02:00
|
|
|
func waitForExitSignal() {
|
|
|
|
osSigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(osSigs, syscall.SIGINT, syscall.SIGTERM)
|
2024-06-25 15:13:08 +02:00
|
|
|
<-osSigs
|
2024-05-27 09:42:27 +02:00
|
|
|
}
|
2024-05-17 20:24:06 +02:00
|
|
|
|
2024-06-19 17:40:16 +02:00
|
|
|
func execute(cmd *cobra.Command, args []string) {
|
2024-05-17 20:24:06 +02:00
|
|
|
srv := server.NewServer()
|
2024-06-19 17:40:16 +02:00
|
|
|
err := srv.Listen(listenAddress)
|
2024-05-17 20:24:06 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed to bind server: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2024-05-26 22:14:33 +02:00
|
|
|
|
2024-05-27 09:42:27 +02:00
|
|
|
waitForExitSignal()
|
|
|
|
|
|
|
|
err = srv.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed to close server: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2024-05-17 20:24:06 +02:00
|
|
|
}
|
2024-06-19 17:40:16 +02:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := rootCmd.Execute()
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|