Documentation ¶
Index ¶
- Constants
- func AddExitAction(f func())
- func AddSighupHandler(handler func())
- func AppRun()
- func AppStart(setup IAppStartSetup) (exitCode int, err error)
- func AppStop(graceful bool, sd *SetuidData) (exitCode int, err error)
- func CheckAppConfig(config configuration.IConfig) error
- func CheckHTTPConfig(httpConfig configuration.IConfig) error
- func CheckLockFileConfig(conf configuration.IConfig) (err error)
- func CheckLogConfig(tag string, conf configuration.IConfig) error
- func CheckPidfileConfig(pidfileConfig configuration.IConfig) error
- func CheckSetuidConfig(setuidConfig configuration.IConfig) error
- func CleanupSighupHandlers()
- func DropHTTPListener()
- func DropHTTPServer()
- func DropLockFile()
- func DropLogger(tag string)
- func DropPidfile()
- func Exit(code int)
- func GetCommandLineFlags(CustomFlags func(cmdFlags map[string]string)) map[string]string
- func GetEnvironment(sl ...interface{}) (env string, err error)
- func GetHTTPListener() net.Listener
- func GetHTTPLogger() *zerolog.Logger
- func GetHTTPServer() *http.Server
- func GetLogger(tag string) *zerolog.Logger
- func GetSystemLogger() *zerolog.Logger
- func PrepareHTTPListener(graceful bool, httpConfig configuration.IConfig) error
- func SetHTTPServeMux(mux http.Handler)
- func SetupHTTPServer(httpConfig configuration.IConfig) error
- func SetupLockFile(conf configuration.IConfig) (err error)
- func SetupLog(tag string, config configuration.IConfig) (logger *zerolog.Logger, err error)
- func SetupPidfile(pidfileConfig configuration.IConfig) error
- func SetupSighupHandlers()
- func SetupSighupRotationForLogs() error
- func StartHTTPServer()
- func ValidateEnv(str string) error
- type DefaultAppStartSetup
- func (*DefaultAppStartSetup) CheckUserConfig(mainconf configuration.IConfig) error
- func (*DefaultAppStartSetup) CommandLineHook(cmdFlags map[string]string)
- func (*DefaultAppStartSetup) ConfigureHTTPServer(graceful bool) error
- func (*DefaultAppStartSetup) HandleSignal(sg os.Signal) error
- func (*DefaultAppStartSetup) NeedHTTP() bool
- func (*DefaultAppStartSetup) SetupOwnExtraFiles(cmd *exec.Cmd, newConfig configuration.IConfig) error
- func (*DefaultAppStartSetup) SystemSetup(graceful bool) error
- func (*DefaultAppStartSetup) SystemShutdown(graceful bool) error
- func (*DefaultAppStartSetup) SystemStart(graceful bool) error
- type IAppStartSetup
- type NullWriter
- type SetuidData
Constants ¶
const ( ExitCodeNormalExit = iota ExitCodeWrongEnv ExitCodeConfigError ExitCodeLockfileError ExitHTTPStartError ExitUserDefinedCodeError ExitHTTPServeError ExitCustomAppError ExitSuidError )
variants of exit codes
Variables ¶
This section is empty.
Functions ¶
func AddExitAction ¶
func AddExitAction(f func())
AddExitAction adds action to our exit function(close logs, remove pid file etc. - for normal exit case)
func AddSighupHandler ¶
func AddSighupHandler(handler func())
AddSighupHandler adds sighup handler to catch suck things as log rotation
func AppRun ¶
func AppRun()
AppRun just to run app when we all do here is no way cover with tests cause need manually test them or make integration tests there
func AppStart ¶
func AppStart(setup IAppStartSetup) (exitCode int, err error)
AppStart app start function if graceful - then to app transmitted http socket in fd 3 https in fd 4 etc.
func AppStop ¶
func AppStop(graceful bool, sd *SetuidData) (exitCode int, err error)
AppStop is intended to control app stop while things: SIGINT handling, SIGTERM handling, SIGUSR handling for a graceful exit to give socket descriptors to new process if graceful==true then function tries make graceful restart function makes app restart and also makes it's suid start NOTICE: if set suid and graceful restart and lower ports are used we assume than you do not change port numbers cause we do not have root controller process to supervise lower ports openings
func CheckAppConfig ¶
func CheckAppConfig(config configuration.IConfig) error
CheckAppConfig checks whole configuration file like their initialization order and returns error if something is wrong NOTE: Environment must be initialized before start this function this function is intended to configtest commandline argument and for application startup
func CheckHTTPConfig ¶
func CheckHTTPConfig(httpConfig configuration.IConfig) error
CheckHTTPConfig to check http config part at startup
func CheckLockFileConfig ¶
func CheckLockFileConfig(conf configuration.IConfig) (err error)
CheckLockFileConfig checks config file if is not correct
func CheckLogConfig ¶
CheckLogConfig checks config internals before and in SetupLog call
func CheckPidfileConfig ¶
func CheckPidfileConfig(pidfileConfig configuration.IConfig) error
CheckPidfileConfig checks pidfile subconfig
func CheckSetuidConfig ¶
func CheckSetuidConfig(setuidConfig configuration.IConfig) error
CheckSetuidConfig checks setuid part of configuration file
func CleanupSighupHandlers ¶
func CleanupSighupHandlers()
CleanupSighupHandlers clears channel and routines
func DropHTTPListener ¶
func DropHTTPListener()
DropHTTPListener close socket. Call when not graceful there
func DropHTTPServer ¶
func DropHTTPServer()
DropHTTPServer shut downs and drop server - not listener
func DropLogger ¶
func DropLogger(tag string)
DropLogger drops log from our internal registry to e.g. reinit them while reload logs
func Exit ¶
func Exit(code int)
Exit run exit actions in reverse order one by one and after run os.exit no sense to test cause exits program motherfucker
func GetCommandLineFlags ¶
GetCommandLineFlags generates parameter map from commanline and reports errors on usage CustomFlags function add to cmdFlags additional flags all the same as in function
func GetEnvironment ¶
GetEnvironment returns configured application environment function will have 2 parameters first used to reset default false second used to reset to default value - used in error cases I need them for testing purposes too
func GetHTTPListener ¶
GetHTTPListener returns internal http socket
func GetHTTPLogger ¶
GetHTTPLogger is to avoid env.GetLoggger("http") calls to minimize some work
func GetHTTPServer ¶
GetHTTPServer gets http server instance if started
func GetSystemLogger ¶
GetSystemLogger is to avoid env.GetLoggger("system") calls to minimize some work is system logger is not initialized out to stderr
func PrepareHTTPListener ¶
PrepareHTTPListener prepare http socket to run Notice: here we assume config is clean and normal
func SetupHTTPServer ¶
func SetupHTTPServer(httpConfig configuration.IConfig) error
SetupHTTPServer setups http server(not stats!). for case of graceful gives their socket graceful or not here depends on was changed configuration file or not this one you must use after PrepareHTTPListener runned
func SetupLockFile ¶
func SetupLockFile(conf configuration.IConfig) (err error)
SetupLockFile sets up LockFile by the given config
func SetupPidfile ¶
func SetupPidfile(pidfileConfig configuration.IConfig) error
SetupPidfile try setup pidfile if enabled.
func SetupSighupHandlers ¶
func SetupSighupHandlers()
SetupSighupHandlers sets handler at startup got SIGHUP kill We need that e.g. to rotate logs
func SetupSighupRotationForLogs ¶
func SetupSighupRotationForLogs() error
SetupSighupRotationForLogs setups rotation hadlers for logs Call that functions when all logs are set up and configures
func ValidateEnv ¶
ValidateEnv checks correct _Env variable value
Types ¶
type DefaultAppStartSetup ¶
type DefaultAppStartSetup struct { }
DefaultAppStartSetup implements IAppStartSetup this is default app start setup and an example on how to write own appstart class
func (*DefaultAppStartSetup) CheckUserConfig ¶
func (*DefaultAppStartSetup) CheckUserConfig(mainconf configuration.IConfig) error
CheckUserConfig checks user config parts
func (*DefaultAppStartSetup) CommandLineHook ¶
func (*DefaultAppStartSetup) CommandLineHook(cmdFlags map[string]string)
CommandLineHook implements IAppStartSetup.CommandLineHook() method
func (*DefaultAppStartSetup) ConfigureHTTPServer ¶
func (*DefaultAppStartSetup) ConfigureHTTPServer(graceful bool) error
ConfigureHTTPServer implements IAppStartSetup.ConfigureHTTPServer() method
func (*DefaultAppStartSetup) HandleSignal ¶
func (*DefaultAppStartSetup) HandleSignal(sg os.Signal) error
HandleSignal handles signal from OS
func (*DefaultAppStartSetup) NeedHTTP ¶
func (*DefaultAppStartSetup) NeedHTTP() bool
NeedHTTP implements IAppStartSetup.NeedHTTP() method
func (*DefaultAppStartSetup) SetupOwnExtraFiles ¶
func (*DefaultAppStartSetup) SetupOwnExtraFiles(cmd *exec.Cmd, newConfig configuration.IConfig) error
SetupOwnExtraFiles for graceful restart
func (*DefaultAppStartSetup) SystemSetup ¶
func (*DefaultAppStartSetup) SystemSetup(graceful bool) error
SystemSetup implements IAppStartSetup.SystemSetup() method
func (*DefaultAppStartSetup) SystemShutdown ¶
func (*DefaultAppStartSetup) SystemShutdown(graceful bool) error
SystemShutdown implements IAppStartSetup.SystemShutdown
func (*DefaultAppStartSetup) SystemStart ¶
func (*DefaultAppStartSetup) SystemStart(graceful bool) error
SystemStart start custom services
type IAppStartSetup ¶
type IAppStartSetup interface { // NeedHTTP does app need http service or not NeedHTTP() bool // CommandLineHookadds additional command line flags to global cmdFlags structure CommandLineHook(cmdFlags map[string]string) // checks user config parts CheckUserConfig(mainconf configuration.IConfig) error // SystemSetup setup other suid ports here, sockets, etc SystemSetup(graceful bool) error // SetupOwnExtraFiles for graceful restart - transfer suid ports to graceful child // for made System setup when suid or graceful restart // newConfig is full new app config to compare settings SetupOwnExtraFiles(cmd *exec.Cmd, newConfig configuration.IConfig) error // HandleSignal handles signal from OS HandleSignal(sg os.Signal) error // Set up custom http mux, log, etc ConfigureHTTPServer(graceful bool) error // Start custom services - after ports are ready SystemStart(graceful bool) error // Run on app shutdown SystemShutdown(graceful bool) error }
IAppStartSetup appstart setup for application Methods at start are called at following order: 1. CommandLineHook add command line reading 2. CheckUserConfig add additional config tests 3. SystemSetup - prepare own socket listeners etc 3. ConfigureHTTPServer configure e.g. mux for http 4. SystemStart - stat listen listeners, etc. At SIGINT or SIGTERM are called: 1. HandleSignal - to determine type of signal and handle them 2. SystemShutdown - shutdown listenere At SIGUSR1 - system does graceful restart and calls: 1. SystemShutdown if there is graceful flag - do not close listeners - just shut down your services 2. SetupOwnExtraFiles - setup them here to make restart app with open sockets
type SetuidData ¶
type SetuidData struct {
// contains filtered or unexported fields
}
SetuidData intended to transmit data to AppStop to set credentials there
func GetSetUIDGIDData ¶
func GetSetUIDGIDData(setuidConf configuration.IConfig) (*SetuidData, error)
GetSetUIDGIDData lookups Setuid gid data to suid no tests here cause too system dependent
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
helloservice
Here would be main program file located to work To run: ENV=dev go run helloservice.go Also it can do suid from lower ports We listen on default HTTP port and answer hello there and open specific config with special section for our miniservice
|
Here would be main program file located to work To run: ENV=dev go run helloservice.go Also it can do suid from lower ports We listen on default HTTP port and answer hello there and open specific config with special section for our miniservice |
helloservicenohttp
Here would be main program file located to work To run: ENV=dev go run helloservicenohttp.go Also it can do suid from lower ports config with special section for our miniservice This is example for case when http subservice is disabled - see NeedHTTP() method of application object
|
Here would be main program file located to work To run: ENV=dev go run helloservicenohttp.go Also it can do suid from lower ports config with special section for our miniservice This is example for case when http subservice is disabled - see NeedHTTP() method of application object |
simplestart
Here would be main program file located to work To run: ENV=dev go run simplestart.go Or: go build ENV=test ./simplestart and try killall -HUP simplestart to see on how reload works Also it can do suid from lower ports
|
Here would be main program file located to work To run: ENV=dev go run simplestart.go Or: go build ENV=test ./simplestart and try killall -HUP simplestart to see on how reload works Also it can do suid from lower ports |