@@ -376,6 +376,12 @@ func moduleStop(c *container.C) {
376376func moduleMain (configPath string ) error {
377377 log .DefaultLogger .Msg ("loading configuration..." )
378378
379+ // Make path absolute to make sure we can still read it if current directory changes (in moduleConfigure).
380+ configPath , err := filepath .Abs (configPath )
381+ if err != nil {
382+ return err
383+ }
384+
379385 c , err := moduleConfigure (configPath )
380386 if err != nil {
381387 return err
@@ -389,7 +395,12 @@ func moduleMain(configPath string) error {
389395 c .DefaultLogger .Msg ("server started" , "version" , Version )
390396
391397 systemdStatus (SDReady , "Listening for incoming connections..." )
392- handleSignals ()
398+ for handleSignals () {
399+ systemdStatus (SDReloading , "Reloading state..." )
400+ hooks .RunHooks (hooks .EventReload )
401+
402+ c = moduleReload (c , configPath )
403+ }
393404
394405 c .DefaultLogger .Msg ("server stopping..." )
395406 systemdStatus (SDStopping , "Waiting for running transactions to complete..." )
@@ -399,6 +410,33 @@ func moduleMain(configPath string) error {
399410 return nil
400411}
401412
413+ func moduleReload (oldContainer * container.C , configPath string ) * container.C {
414+ oldContainer .DefaultLogger .Msg ("reloading server..." )
415+
416+ oldContainer .DefaultLogger .Msg ("loading new configuration..." )
417+ newContainer , err := moduleConfigure (configPath )
418+ if err != nil {
419+ oldContainer .DefaultLogger .Error ("failed to load new configuration" , err )
420+ return oldContainer
421+ }
422+
423+ oldContainer .DefaultLogger .Msg ("configuration loaded" )
424+
425+ oldContainer .DefaultLogger .Msg ("starting new server" )
426+ if err := moduleStart (newContainer ); err != nil {
427+ oldContainer .DefaultLogger .Error ("failed to start new server" , err )
428+ container .Global = oldContainer
429+ return oldContainer
430+ }
431+
432+ newContainer .DefaultLogger .Msg ("server started" , "version" , Version )
433+ oldContainer .DefaultLogger .Msg ("stopping server" )
434+ moduleStop (oldContainer )
435+ oldContainer .DefaultLogger .Msg ("server stopped" )
436+
437+ return newContainer
438+ }
439+
402440func RegisterModules (c * container.C , globals map [string ]interface {}, nodes []config.Node ) (err error ) {
403441 var endpoints []struct {
404442 Endpoint module.LifetimeModule
0 commit comments