winsvc

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2020 License: MIT Imports: 10 Imported by: 0

README

winsvc

The modularlization of the official example of windows service.

Example

An example is here.

Documentation

Rendered for windows/amd64

Index

Examples

Constants

This section is empty.

Variables

View Source
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

func ControlService(ctx context.Context, name string, c svc.Cmd, to svc.State) error

ControlService sends state change request c to the service name.

func GetTimeout

func GetTimeout() (d time.Duration, err error)

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

func QueryService(name string) (svc.State, error)

QueryService gets the status of the service name

func RemoveService

func RemoveService(name string) error

RemoveService removes the service name on the system.

func StartService

func StartService(name string, cmdArgs []string) error

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

func (*EventLogWriter) Write

func (elw *EventLogWriter) Write(p []byte) (n int, err error)

type SvcOpt

type SvcOpt func(*mgr.Service) error

SvcOpt can apply SetRecoveryActions, SetRecoveryCommand or SetRebootMessage to service.

Directories

Path Synopsis
Example service program that works as http server.
Example service program that works as http server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL