Documentation
¶
Index ¶
- Variables
- func ControlService(ctx context.Context, name string, c svc.Cmd, to svc.State) error
- func GetTimeout() (d time.Duration, err error)
- func InstallService(exepath, name string, mgrConfig mgr.Config, cmdArgs []string, opts ...SvcOpt) error
- func MaximizeTimeout() error
- func QueryService(name string) (svc.State, error)
- func RemoveService(name string) error
- func StartService(name string, cmdArgs []string) error
- type EventLogWriter
- type SvcOpt
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var StateLabel = map[svc.State]string{ svc.Stopped: "Stopped", svc.StartPending: "StartPending", svc.StopPending: "StopPending", svc.Running: "Running", svc.ContinuePending: "ContinuePending", svc.PausePending: "PausePending", svc.Paused: "Paused", }
Functions ¶
func ControlService ¶
ControlService sends state change request c to the service name.
func GetTimeout ¶
GetTimeout returns the timeout duration based on the registry value of LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\WaitToKillServiceTimeout
func InstallService ¶
func InstallService(exepath, name string, mgrConfig mgr.Config, cmdArgs []string, opts ...SvcOpt) error
InstallService installs new service name on the system.
Example ¶
exepath, err := os.Executable() if err != nil { return } InstallService( exepath, "test-service", mgr.Config{ StartType: mgr.StartAutomatic, Description: "golang test service", DelayedAutoStart: true, Dependencies: []string{"W32time"}, }, nil, // command-line arguments when the service is started func(s *mgr.Service) error { // enable to apply SetRecoveryActions, SetRecoveryCommand or SetRebootMessage return s.SetRecoveryActions( []mgr.RecoveryAction{ mgr.RecoveryAction{ Type: mgr.ServiceRestart, Delay: 1 * time.Minute, }, mgr.RecoveryAction{ Type: mgr.ServiceRestart, Delay: 1 * time.Minute, }, mgr.RecoveryAction{ Type: mgr.ServiceRestart, Delay: 1 * time.Minute, }, }, 0, ) }, )
Output:
func MaximizeTimeout ¶
func MaximizeTimeout() error
MaximizeTimeout tries to change the registry value of LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\WaitToKillServiceTimeout to "20000"
func QueryService ¶
QueryService gets the status of the service name
func RemoveService ¶
RemoveService removes the service name on the system.
func StartService ¶
StartService starts the service name
Types ¶
type EventLogWriter ¶
type EventLogWriter struct {
// contains filtered or unexported fields
}
func NewEventLogWriter ¶
func NewEventLogWriter( svcname string, eId uint32, infoKey, warningKey, errorKey string, ) (*EventLogWriter, error)
NewEventLogWriter creates a new io.WriteCloser. Writes to the returned io.WriteCloser are output to eventlog.Log.Info/Warning/Error depending on the presence of the keywords.
func (*EventLogWriter) Close ¶
func (elw *EventLogWriter) Close() error