Documentation ¶
Overview ¶
Package cerberus is a Windows service helper program inspired by [NSSM](https://nssm.cc/). It can be used to create and manage Windows services for ordinary binaries.
Index ¶
- Variables
- func InstallService(config SvcConfig) error
- func RemoveService(name string) error
- func RemoveServiceCfg(name string) error
- func RunService(name string) error
- func UpdateService(config SvcConfig) error
- type Error
- type ErrorCode
- type RecoveryAction
- type StartType
- type StopSignal
- type SvcConfig
- type SvcRecoveryAction
Constants ¶
This section is empty.
Variables ¶
var DebugLogger = log.New(ioutil.Discard, "Cerberus: ", 0)
DebugLogger logs all debug information, per default ioutil.Discard is used and no output is generated.
var Logger = log.New(os.Stdout, "Cerberus: ", 0)
Logger is the default logger for cerberus. Per default os.Stdout is used.
Functions ¶
func InstallService ¶
InstallService installs a windows service with the given configuration.
func RemoveService ¶
RemoveService removes the service with the given name. Stops the service first, can return a timeout error if it can't stop the service.
func RemoveServiceCfg ¶
RemoveServiceCfg removes the service configuration form the cerberus service db. It returns a generic error if call fails.
func RunService ¶
RunService runs the service with the given name.
func UpdateService ¶ added in v2.1.2
UpdateService updates a cerberus service with the given configuration.
Types ¶
type ErrorCode ¶
type ErrorCode int
ErrorCode cerberus unique error codes.
const ( // ErrGeneric indicates a general error. ErrGeneric ErrorCode // ErrSaveServiceCfg indicates error while saving the service configuration. ErrSaveServiceCfg // ErrLoadServiceCfg indicates error while loading the service configuration. ErrLoadServiceCfg // ErrInstallService indicates error while installing a service. ErrInstallService // ErrUpdateService indicates error while updating a service. ErrUpdateService // ErrInvalidConfiguration indicates error while validating service configuration. ErrInvalidConfiguration // ErrRemoveService indicates error while removing a service. ErrRemoveService // ErrRunService indicates error while running a service. ErrRunService // ErrTimeout indicates an action run into a timeout. ErrTimeout // ErrSCMConnect indicates a failure while connecting to the SCM. ErrSCMConnect )
type RecoveryAction ¶ added in v2.1.2
type RecoveryAction int
RecoveryAction defines what happens if a binary exits with error
const ( // NoAction is the default action and will stop the service on error. NoAction RecoveryAction = 1 << iota // RestartAction restarts the serivce according the specified settings. RestartAction // RunProgramAction will run the specified program. RunProgramAction // RunAndRestartAction restarts the service and runs the specified program. RunAndRestartAction = RestartAction | RunProgramAction )
type StartType ¶ added in v2.1.2
type StartType uint32
StartType configures the startup type.
const ( // AutoStartType configures the service to startup automatically. AutoStartType StartType = 2 // AutoDelayedStartType configures the service to startup automatically with delay. AutoDelayedStartType StartType = 9999 // ManualStartType configures the service for manual startup. ManualStartType StartType = 3 // DisabledStartType disables the service. DisabledStartType StartType = 4 )
type StopSignal ¶ added in v2.1.2
type StopSignal int
StopSignal specifies a signal to send to a process if the service has to stop.
const ( CtrlCSignal StopSignal = 1 << iota WmQuitSignal WmCloseSignal NoSignal StopSignal = 0 )
Signals to send to a process to gracefully terminate a process. WmQuit and WmClose signal works only for application with a window.
func (StopSignal) String ¶ added in v2.1.2
func (s StopSignal) String() string
type SvcConfig ¶
type SvcConfig struct { // Base configuration Name string Desc string DisplayName string ExePath string WorkDir string Args []string Env []string // Extended Configurations RecoveryActions map[int]SvcRecoveryAction StopSignal StopSignal // SCM Properties (Admin rights require to load this properties) Dependencies []string ServiceUser string Password *string StartType StartType }
SvcConfig is the data required run the executable as a service.
func LoadServiceCfg ¶
LoadServiceCfg loads a service configuration for a given service from the cerberus service db.
func LoadServicesCfg ¶
LoadServicesCfg loads all configured services.
type SvcRecoveryAction ¶ added in v2.1.2
type SvcRecoveryAction struct { ExitCode int Action RecoveryAction Delay int MaxRestarts int ResetAfter time.Duration Program string Arguments []string }
SvcRecoveryAction defines what cerberus should do if a binary returns an error.