launchd

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: BSD-3-Clause Imports: 11 Imported by: 1

README

launchd

🚀 Manage go daemons on MacOS

A set of methods for interacting with the MacOS launchd(8) init system.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// Name is the fully qualified name of the service e.g. com.id.doom
	Name string
	// ExecutablePath is the absolute path to the executable that will run the service
	ExecutablePath string
	// Argv is the list of arguments to pass to ExecutablePath
	Argv []string
	// RunAtLoad is whether the service should be started at login
	RunAtLoad bool
	// KeepAlive is whether the service should be restarted if it crashes
	KeepAlive bool
}

Service is a LaunchAgent service.

func ForRunningProgram added in v0.2.0

func ForRunningProgram(name string, argv []string) *Service

ForRunningProgram returns a Service with appropriate daemon defaults for the current running executable.

func (*Service) Bootout added in v0.2.3

func (s *Service) Bootout(removePlist bool) error

Bootout uninstalls a service (`launchctl bootout` née `launchctl unload`) Optionally deletes the service definition file (plist) as well.

func (*Service) Bootstrap

func (s *Service) Bootstrap() ([]byte, error)

Bootstrap a new service (`launchctl bootstrap` née `launchctl load`)

func (*Service) DefinitionPath

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

DefinitionPath is the absolute fs path where the service's plist config lives

func (*Service) Install

func (s *Service) Install() (err error)

Install sets up a new service by writing a plist file and telling launchd about it. It also starts the service and waits for it to come up if RunAtLoad is true.

func (*Service) InstallState

func (s *Service) InstallState() *state.Install

InstallState returns information about whether or not a service is installed.

func (*Service) IsHealthy

func (s *Service) IsHealthy() bool

IsHealthy returns true if the service is running and healthy.

func (*Service) PollUntil

func (s *Service) PollUntil(desired state.RunState, timeout time.Duration) (current *state.Run, timedOut bool)

PollUntil polls the service until it reaches the desired state or the timeout is reached.

func (*Service) Print

func (s *Service) Print() ([]byte, error)

Print service state (`launchctl print`)

func (*Service) RenderPlist added in v0.2.0

func (s *Service) RenderPlist() ([]byte, error)

RenderPlist returns the contents of a plist file content for a launchd service.

func (*Service) RunState

func (s *Service) RunState() *state.Run

RunState returns information about the runtime status of a service.

func (*Service) Start added in v0.2.5

func (s *Service) Start() error

Start a service (`launchctl start`)

func (*Service) Stop added in v0.2.5

func (s *Service) Stop() error

Stop a service (`launchctl stop`)

func (*Service) UserSpecifier

func (s *Service) UserSpecifier() string

UserSpecifier unambiguously identifies the service in subcommands. e.g. gui/501/com.id.doom See launchctl(1).

func (*Service) WritePlist added in v0.2.0

func (s *Service) WritePlist(content []byte) error

WritePlist writes the contents of the service's plist file content to the appropriate directory.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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