master

package
v0.0.0-...-130d745 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 13 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/topfreegames/pmgo)
	Name       string   // Name is the process name that will be given to the process.
	KeepAlive  bool     // KeepAlive will determine whether pmgo 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.
	BinFile    bool
}

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 pmgo folder where the necessary config files will be stored.
	PidFile   string           // PidFille is the pmgo pid file path.
	OutFile   string           // OutFile is the pmgo output log file path.
	ErrFile   string           // ErrFile is the pmgo 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 pmgo.
	// contains filtered or unexported fields
}

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) IsExistProc

func (master *Master) IsExistProc(procName string) (bool, error)

IsExistProc current proc whether exist

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, fromBin bool) (preparable.ProcPreparable, []byte, error)

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

func (*Master) ProcInfo

func (master *Master) ProcInfo(proName string) map[string]string

ProcInfo will return process detail info with map

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) 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 pmgo and save 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
}

ProcDataResponse is a struct than about proc attr

type ProcResponse

type ProcResponse struct {
	Procs []*ProcDataResponse
}

ProcResponse is procs attr array

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) GetProcByName

func (client RemoteClient) GetProcByName(procName string) *map[string]string

GetProcByName will return proc info by name

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) 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, binFile bool) 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 pmgo 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) GetProcByName

func (remote_master *RemoteMaster) GetProcByName(procName string, response *map[string]string) error

GetProcByName will return proc detail info by name

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) 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 pmgo 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