MINOR: add option to allow delay starting runtime

added AllowDelayedStartMax and AllowDelayedStartTick
to check allow slower starting of HAProxy, useful on limited machines.
these can be accessed with runtimeOptions.AllowDelayedStart(max, tick)
master^2
Zlatko Bratkovic 3 months ago
parent d3babf0d31
commit d79bf18a3b
  1. 37
      runtime/options/allow-delayed-start.go
  2. 4
      runtime/options/options.go
  3. 20
      runtime/runtime_single_client.go

@ -0,0 +1,37 @@
/*
Copyright 2022 HAProxy Technologies
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package options
import "time"
type allowDelayedStart struct {
allowDelayedStartMax time.Duration
allowDelayedStartTick time.Duration
}
func (d allowDelayedStart) Set(o *RuntimeOptions) error {
o.AllowDelayedStartMax = &d.allowDelayedStartMax
o.AllowDelayedStartTick = &d.allowDelayedStartTick
return nil
}
func AllowDelayedStart(allowDelayedStartMax, allowDelayedStartTick time.Duration) RuntimeOption {
return allowDelayedStart{
allowDelayedStartMax: allowDelayedStartMax,
allowDelayedStartTick: allowDelayedStartTick,
}
}

@ -16,11 +16,15 @@ limitations under the License.
package options
import "time"
type RuntimeOptions struct {
MapsDir *string
MasterSocketData *masterSocketData
Sockets map[int]string
DoNotCheckRuntimeOnInit bool
AllowDelayedStartMax *time.Duration
AllowDelayedStartTick *time.Duration
}
type RuntimeOption interface {

@ -71,9 +71,23 @@ func (s *SingleRuntime) Init(ctx context.Context, socketPath string, worker int,
s.process = process
go s.handleIncomingJobs(ctx)
if !runtimeOptions.DoNotCheckRuntimeOnInit {
// check if we have a valid socket
if _, err := s.ExecuteRaw("help"); err != nil {
return err
if runtimeOptions.AllowDelayedStartMax != nil {
now := time.Now()
var err error
for {
if _, err = s.ExecuteRaw("help"); err == nil {
break
}
time.Sleep(*runtimeOptions.AllowDelayedStartTick)
if time.Since(now) > *runtimeOptions.AllowDelayedStartMax {
return fmt.Errorf("cannot connect to runtime API %s within %s: %w", socketPath, *runtimeOptions.AllowDelayedStartMax, err)
}
}
} else {
// check if we have a valid socket
if _, err := s.ExecuteRaw("help"); err != nil {
return err
}
}
}
return nil

Loading…
Cancel
Save