process

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Handler *daemon.Handler = &daemon.Handler{
	Name: "process manager",
	Call: func() error {
		files, err := os.ReadDir(filepath.Join(config.PATH_SERVICES))
		if err != nil {
			return err
		}

		pm := NewProcessManager()
		for _, file := range files {
			if file.Name() != config.BUILD_APP_NAME {
				pm.CreateProcess(
					file.Name(),
					filepath.Join(config.PATH_SERVICES, file.Name()),
				)
			}
		}

		return nil
	},
}

Handler represents the process manager handler.

Functions

This section is empty.

Types

type Manager

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

func NewProcessManager

func NewProcessManager() *Manager

func (*Manager) CreateProcess

func (m *Manager) CreateProcess(name string, command string, args ...string) (*Process, error)

CreateProcess creates a new process with the given name, command, and arguments. It returns a pointer to the created Process and an error if any. If a process with the same name is already running or exists, an error is returned.

func (*Manager) DeleteProcess

func (m *Manager) DeleteProcess(name string) error

DeleteProcess deletes a process with the given name from the manager. It kills the process and removes it from the list of managed processes. If no process is found with the given name, it returns an error.

func (*Manager) GetProcess

func (m *Manager) GetProcess(name string) (*Process, bool)

GetProcess récupère le processus avec le nom spécifié. Il renvoie le processus et un booléen indiquant si le processus existe.

func (*Manager) ListProcesses

func (m *Manager) ListProcesses() map[string]*Process

ListProcesses returns a map of all processes managed by the Manager. The key of the map is the name of the process, and the value is a pointer to the Process struct.

type Process

type Process struct {
	Name string // Name is the name of the process.

	IsRunning bool      // IsRunning indicates whether the process is currently running.
	Proc      *exec.Cmd // Proc is the underlying exec.Cmd instance representing the process.
	// contains filtered or unexported fields
}

Process represents a process that can be started and managed.

func (*Process) Kill

func (p *Process) Kill() error

Kill terminates the process associated with the Process object. It first retrieves the process ID (PID) using the pidHandler. If the PID is not 0, it uses os.FindProcess to find the process. Then, it calls the Kill method on the process to terminate it. If an error occurs during the process termination or while clearing the PID file, it returns an error with a descriptive message. If the PID is 0, indicating that no process is associated with the Process object, it returns nil.

func (*Process) Restart

func (p *Process) Restart() error

Restart restarts the process. It stops the process, waits for 1 second, and then starts it again. If stopping the process or starting it again fails, an error is returned.

func (*Process) Start

func (p *Process) Start() error

Start starts the process. It returns an error if the process is already running or if it fails to start. The function starts the process in a separate goroutine and updates the IsRunning flag accordingly. If the process stops, it will be automatically restarted.

func (*Process) Stop

func (p *Process) Stop() error

Stop stops the process. It returns an error if the process is not running or if there was an error while stopping the process.

Jump to

Keyboard shortcuts

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