Documentation
¶
Index ¶
- Constants
- Variables
- func CheckPIDFile(pidFileName string) error
- func CreatePIDFile(pidFileName string, pid int) (*pidfile.File, error)
- func ExistsAndRecord(pidFileName string) (bool, error)
- func GetPIDFromFile(pidFileName string) (int, error)
- func Interrupt(pid int) error
- func InterruptProcess(pidFile string) (int, error)
- func IsProcessAlive(pid int) (bool, error)
- func KillProcessGroup(pid int) error
- func QuitProcess(pid int) error
- func StopProcess(pidFile string) (int, error)
- func StopProcessWithin(pidFile string, timeout time.Duration) (int, error)
- func WaitProcessTermination(pid int, timeout time.Duration) error
- type ProcessState
Constants ¶
const ( ProcessRunningCode = iota ProcessStoppedCode ProcessDeadCode )
const TerminationTimeout = 35 * time.Second
TerminationTimeout is how long StopProcess and QuitProcess wait for the process to exit. A watchdog they stop kills its child 30 seconds after the stop signal and then reaps it and cleans up, so they wait longer than that.
Variables ¶
var ( ProcStateRunning = ProcessState{ Code: ProcessRunningCode, Status: "RUNNING", PID: 0, // contains filtered or unexported fields } ProcStateStopped = ProcessState{ Code: ProcessStoppedCode, Status: "NOT RUNNING", PID: 0, // contains filtered or unexported fields } ProcStateDead = ProcessState{ Code: ProcessDeadCode, Status: "ERROR. The process is dead", PID: 0, // contains filtered or unexported fields } )
Functions ¶
func CheckPIDFile ¶
CheckPIDFile reports an error for a PID file that names a live process, or that cannot be read; a missing file, or one naming a dead process, is no error. It never removes a stale file: CreatePIDFile takes one over under the lock.
func CreatePIDFile ¶
CreatePIDFile takes the PID file over for pid and writes pid into it, as pidfile.Acquire does. The caller owns the file until it releases it, or keeps it when it exits while pid goes on.
func ExistsAndRecord ¶
ExistsAndRecord checks if the process with the given pidFileName exists and is alive. If it does, returns true, otherwise returns false. If something went wrong while trying to read the PID file, returns an error.
func GetPIDFromFile ¶
GetPIDFromFile returns PID from the PIDFile.
func Interrupt ¶
Interrupt sends SIGINT to the process pid without waiting for it to exit. The caller tells that pid is the process it means: a pid read from a pid file may name another process by now.
func InterruptProcess ¶
InterruptProcess sends SIGINT to the process by pidFile without waiting for it to exit.
func IsProcessAlive ¶
IsProcessAlive checks if the process is alive.
func KillProcessGroup ¶
KillProcessGroup kills the process group of the process pid with SIGKILL. The caller tells that pid is the process it means, as for Interrupt.
func QuitProcess ¶
QuitProcess sends SIGQUIT to the process pid and waits TerminationTimeout for it to exit. The caller tells that pid is the process it means, as for Interrupt.
func StopProcess ¶
StopProcess stops the process by pidFile, waiting TerminationTimeout for it to exit.
func StopProcessWithin ¶
StopProcessWithin sends SIGINT to the process by pidFile and waits up to timeout for it to exit.
Types ¶
type ProcessState ¶
type ProcessState struct {
Code int
Status string
PID int
// contains filtered or unexported fields
}
func ProcessStatus ¶
func ProcessStatus(pidFile string) ProcessState
ProcessStatus returns the status of the process.
func (ProcessState) FormattedStatus ¶
func (procState ProcessState) FormattedStatus() string
FormattedStatus returns the status string formatted with the appropriate color.
func (ProcessState) String ¶
func (procState ProcessState) String() string
String makes a string from ProcessState.