How claytonaalves/process-guardian works
Project Type and Purpose
• This is a lightweight command-line “Process Guardian” utility written in Free Pascal/Lazarus.
• Its sole responsibility is to read a simple INI-style config, launch one or more child processes under Windows, monitor them, and restart any that crash.
File Structure Analysis
• Top-level files only:
• Guardian.lpr / .lpi – the Pascal project and IDE project file
• UGuardian.pas – the core Pascal unit implementing the guardian logic
• README.md, LICENSE, .gitignore
• No separate “frontend” or “backend” directories—this is a single executable with no GUI.
README Insights
• Defines an INI format with sections per-process.
• Shows keys: command, params, working-dir, optional retries and check-network.
• Implies a loop: load config → spawn processes → detect exit → apply retry logic → restart.
a. Main Components
• Config Loader – parses the INI file into in-memory process definitions
• Supervisor Engine – core loop that starts, monitors, and restarts processes
• OS Interface – wraps Windows API calls for CreateProcess, WaitFor…
• (Optional) Network Checker – if “check-network=yes” enables a network-availability subroutine
• Logger – writes status to console or event log
• Child Processes – as defined in the config file
b. Relationships & Interactions
1. On startup, the Config Loader reads the INI file.
2. Supervisor Engine iterates over each process definition.
3. For each entry, Supervisor uses OS Interface to start the process.
4. Supervisor monitors the child’s exit code.
5. On crash/failure, applies retry policy, possibly invoking Network Checker first.
6. Logger records “started”, “stopped”, “restarting” events.
c. Architectural Patterns
• A single-process, event-driven loop (reactor pattern).
• Clear separation between config parsing, process control, and logging concerns.
d. Key Technologies
• Free Pascal / Lazarus runtime
• Windows API calls (CreateProcess, WaitForSingleObject, etc.)
• Simple INI parsing library (built into Free Pascal’s TIniFile)