File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ package main
33import (
44 "log"
55 "os"
6+ "os/signal"
67 "strings"
8+ "syscall"
79
810 "github.com/hashicorp/go-hclog"
911 "github.com/netauth/netauth/pkg/netauth"
@@ -60,8 +62,21 @@ func main() {
6062 os .Exit (1 )
6163 }
6264
63- if err := srvr .Serve (); err != nil {
64- appLogger .Error ("Error serving" , "error" , err )
65- os .Exit (1 )
65+ go func () {
66+ if err := srvr .Serve (); err != nil {
67+ appLogger .Error ("Error serving" , "error" , err )
68+ os .Exit (1 )
69+ }
70+ }()
71+
72+ // Sit here and wait for a signal to shutdown.
73+ ch := make (chan os.Signal , 5 )
74+ signal .Notify (ch , syscall .SIGINT , syscall .SIGTERM )
75+ <- ch
76+ appLogger .Info ("Shutting down..." )
77+ if err := srvr .Shutdown (); err != nil {
78+ appLogger .Error ("Error during shutdown" , "error" , err )
79+ os .Exit (2 )
6680 }
81+ appLogger .Info ("Goodbye!" )
6782}
Original file line number Diff line number Diff line change 11package radius
22
33import (
4+ "context"
45 "fmt"
56
67 "github.com/hashicorp/go-hclog"
@@ -43,7 +44,13 @@ func (s *Server) Serve() error {
4344 Handler : radius .HandlerFunc (s .handler ),
4445 SecretSource : radius .StaticSecretSource ([]byte ("secret" )),
4546 }
47+ s .radsrv = server
4648
4749 s .log .Info ("Serving Radius on :1812" )
4850 return server .ListenAndServe ()
4951}
52+
53+ // Shutdown requests the underlying packetserver to shutdown smoothly.
54+ func (s * Server ) Shutdown () error {
55+ return s .radsrv .Shutdown (context .Background ())
56+ }
Original file line number Diff line number Diff line change @@ -4,12 +4,15 @@ import (
44 "context"
55
66 "github.com/hashicorp/go-hclog"
7+ "layeh.com/radius"
78)
89
910// Server owns the radius server itself and its handlers.
1011type Server struct {
1112 log hclog.Logger
1213 n netauth
14+
15+ radsrv radius.PacketServer
1316}
1417
1518// Option enables passing of various options to the server on startup.
You can’t perform that action at this time.
0 commit comments