@@ -129,20 +129,12 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
129
129
130
130
api .ServerShutdown = serverShutdown
131
131
132
- c := configureNativeClient ()
133
- client := & c
132
+ client := configureNativeClient ()
134
133
135
134
// Handle reload signals
136
135
sigs := make (chan os.Signal , 1 )
137
- signal .Notify (sigs , syscall .SIGUSR1 )
138
-
139
- go func () {
140
- sig := <- sigs
141
- if sig == syscall .SIGUSR1 {
142
- c = configureNativeClient ()
143
- log .Info ("Reloaded Data Plane API" )
144
- }
145
- }()
136
+ signal .Notify (sigs , syscall .SIGUSR1 , syscall .SIGUSR2 )
137
+ go handleSignals (sigs , client )
146
138
147
139
// Initialize reload agent
148
140
ra := & haproxy.ReloadAgent {}
@@ -476,7 +468,7 @@ func serverShutdown() {
476
468
}
477
469
}
478
470
479
- func configureNativeClient () client_native.HAProxyClient {
471
+ func configureNativeClient () * client_native.HAProxyClient {
480
472
// Override options with env variables
481
473
if os .Getenv ("HAPROXY_MWORKER" ) == "1" {
482
474
masterRuntime := os .Getenv ("HAPROXY_MASTER_CLI" )
@@ -490,16 +482,9 @@ func configureNativeClient() client_native.HAProxyClient {
490
482
haproxyOptions .ConfigFile = cfg [0 ]
491
483
}
492
484
// Initialize HAProxy native client
493
- confClient := & configuration.Client {}
494
- confParams := configuration.ClientParams {
495
- ConfigurationFile : haproxyOptions .ConfigFile ,
496
- Haproxy : haproxyOptions .HAProxy ,
497
- UseValidation : false ,
498
- TransactionDir : haproxyOptions .TransactionDir ,
499
- }
500
- err := confClient .Init (confParams )
485
+ confClient , err := configureConfigurationClient ()
501
486
if err != nil {
502
- log .Fatalf ("Error setting up configuration client: %s" , err .Error ())
487
+ log .Fatalf (err .Error ())
503
488
}
504
489
505
490
runtimeClient := configureRuntimeClient (confClient )
@@ -508,7 +493,23 @@ func configureNativeClient() client_native.HAProxyClient {
508
493
log .Fatalf ("Error setting up native client: %s" , err .Error ())
509
494
}
510
495
511
- return * client
496
+ return client
497
+ }
498
+
499
+ func configureConfigurationClient () (* configuration.Client , error ) {
500
+ confClient := & configuration.Client {}
501
+ confParams := configuration.ClientParams {
502
+ ConfigurationFile : haproxyOptions .ConfigFile ,
503
+ Haproxy : haproxyOptions .HAProxy ,
504
+ UseValidation : false ,
505
+ PersistentTransactions : false ,
506
+ TransactionDir : haproxyOptions .TransactionDir ,
507
+ }
508
+ err := confClient .Init (confParams )
509
+ if err != nil {
510
+ return nil , fmt .Errorf ("Error setting up configuration client: %s" , err .Error ())
511
+ }
512
+ return confClient , nil
512
513
}
513
514
514
515
func configureRuntimeClient (confClient * configuration.Client ) * runtime_api.Client {
@@ -551,3 +552,22 @@ func configureRuntimeClient(confClient *configuration.Client) *runtime_api.Clien
551
552
}
552
553
return runtimeClient
553
554
}
555
+
556
+ func handleSignals (sigs chan os.Signal , client * client_native.HAProxyClient ) {
557
+ for {
558
+ select {
559
+ case sig := <- sigs :
560
+ if sig == syscall .SIGUSR1 {
561
+ client .Runtime = configureRuntimeClient (client .Configuration )
562
+ log .Info ("Reloaded Data Plane API" )
563
+ } else if sig == syscall .SIGUSR2 {
564
+ confClient , err := configureConfigurationClient ()
565
+ if err != nil {
566
+ log .Fatalf (err .Error ())
567
+ }
568
+ log .Info ("Rereading Configuration Files" )
569
+ client .Configuration = confClient
570
+ }
571
+ }
572
+ }
573
+ }
0 commit comments