svc

package
v0.0.0-...-6065391 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrSystemUnsupported is returned when a function call cannot identify the
	// current system's supervisor
	ErrSystemUnsupported = errors.New("no supported system supervisor located")

	// ErrExeNotExist is returned when the service cannot find it's set executable
	ErrExeNotExist = errors.New("no file located at executable path")

	// ErrExeNotExecutable is returned when an executable path contains a file without valid execute perms
	ErrExeNotExecutable = errors.New("file at executable path is not executable")

	// ErrNoName is returned when a service is attempted to be enumerated without a name
	ErrNoName = errors.New("service does not have a name")

	// ErrNoDescription is returned when a service does not have a description set
	ErrNoDescription = errors.New("service does not have a description")

	// ErrNoDisplayName is returned when a service does not have a display name set
	ErrNoDisplayName = errors.New("service does not have a display name")

	// ErrNotEnoughPerms is returned when the current process does not have sufficient privileges to install a service
	ErrNotEnoughPerms = errors.New("current user does not have privileges to manipulate services")

	// ErrWorkingDirNotExist is returned when the working directory path does not exist
	ErrWorkingDirNotExist = errors.New("working directory does not exist")
)

Functions

func IsErrExeNotExecutable

func IsErrExeNotExecutable(e error) bool

IsErrExeNotExecutable is used to check if a returned error is because the executable has insufficient permissions

func IsErrExeNotExist

func IsErrExeNotExist(e error) bool

IsErrExeNotExist is used to check if a returned error is because the executable doesn't exist

func IsErrNoDescription

func IsErrNoDescription(e error) bool

IsErrNoDescription is used to check if a returned error is because no description is set

func IsErrNoDisplayName

func IsErrNoDisplayName(e error) bool

IsErrNoDisplayName is used to check if a returned error is because no display name is set

func IsErrNoName

func IsErrNoName(e error) bool

IsErrNoName is used to check if a returned error is because no name is set

func IsErrNotEnoughPerms

func IsErrNotEnoughPerms(e error) bool

IsErrNotEnoughPerms is used to check if a returned error is because the current process lacks privileges to manipulate system services

func IsErrSystemUnsupported

func IsErrSystemUnsupported(e error) bool

IsErrSystemUnsupported is used to check if a returned error is because the current system does not have a supported supervisor

func IsErrWorkingDirNotExist

func IsErrWorkingDirNotExist(e error) bool

IsErrWorkingDirNotExist is used to check if a returned error is because the defined working directory does not exist

func ServicePlatform

func ServicePlatform() string

ServicePlatform returns a string of the current system's service platform

Types

type KeyValue

type KeyValue map[string]interface{}

KeyValue is a helper type alias for platform specific options

func (KeyValue) GetBool

func (k KeyValue) GetBool(key string) bool

GetBool will return a true when a value exists and is anything other a boolean "false". Otherwise it will return false.

type Service

type Service struct {
	Name             string   `json:"name,omitempty"`
	DisplayName      string   `json:"display_name,omitempty"`
	Description      string   `json:"description,omitempty"`
	UserName         string   `json:"user_name,omitempty"`
	Arguments        []string `json:"arguments,omitempty"`
	ExecutablePath   string   `json:"executable_path,omitempty"`
	WorkingDirectory string   `json:"working_directory,omitempty"`
	Options          KeyValue `json:"options"`
}

Service represents a definition for a system service (cross platform)

func NewAsZero

func NewAsZero() *Service

NewAsZero instantiates a zero value Service object

func NewFromArgs

func NewFromArgs(name, displayName, description, exePath string, args []interface{}, opts map[string]interface{}) (*Service, error)

NewFromArgs instantiates a Service object given the parameters

func NewFromJSON

func NewFromJSON(jsonData map[string]interface{}) (*Service, error)

NewFromJSON instantiates a Service object from a given map of parameters

func (*Service) AppendArguments

func (s *Service) AppendArguments(args []interface{})

AppendArguments does not clear the current argument list, simply adds to it.

func (*Service) CheckConfig

func (s *Service) CheckConfig(autofix bool) (bool, error)

CheckConfig looks to make sure the options and information you've defined in your Service object checks out for the current system.

func (*Service) CheckExists

func (s *Service) CheckExists() (bool, error)

CheckExists will attempt to check to see if the service as defined already exists on the system. Note: this currently does not work on Windows since there is no file location to check.

func (*Service) Install

func (s *Service) Install(overwrite bool) error

Install attempts to install the defined system service

func (*Service) Restart

func (s *Service) Restart() error

Restart attempts to restart a service with a delay of 50 milliseconds.

func (*Service) RestartWithDelay

func (s *Service) RestartWithDelay(seconds int64) error

RestartWithDelay will stop a service, wait for a given period of time, then attempt to start the service after the delay period.

func (*Service) ServiceFilePath

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

ServiceFilePath returns the path to config file (where applicable) for the defined configuration.

func (*Service) SetArguments

func (s *Service) SetArguments(args []interface{})

SetArguments clears the service's defined arguments and re-defines them given the passed args.

func (*Service) SetDescription

func (s *Service) SetDescription(description string)

SetDescription sets the service description

func (*Service) SetDisplayName

func (s *Service) SetDisplayName(displayName string)

SetDisplayName sets the service longer display name

func (*Service) SetExecutablePath

func (s *Service) SetExecutablePath(exepath string)

SetExecutablePath sets the location where the executable binary will be on the filesystem. Note - should ensure executable has valid execute permissions on the filesystem.

func (*Service) SetName

func (s *Service) SetName(name string)

SetName sets the service name

func (*Service) SetOptions

func (s *Service) SetOptions(opts map[string]interface{})

SetOptions allows you to overwrite the current options and it's values.

func (*Service) SetUserName

func (s *Service) SetUserName(username string)

SetUserName sets the user to run the service as Note: not supported on darwin-launchd, unix-systemv, windows-service requires a 'Password' option value.

func (*Service) SetWorkingDirectory

func (s *Service) SetWorkingDirectory(dir string)

SetWorkingDirectory allows you to tell the platform (where supported) what directory the program should be located in while running.

func (*Service) Start

func (s *Service) Start() error

Start attempts to start the running service

func (*Service) Stop

func (s *Service) Stop() error

Stop attempts to stop the running service

func (*Service) Uninstall

func (s *Service) Uninstall() error

Uninstall attempts to remove a system service from the local system including: - stopping the service - uninstalling the service - removing symlinks to any scripts - removing config files - reloading platform service supervisors when applicable

Jump to

Keyboard shortcuts

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