daemonize

package
v0.0.0-...-841f565 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPidNotFound raised when a pid cannot be by querying the OS
	ErrPidNotFound = errors.New("pid not found")

	// ErrPIDInvalid raised when an invalid pid is parsed from a pidfile
	ErrPIDInvalid = errors.New("pid wasn't valid")

	// ErrFailedToAcquirePidLock raised when a lock acquisition times out or fails due to contention
	ErrFailedToAcquirePidLock = errors.New("failed to acquire lock on pidfile")

	// ErrFailedToWritePidFile raised when the pid cannot be written to the pidfile
	ErrFailedToWritePidFile = errors.New("failed to write pidfile")

	// ErrFailedToStartProc we failed to call os.Exec
	ErrFailedToStartProc = errors.New("failed to start process")

	// ErrFailedToDetach we started the process but failed to orphan it
	ErrFailedToDetach = errors.New("failed to detach from process")

	// ErrAlreadyRunning raised by Proc.Init when a pid is active
	ErrAlreadyRunning = errors.New("cannot init process pid is already running")

	// ErrTimeout is raised when we fail to stop a process
	ErrTimeout = errors.New("an operation timed out")
)

Functions

func FindProcess

func FindProcess(pid int) (*os.Process, error)

FindProcess attempts to locate a process by its pid returns a wrapped ErrPidNotFound if the process cannot be signaled

func Fork

func Fork(program string, args ...string) (int, error)

Fork allows a program to be started and orphaned This process will exit without cleaning up its child process It is highly recommended managing the PID returned from this function

func LoadPidFile

func LoadPidFile(pidfile string) (int, error)

LoadPidFile opens a pidfile and parses its value as an integer

func Stop

func Stop(pidfile string) error

Stop accepts the location of a pid file and attempts to clean up the running process Will block until the process exits and timeout after 10 seconds

Types

type Proc

type Proc struct {
	// contains filtered or unexported fields
}

Proc a struct that houses data for managing a process

func NewProc

func NewProc(command string, arguments []string, pidfile string) *Proc

NewProc creates a new instance of a Proc init system

func (*Proc) Init

func (p *Proc) Init() error

Init attempts to validate if a process is already running at the given pidfile If the process is already running no action is taken If the process isn't running we attempt to acquire a lock pidfile We then start the process and store its pid in the pidfile and release the lock

func (*Proc) Status

func (p *Proc) Status() (STATE, error)

Status returns the STATE of the running process

func (*Proc) Stop

func (p *Proc) Stop() error

Stop stops the current proc

type STATE

type STATE int

STATE the applications execution state

const (
	// STATE_UNKNOWN the process is in an unknown state (possible due to an error)
	STATE_UNKNOWN STATE = iota

	// STATE_RUNNING the process is running
	STATE_RUNNING

	// STATE_STOPPED the process isn't currently running
	STATE_STOPPED
)

Jump to

Keyboard shortcuts

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