@@ -38,13 +38,18 @@ func (s *serveCmd) Run(cli *cli) error {
3838 slog .SetDefault (slog .New (handler ))
3939
4040 for {
41- if err := serveUntilReload (context .Background (), cli ); err != nil && ! errors .Is (err , context .Canceled ) {
41+ config , err := sshgate .ReadConfig (cli .Config )
42+ if err != nil {
43+ return err
44+ }
45+
46+ if err := serveUntilReload (context .Background (), cli , config ); err != nil && ! errors .Is (err , context .Canceled ) {
4247 return err
4348 }
4449 }
4550}
4651
47- func serveUntilReload (ctx context.Context , cli * cli ) error {
52+ func serveUntilReload (ctx context.Context , cli * cli , config * sshgate. Config ) error {
4853 watcher , err := fsnotify .NewWatcher ()
4954 if err != nil {
5055 return err
@@ -55,24 +60,32 @@ func serveUntilReload(ctx context.Context, cli *cli) error {
5560 return err
5661 }
5762
63+ for _ , hostKeyPath := range []string {
64+ config .HostKeyPaths .ECDSA ,
65+ config .HostKeyPaths .ED25519 ,
66+ config .HostKeyPaths .RSA ,
67+ } {
68+ if hostKeyPath != "" {
69+ if err := watcher .Add (hostKeyPath ); err != nil {
70+ return err
71+ }
72+ }
73+ }
74+
5875 ctx , cancel := fsnotifyContext (ctx , watcher )
5976 defer cancel ()
6077
61- return serve (ctx , cli )
78+ return serve (ctx , cli , config )
6279}
6380
64- func serve (ctx context.Context , c * cli ) error {
81+ func serve (ctx context.Context , c * cli , config * sshgate. Config ) error {
6582 var opts []sshgate.Option
6683 if c .Ruleless {
6784 opts = append (opts , sshgate .WithRulelessMode ())
6885 }
6986
70- config , err := sshgate .ReadConfig (c .Config )
71- if err != nil {
72- return err
73- }
74-
7587 server := sshgate .New (config , c .ListenAddr , opts ... )
88+
7689 return server .ListenAndServe (ctx )
7790}
7891
0 commit comments