daemon

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartTestWorkerMsg = "Test worker started"
	StopTestWorkerMsg  = "Test worker stopped"
)
View Source
const (
	TestProcessLogPath = "test_process.log"
	TestProcessPidFile = "test_process.pid"
)
View Source
const (
	EnvName = "TT_CLI_DAEMON"
)

Variables

This section is empty.

Functions

func IsDaemonAlive

func IsDaemonAlive(pid int) (bool, error)

IsDaemonAlive checks is daemon alive by process pid.

func RunHTTPServerOnBackground

func RunHTTPServerOnBackground(daemonCtx *DaemonCtx) error

RunHTTPServerOnBackground starts http daemon process.

func StopDaemon

func StopDaemon(daemonCtx *DaemonCtx) error

StopDaemon starts http daemon process.

Types

type DaemonCtx

type DaemonCtx struct {
	// Port is a port number to be used for daemon http server.
	Port int
	// PIDFile is a path of a file contains pid of daemon process.
	PIDFile string
	// LogPath is a path to a file contains log of daemon process.
	LogPath string
	// LogMaxSize is the maximum size in megabytes of the log file
	// before it gets rotated. It defaults to 100 megabytes.
	LogMaxSize int
	// LogMaxBackups is the maximum number of old log files to retain.
	// The default is to retain all old log files (though LogMaxAge may
	// still cause them to get deleted).
	LogMaxBackups int
	// LogMaxAge is the maximum number of days to retain old log files
	// based on the timestamp encoded in their filename. Note that a
	// day is defined as 24 hours and may not exactly correspond to
	// calendar days due to daylight savings, leap seconds, etc. The
	// default is not to remove old log files based on age.
	LogMaxAge int
	// ListenInterface is a network interface the IP address
	// should be found on to bind http server socket.
	ListenInterface string
}

DaemonCtx contains information for running an daemon instance.

func NewDaemonCtx

func NewDaemonCtx(opts *config.DaemonOpts) *DaemonCtx

NewDaemonCtx creates the DaemonCtx context.

type HTTPServer

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

HTTPServer contains information for http server.

func NewHTTPServer

func NewHTTPServer(listenInterface string, port int) *HTTPServer

NewHTTPServer creates new HTTPServer.

func (*HTTPServer) SetLogger

func (httpServer *HTTPServer) SetLogger(logger *ttlog.Logger)

SetLogger sets a log file the HTTP server will write to.

func (*HTTPServer) Start

func (httpServer *HTTPServer) Start(ttPath string)

Start starts HTTP server.

func (*HTTPServer) Stop

func (httpServer *HTTPServer) Stop() error

Stop stops HTTP server.

func (*HTTPServer) Timeout

func (httpServer *HTTPServer) Timeout(timeout time.Duration) *HTTPServer

Timeout sets the time that was provided to the HTTP server to shutdown correctly.

type Process

type Process struct {

	// DaemonTag is an env name to check the process is a child process.
	DaemonTag string
	// contains filtered or unexported fields
}

Process describes a running process.

func NewProcess

func NewProcess(worker Worker, pidFileName string, logOpts ttlog.LoggerOpts) *Process

NewProcess creates new Process.

func (*Process) CmdArgs

func (process *Process) CmdArgs(cmdArgs []string) *Process

CmdArgs sets arguments to the command the process should perform.

func (*Process) CmdPath

func (process *Process) CmdPath(cmdPath string) *Process

CmdPath sets a path to the command the process should perform.

func (*Process) IsChild

func (process *Process) IsChild() bool

IsChild checks a process is the child process.

func (*Process) Start

func (process *Process) Start() error

Start starts the process.

func (*Process) Stop

func (process *Process) Stop()

Stop stops the process.

type Worker

type Worker interface {
	Start(ttPath string)
	Stop() error
	SetLogger(logger *ttlog.Logger)
}

Worker describes an interface of a worker the process will manage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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