Documentation ¶
Overview ¶
Package serviceutil contains useful experiments and utilities that have not yet reached the level of robustness required to be part of the service package.
Index ¶
Constants ¶
const DefaultShutdownTimeout = 5 * time.Second
Variables ¶
This section is empty.
Functions ¶
func IsRestartLimitExceeded ¶
Types ¶
type HTTP ¶
type HTTP struct { Name service.Name Server *http.Server // When the service is instructed to stop, wait this long for // existing clients to finish before terminating. ShutdownTimeout time.Duration TLS bool // Starts with ListenAndServeTLS if true. CertFile string // If TLS == true, use this file for the certificate. KeyFile string // If TLS == true, use this file for the key. // contains filtered or unexported fields }
HTTP wraps a http.Server in a service.Service.
func (*HTTP) SetTLSCert ¶
SetTLSCertFile configures the HTTP server to use TLS with a cert and key supplied as byte arrays.
Any certificates set in Server.TLSConfig, or set in CertFile/KeyFile are cleared.
func (*HTTP) SetTLSCertFile ¶
SetTLSCertFile configures the HTTP server to use TLS with a cert file and a key file
Any certificates set in Server.TLSConfig are cleared.
type TimedRestart ¶
type TimedRestart struct {
// contains filtered or unexported fields
}
TimedRestart is an experimental service.Runnable that wraps your service and restarts it if it ends prematurely after a specific interval.
It's intended to prototype a method for retrying failed connections or subprocesses.
The "Suspend" function may not work as desired; more testing is required.
func NewTimedRestart ¶
func NewTimedRestart(runnable service.Runnable, timeout time.Duration, wait WaitCalc, options ...TimedRestartOption) *TimedRestart
NewTimedRestart creates a TimedRestart service. If you want to log errors, pass in a listener, otherwise pass nil.
func (*TimedRestart) Running ¶
func (t *TimedRestart) Running() bool
func (*TimedRestart) Starts ¶
func (t *TimedRestart) Starts() uint64
func (*TimedRestart) Suspend ¶
func (t *TimedRestart) Suspend(suspended bool) (changed bool)
Suspend instructs the service to halt and to not restart.
func (*TimedRestart) Suspended ¶
func (t *TimedRestart) Suspended() (out bool)
type TimedRestartOption ¶
type TimedRestartOption func(tr *TimedRestart)
func TimedRestartActive ¶
func TimedRestartActive(active bool) TimedRestartOption
func TimedRestartLimit ¶
func TimedRestartLimit(limit uint64) TimedRestartOption
func TimedRestartNotify ¶
func TimedRestartNotify(r func(start uint64, err error)) TimedRestartOption