master

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecodableMaster

type DecodableMaster struct {
	SysFolder string
	PidFile   string
	OutFile   string
	ErrFile   string

	Watcher *watcher.Watcher

	Procs map[string]*process.Proc
}

DecodableMaster is a struct that the config toml file will decode to. It is needed because toml decoder doesn't decode to interfaces, so the Procs map can't be decoded as long as we use the ProcContainer interface

type GoBin

type GoBin struct {
	SourcePath string   // SourcePath is the package path. (Ex: github.com/eafun/apm)
	Name       string   // Name is the process name that will be given to the process.
	KeepAlive  bool     // KeepAlive will determine whether APM should keep the proc live or not.
	Args       []string // Args is an array containing all the extra args that will be passed to the binary after compilation.
}

GoBin is a struct that represents the necessary arguments for a go binary to be built.

type Master

type Master struct {
	sync.Mutex

	SysFolder string           // SysFolder is the main APM folder where the necessary config files will be stored.
	PidFile   string           // PidFille is the APM pid file path.
	OutFile   string           // OutFile is the APM output log file path.
	ErrFile   string           // ErrFile is the APM err log file path.
	Watcher   *watcher.Watcher // Watcher is a watcher instance.

	Procs map[string]process.ProcContainer // Procs is a map containing all procs started on APM.
}

Master is the main module that keeps everything in place and execute the necessary actions to keep the process running as they should be.

func InitMaster

func InitMaster(configFile string) *Master

InitMaster will start a master instance with configFile. It returns a Master instance.

func (*Master) DeleteProcess

func (master *Master) DeleteProcess(name string) error

DeleteProcess will delete a process and all its files and childs forever.

func (*Master) ListProcs

func (master *Master) ListProcs() []process.ProcContainer

ListProcs will return a list of all procs.

func (*Master) Prepare

func (master *Master) Prepare(sourcePath string, name string, language string, keepAlive bool, args []string) (preparable.ProcPreparable, []byte, error)

Prepare will compile the source code into a binary and return a preparable ready to be executed.

func (*Master) RestartProcess

func (master *Master) RestartProcess(name string) error

RestartProcess will restart a process.

func (*Master) Revive

func (master *Master) Revive() error

Revive will revive all procs listed on ListProcs. This should ONLY be called during Master startup.

func (*Master) RunPreparable

func (master *Master) RunPreparable(procPreparable preparable.ProcPreparable) error

RunPreparable will run procPreparable and add it to the watch list in case everything goes well.

func (*Master) SaveProcs

func (master *Master) SaveProcs() error

SaveProcs will save a list of procs onto a file inside configPath. Returns an error in case there's any.

func (*Master) SaveProcsLoop

func (master *Master) SaveProcsLoop()

SaveProcsLoop will loop forever to save the list of procs onto the proc file.

func (*Master) StartProcess

func (master *Master) StartProcess(name string) error

StartProcess will a start a process.

func (*Master) Stop

func (master *Master) Stop() error

Stop will stop APM and all of its running procs.

func (*Master) StopProcess

func (master *Master) StopProcess(name string) error

StopProcess will stop a process with the given name.

func (*Master) UpdateStatus

func (master *Master) UpdateStatus()

UpdateStatus will update a process status every 30s.

func (*Master) WatchProcs

func (master *Master) WatchProcs()

WatchProcs will keep the procs running forever.

type ProcDataResponse

type ProcDataResponse struct {
	Name      string
	Pid       int
	Status    *process.ProcStatus
	KeepAlive bool
}

type ProcResponse

type ProcResponse struct {
	Procs []*ProcDataResponse
}

type RemoteClient

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

RemoteClient is a struct that holds the remote client instance.

func StartRemoteClient

func StartRemoteClient(dsn string, timeout time.Duration) (*RemoteClient, error)

StartRemoteClient will start a remote client that can talk to a remote server that is already running on dsn address. It returns an error in case there's any or it could not connect within the timeout.

func (*RemoteClient) DeleteProcess

func (client *RemoteClient) DeleteProcess(procName string) error

DeleteProcess is a wrapper that calls the remote DeleteProcess. It returns an error in case there's any.

func (*RemoteClient) MonitStatus

func (client *RemoteClient) MonitStatus() (ProcResponse, error)

MonitStatus is a wrapper that calls the remote MonitStatus. It returns a tuple with a list of process and an error in case there's any.

func (*RemoteClient) RestartProcess

func (client *RemoteClient) RestartProcess(procName string) error

RestartProcess is a wrapper that calls the remote RestartProcess. It returns an error in case there's any.

func (*RemoteClient) Resurrect

func (client *RemoteClient) Resurrect() error

Resurrect will restore all previously save processes. Returns an error in case there's any.

func (*RemoteClient) Save

func (client *RemoteClient) Save() error

Save will save a list of procs onto a file. Returns an error in case there's any.

func (*RemoteClient) StartGoBin

func (client *RemoteClient) StartGoBin(sourcePath string, name string, keepAlive bool, args []string) error

StartGoBin is a wrapper that calls the remote StartsGoBin. It returns an error in case there's any.

func (*RemoteClient) StartProcess

func (client *RemoteClient) StartProcess(procName string) error

StartProcess is a wrapper that calls the remote StartProcess. It returns an error in case there's any.

func (*RemoteClient) StopProcess

func (client *RemoteClient) StopProcess(procName string) error

StopProcess is a wrapper that calls the remote StopProcess. It returns an error in case there's any.

type RemoteMaster

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

RemoteMaster is a struct that holds the master instance.

func StartRemoteMasterServer

func StartRemoteMasterServer(dsn string, configFile string) *RemoteMaster

StartRemoteMasterServer starts a remote APM server listening on dsn address and binding to configFile. It returns a RemoteMaster instance.

func (*RemoteMaster) DeleteProcess

func (remote_master *RemoteMaster) DeleteProcess(procName string, ack *bool) error

DeleteProcess will delete a process with name procName. It returns an error in case there's any.

func (*RemoteMaster) MonitStatus

func (remote_master *RemoteMaster) MonitStatus(req string, response *ProcResponse) error

MonitStatus will query for the status of each process and bind it to procs pointer list. It returns an error in case there's any.

func (*RemoteMaster) RestartProcess

func (remote_master *RemoteMaster) RestartProcess(procName string, ack *bool) error

RestartProcess will restart a process that was previously built using GoBin. It returns an error in case there's any.

func (*RemoteMaster) Resurrect

func (remote_master *RemoteMaster) Resurrect(req string, ack *bool) error

Resurrect will restore all previously save processes. Returns an error in case there's any.

func (*RemoteMaster) Save

func (remote_master *RemoteMaster) Save(req string, ack *bool) error

Save will save the current running and stopped processes onto a file. Returns an error in case there's any.

func (*RemoteMaster) StartGoBin

func (remote_master *RemoteMaster) StartGoBin(goBin *GoBin, ack *bool) error

StartGoBin will build a binary based on the arguments passed on goBin, then it will start the process and keep it alive if KeepAlive is set to true. It returns an error and binds true to ack pointer.

func (*RemoteMaster) StartProcess

func (remote_master *RemoteMaster) StartProcess(procName string, ack *bool) error

StartProcess will start a process that was previously built using GoBin. It returns an error in case there's any.

func (*RemoteMaster) Stop

func (remote_master *RemoteMaster) Stop() error

Stop will stop APM remote server. It returns an error in case there's any.

func (*RemoteMaster) StopProcess

func (remote_master *RemoteMaster) StopProcess(procName string, ack *bool) error

StopProcess will stop a process that is currently running. It returns an error in case there's any.

Jump to

Keyboard shortcuts

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