Back to godoc.org

Package mgr

v0.0.0-...-9773273
Latest Go to latest

The latest major version is .

Published: Apr 12, 2019 | License: BSD-3-Clause | Module: golang.org/x/sys

Overview

Package mgr can be used to manage Windows service programs. It can be used to install and remove them. It can also start, stop and pause them. The package can query / change current service state and config parameters.

Index

Constants

const (
	// Service start types.
	StartManual    = windows.SERVICE_DEMAND_START // the service must be started manually
	StartAutomatic = windows.SERVICE_AUTO_START   // the service will start by itself whenever the computer reboots
	StartDisabled  = windows.SERVICE_DISABLED     // the service cannot be started

	// The severity of the error, and action taken,
	// if this service fails to start.
	ErrorCritical = windows.SERVICE_ERROR_CRITICAL
	ErrorIgnore   = windows.SERVICE_ERROR_IGNORE
	ErrorNormal   = windows.SERVICE_ERROR_NORMAL
	ErrorSevere   = windows.SERVICE_ERROR_SEVERE
)
const (
	// Possible recovery actions that the service control manager can perform.
	NoAction       = windows.SC_ACTION_NONE        // no action
	ComputerReboot = windows.SC_ACTION_REBOOT      // reboot the computer
	ServiceRestart = windows.SC_ACTION_RESTART     // restart the service
	RunCommand     = windows.SC_ACTION_RUN_COMMAND // run a command
)

type Config

type Config struct {
	ServiceType      uint32
	StartType        uint32
	ErrorControl     uint32
	BinaryPathName   string // fully qualified path to the service binary file, can also include arguments for an auto-start service
	LoadOrderGroup   string
	TagId            uint32
	Dependencies     []string
	ServiceStartName string // name of the account under which the service should run
	DisplayName      string
	Password         string
	Description      string
}

type Mgr

type Mgr struct {
	Handle windows.Handle
}

Mgr is used to manage Windows service.

func Connect

func Connect() (*Mgr, error)

Connect establishes a connection to the service control manager.

func ConnectRemote

func ConnectRemote(host string) (*Mgr, error)

ConnectRemote establishes a connection to the service control manager on computer named host.

func (*Mgr) CreateService

func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Service, error)

CreateService installs new service name on the system. The service will be executed by running exepath binary. Use config c to specify service parameters. Any args will be passed as command-line arguments when the service is started; these arguments are distinct from the arguments passed to Service.Start or via the "Start parameters" field in the service's Properties dialog box.

func (*Mgr) Disconnect

func (m *Mgr) Disconnect() error

Disconnect closes connection to the service control manager m.

func (*Mgr) ListServices

func (m *Mgr) ListServices() ([]string, error)

ListServices enumerates services in the specified service control manager database m. If the caller does not have the SERVICE_QUERY_STATUS access right to a service, the service is silently omitted from the list of services returned.

func (*Mgr) OpenService

func (m *Mgr) OpenService(name string) (*Service, error)

OpenService retrieves access to service name, so it can be interrogated and controlled.

type RecoveryAction

type RecoveryAction struct {
	Type  int           // one of NoAction, ComputerReboot, ServiceRestart or RunCommand
	Delay time.Duration // the time to wait before performing the specified action
}

RecoveryAction represents an action that the service control manager can perform when service fails. A service is considered failed when it terminates without reporting a status of SERVICE_STOPPED to the service controller.

type Service

type Service struct {
	Name   string
	Handle windows.Handle
}

Service is used to access Windows service.

func (*Service) Close

func (s *Service) Close() error

Close relinquish access to the service s.

func (*Service) Config

func (s *Service) Config() (Config, error)

Config retrieves service s configuration paramteres.

func (*Service) Control

func (s *Service) Control(c svc.Cmd) (svc.Status, error)

Control sends state change request c to the servce s.

func (*Service) Delete

func (s *Service) Delete() error

Delete marks service s for deletion from the service control manager database.

func (*Service) Query

func (s *Service) Query() (svc.Status, error)

Query returns current status of service s.

func (*Service) RebootMessage

func (s *Service) RebootMessage() (string, error)

RebootMessage is broadcast to server users before rebooting in response to the ComputerReboot service controller action.

func (*Service) RecoveryActions

func (s *Service) RecoveryActions() ([]RecoveryAction, error)

RecoveryActions returns actions that service controller performs when service fails. The service control manager counts the number of times service s has failed since the system booted. The count is reset to 0 if the service has not failed for ResetPeriod seconds. When the service fails for the Nth time, the service controller performs the action specified in element [N-1] of returned slice. If N is greater than slice length, the service controller repeats the last action in the slice.

func (*Service) RecoveryCommand

func (s *Service) RecoveryCommand() (string, error)

RecoveryCommand is the command line of the process to execute in response to the RunCommand service controller action. This process runs under the same account as the service.

func (*Service) ResetPeriod

func (s *Service) ResetPeriod() (uint32, error)

ResetPeriod is the time after which to reset the service failure count to zero if there are no failures, in seconds.

func (*Service) ResetRecoveryActions

func (s *Service) ResetRecoveryActions() error

ResetRecoveryActions deletes both reset period and array of failure actions.

func (*Service) SetRebootMessage

func (s *Service) SetRebootMessage(msg string) error

SetRebootMessage sets service s reboot message. If msg is "", the reboot message is deleted and no message is broadcast.

func (*Service) SetRecoveryActions

func (s *Service) SetRecoveryActions(recoveryActions []RecoveryAction, resetPeriod uint32) error

SetRecoveryActions sets actions that service controller performs when service fails and the time after which to reset the service failure count to zero if there are no failures, in seconds. Specify INFINITE to indicate that service failure count should never be reset.

func (*Service) SetRecoveryCommand

func (s *Service) SetRecoveryCommand(cmd string) error

SetRecoveryCommand sets the command line of the process to execute in response to the RunCommand service controller action. If cmd is "", the command is deleted and no program is run when the service fails.

func (*Service) Start

func (s *Service) Start(args ...string) error

Start starts service s. args will be passed to svc.Handler.Execute.

func (*Service) UpdateConfig

func (s *Service) UpdateConfig(c Config) error

UpdateConfig updates service s configuration parameters.

Package Files

Documentation was rendered with GOOS=windows and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier