Documentation ¶
Index ¶
- Variables
- func IsErrExeNotExecutable(e error) bool
- func IsErrExeNotExist(e error) bool
- func IsErrNoDescription(e error) bool
- func IsErrNoDisplayName(e error) bool
- func IsErrNoName(e error) bool
- func IsErrNotEnoughPerms(e error) bool
- func IsErrSystemUnsupported(e error) bool
- func IsErrWorkingDirNotExist(e error) bool
- func ServicePlatform() string
- type KeyValue
- type Service
- func (s *Service) AppendArguments(args []interface{})
- func (s *Service) CheckConfig(autofix bool) (bool, error)
- func (s *Service) CheckExists() (bool, error)
- func (s *Service) Install(overwrite bool) error
- func (s *Service) Restart() error
- func (s *Service) RestartWithDelay(seconds int64) error
- func (s *Service) ServiceFilePath() (string, error)
- func (s *Service) SetArguments(args []interface{})
- func (s *Service) SetDescription(description string)
- func (s *Service) SetDisplayName(displayName string)
- func (s *Service) SetExecutablePath(exepath string)
- func (s *Service) SetName(name string)
- func (s *Service) SetOptions(opts map[string]interface{})
- func (s *Service) SetUserName(username string)
- func (s *Service) SetWorkingDirectory(dir string)
- func (s *Service) Start() error
- func (s *Service) Stop() error
- func (s *Service) Uninstall() error
Constants ¶
This section is empty.
Variables ¶
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 ¶
IsErrExeNotExecutable is used to check if a returned error is because the executable has insufficient permissions
func IsErrExeNotExist ¶
IsErrExeNotExist is used to check if a returned error is because the executable doesn't exist
func IsErrNoDescription ¶
IsErrNoDescription is used to check if a returned error is because no description is set
func IsErrNoDisplayName ¶
IsErrNoDisplayName is used to check if a returned error is because no display name is set
func IsErrNoName ¶
IsErrNoName is used to check if a returned error is because no name is set
func IsErrNotEnoughPerms ¶
IsErrNotEnoughPerms is used to check if a returned error is because the current process lacks privileges to manipulate system services
func IsErrSystemUnsupported ¶
IsErrSystemUnsupported is used to check if a returned error is because the current system does not have a supported supervisor
func IsErrWorkingDirNotExist ¶
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
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 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 ¶
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 ¶
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 ¶
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) RestartWithDelay ¶
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 ¶
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 ¶
SetDescription sets the service description
func (*Service) SetDisplayName ¶
SetDisplayName sets the service longer display name
func (*Service) SetExecutablePath ¶
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) SetOptions ¶
SetOptions allows you to overwrite the current options and it's values.
func (*Service) SetUserName ¶
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 ¶
SetWorkingDirectory allows you to tell the platform (where supported) what directory the program should be located in while running.