UniSet @VERSION@
ProcessInfo.h
1/*
2 * Copyright (c) 2026 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 */
8// -------------------------------------------------------------------------
9#ifndef ProcessInfo_H_
10#define ProcessInfo_H_
11// -------------------------------------------------------------------------
12#include <string>
13#include <vector>
14#include <set>
15#include <map>
16#include <chrono>
17#include <atomic>
18#include <Poco/Process.h>
19// -------------------------------------------------------------------------
20namespace uniset
21{
22 // Process states
23 enum class ProcessState
24 {
25 Stopped, // Not started
26 Starting, // Starting (waiting for readyCheck)
27 Running, // Running normally
28 Completed, // Oneshot process completed successfully
29 Failed, // Crashed/exited unexpectedly
30 Stopping, // Shutting down
31 Restarting // Being restarted (waiting for delay)
32 };
33
34 std::string to_string(ProcessState state);
35
36 // Ready check types
37 enum class ReadyCheckType
38 {
39 None, // No check (immediately ready)
40 TCP, // TCP port is available
41 CORBA, // CORBA object is registered
42 HTTP, // HTTP endpoint returns 200
43 File // File exists
44 };
45
46 std::string to_string(ReadyCheckType type);
47 ReadyCheckType readyCheckTypeFromString(const std::string& s);
48
49 // Ready check configuration
51 {
52 ReadyCheckType type = ReadyCheckType::None;
53 std::string target; // e.g. "2809", "SharedMemory", "http://localhost:8080/health"
54 size_t timeout_msec = 10000; // Total timeout for waitForReady
55 size_t pause_msec = 1000; // Pause between checks (default 1 sec)
56 size_t checkTimeout_msec = 1000; // Timeout for single check (health monitoring)
57
58 bool empty() const
59 {
60 return type == ReadyCheckType::None;
61 }
62 };
63
64 // Process configuration and runtime state
66 {
67 // Configuration (from XML)
68 std::string name;
69 std::string type;
70 std::string command;
71 std::vector<std::string> args; // Normal args (commonArgs + args)
72 std::vector<std::string> rawArgs; // Standalone args (no commonArgs)
73 std::string workDir;
74 std::map<std::string, std::string> env; // Additional environment variables
75
76 ReadyCheck readyCheck;
77
78 // Liveness check (watchdog): if fails healthFailThreshold times - restart process
79 ReadyCheck healthCheck;
80 int healthFailThreshold = 3; // Number of consecutive failures before restart (0 = disabled)
81 int healthFailCount = 0; // Runtime: current consecutive failure count
82
83 // Command to run after process is ready (e.g. "uniset2-admin --create")
84 std::string afterRun;
85 bool critical = true; // If true and exhausted maxRestarts - stop launcher. If false (ignoreFail=true) - just leave Failed
86 int maxRestarts = 0; // -1 = no restart, 0 = infinite restarts, >0 = limited
87 size_t restartDelay_msec = 1000; // Initial delay before restart
88 size_t maxRestartDelay_msec = 30000; // Max delay (exponential backoff cap)
89
90 std::set<std::string> nodeFilter; // Which nodes to run on (empty = all)
91 std::string group; // Process group name
92 bool skip = false; // Skip this process (don't start)
93 bool manual = false; // Manual start only (via REST API)
94 bool oneshot = false; // Oneshot process (exit 0 = success)
95 size_t oneshotTimeout_msec = 30000; // Timeout for oneshot process
96
97 // Runtime state
98 ProcessState state = ProcessState::Stopped;
99 Poco::Process::PID pid = 0;
100 int restartCount = 0;
101 int lastExitCode = 0;
102 std::chrono::steady_clock::time_point lastStartTime;
103 std::chrono::steady_clock::time_point lastFailTime;
104 std::string lastError;
105
106 // Helper methods
107 bool shouldRunOnNode(const std::string& nodeName) const;
108 void reset();
109 };
110
111 // Process group for ordered startup
113 {
114 std::string name;
115 int order = 0;
116 std::set<std::string> depends; // Groups this group depends on
117 std::vector<std::string> processes; // Process names in this group
118 };
119
120} // end of namespace uniset
121// -------------------------------------------------------------------------
122#endif // ProcessInfo_H_
123// -------------------------------------------------------------------------
Definition AccessConfig.h:30
Definition ProcessInfo.h:113
Definition ProcessInfo.h:66
std::string type
Process type (for template lookup, e.g. "SharedMemory")
Definition ProcessInfo.h:69
Definition ProcessInfo.h:51