gowatchprog

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

README

GoWatchProg

Project Status: ⚠️ early development

This module was created to help manage background services on machines by providing the following core feature sets.

  • Install to a proper location based on installation context (user, system, allusers)
  • Register service autostart based on service run context (user, system, allusers)
  • Watchdog autorestart (retry count, retry delay, retry delay increase)
  • Install updates remotely

Install

go get github.com/micaiahwallace/gowatchprog

Documentation

View the documentation on pkg.go.dev

Example

You can see gowatchprog in action on one of my other projects GoScreenMonit

Roadmap

  • Windows support (Full context set not implemented for install / startup)
  • Remote update feature
  • Mac OS support
  • Linux support
  • Features accessible from command line utility (for non-go services)

Documentation

Overview

* file: paths.go

This file provides functions for getting paths to various files and directories regarding the program and its contexts.

Index

Constants

View Source
const PID_FILE = "watchdog.pid"

Variables

View Source
var ErrPathNotFound = errors.New("path not found")
View Source
var InstallPathRoot = map[ProgramContext]string{
	SystemService: filepath.Join("/", "usr", "local"),
	AllUsers:      filepath.Join("/", "usr", "local"),
	CurrentUser:   filepath.Join(os.Getenv("HOME"), ".local"),
}

Functions

func GetCommandLine added in v0.2.1

func GetCommandLine(binPath string, args []string) string

Wrap the binary path in quotes and append the space separated args at the end, return the final string

Types

type InvalidContextError added in v0.2.1

type InvalidContextError string
const ErrInvalidContext InvalidContextError = "Unknown application context"

func (InvalidContextError) Error added in v0.2.1

func (e InvalidContextError) Error() string

type Program

type Program struct {

	// Name of the service
	Name string

	// Filename of service binary
	ExeFile string

	// Arguments to append when service is run
	Args []string

	// Path to installer for user context when AllUsers context is specified
	UserInstaller string

	// Installation context of the service
	InstallContext ProgramContext

	// Startup context of the service
	StartupContext ProgramContext

	// Watchdog retry count before failing, -1 for unlimited
	WatchRetries int

	// Watchdog interval between retries
	WatchRetryWait time.Duration

	// Watchdog factor to increase wait interval each failed attempt
	WatchRetryIncrease int
}

Program defines a program installation that can be used to install, uninstall or start a watchdog based on the defined properties.

func (*Program) DataDirectory

func (p *Program) DataDirectory(create bool) (string, error)

Get the path to the installation data directory

func (*Program) InstallBinary added in v0.2.0

func (p *Program) InstallBinary(sourceBin string) error

Install sourceBin binary file to p.ExeFile in the install directory

func (*Program) InstallDirectory

func (p *Program) InstallDirectory(create bool) (string, error)

Get the path to the installation directory

func (*Program) Installed

func (p *Program) Installed() bool

Check if the program is installed

func (*Program) InstalledBinary added in v0.2.0

func (p *Program) InstalledBinary() (string, error)

Get the path to the ExeFile inside the installation directory

func (*Program) RegisterStartup

func (p *Program) RegisterStartup() error

Register the installed service startup on linux

func (*Program) RemoveInstallation added in v0.2.0

func (p *Program) RemoveInstallation() error

Remove installation directories specified by InstallContext and StartupContext

func (*Program) RemoveStartup

func (p *Program) RemoveStartup() error

Deregister the installed service from startup on linux

func (*Program) RunWatchdog

func (p *Program) RunWatchdog(errs chan error, msgs chan string, quit chan interface{})

Start the watchdog runner

func (*Program) SafeName added in v0.2.1

func (p *Program) SafeName() string

Returns a name safe to use for a directory and registry key

func (*Program) Uninstall

func (p *Program) Uninstall() error

Uninstall is equivalent to running RemoveStartup() then RemoveInstallation()

type ProgramContext

type ProgramContext int

Specifies the type of program installation, so that Program can customize how it installs and configures startup on each system.

const (

	// A global context to install and run user session software for all users
	AllUsers ProgramContext = iota

	// A local context to install and run user session software for the current user
	CurrentUser

	// A global context to install and run a system level service not running in a user context
	SystemService
)

Jump to

Keyboard shortcuts

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