Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.