9
9
10
10
The application ensures high reliability and availability by continuously monitoring and
11
11
restarting processes as necessary. It also logs various statistics about the monitored
12
- processes, including start times, crash times, and ping intervals.
12
+ processes, including start times, crash times, and heartbeat intervals.
13
13
14
14
@date 2023-01-01
15
15
@version 1.0
@@ -47,15 +47,15 @@ typedef struct
47
47
{
48
48
// In the ini file
49
49
int start_delay ; /**< Delay in seconds before starting the application. */
50
- int ping_delay ; /**< Time in seconds to wait before expecting a ping from the application. */
51
- int ping_interval ; /**< Maximum time period in seconds between pings . */
50
+ int heartbeat_delay ; /**< Time in seconds to wait before expecting a heartbeat from the application. */
51
+ int heartbeat_interval ; /**< Maximum time period in seconds between heartbeats . */
52
52
char name [MAX_APP_NAME_LENGTH ]; /**< Name of the application. */
53
53
char cmd [MAX_APP_CMD_LENGTH ]; /**< Command to start the application. */
54
54
// Not in the ini file
55
55
bool started ; /**< Flag indicating whether the application has been started. */
56
- bool first_ping ; /**< Flag indicating whether the application has sent its first ping . */
56
+ bool first_heartbeat ; /**< Flag indicating whether the application has sent its first heartbeat . */
57
57
int pid ; /**< Process ID of the application. */
58
- time_t last_ping ; /**< Time when the last ping was received from the application. */
58
+ time_t last_heartbeat ; /**< Time when the last heartbeat was received from the application. */
59
59
} Application_t ;
60
60
61
61
static Application_t apps [MAX_APPS ]; /**< Array of Application_t structures representing applications defined in the ini file. */
@@ -71,23 +71,23 @@ static int ini_index; /**< Index used to read an array in the ini file. */
71
71
void print_app (int i )
72
72
{
73
73
LOGN ("## Application info [%d]" , i );
74
- LOGN ("%d- name : %s" , i , apps [i ].name );
75
- LOGN ("%d- start_delay : %d" , i , apps [i ].start_delay );
76
- LOGN ("%d- ping_delay : %d" , i , apps [i ].ping_delay );
77
- LOGN ("%d- ping_interval : %d" , i , apps [i ].ping_interval );
78
- LOGN ("%d- cmd : %s" , i , apps [i ].cmd );
79
- LOGN ("%d- started : %d" , i , apps [i ].started );
80
- LOGN ("%d- first_ping : %d" , i , apps [i ].first_ping );
81
- LOGN ("%d- pid : %d" , i , apps [i ].pid );
82
- LOGN ("%d- last_ping : %d" , i , apps [i ].last_ping );
74
+ LOGN ("%d- name : %s" , i , apps [i ].name );
75
+ LOGN ("%d- start_delay : %d" , i , apps [i ].start_delay );
76
+ LOGN ("%d- heartbeat_delay : %d" , i , apps [i ].heartbeat_delay );
77
+ LOGN ("%d- heartbeat_interval : %d" , i , apps [i ].heartbeat_interval );
78
+ LOGN ("%d- cmd : %s" , i , apps [i ].cmd );
79
+ LOGN ("%d- started : %d" , i , apps [i ].started );
80
+ LOGN ("%d- first_heartbeat : %d" , i , apps [i ].first_heartbeat );
81
+ LOGN ("%d- pid : %d" , i , apps [i ].pid );
82
+ LOGN ("%d- last_heartbeat : %d" , i , apps [i ].last_heartbeat );
83
83
}
84
84
85
85
//------------------------------------------------------------------
86
86
87
- void update_ping_time (int i )
87
+ void update_heartbeat_time (int i )
88
88
{
89
- apps [i ].last_ping = time (NULL );
90
- LOGD ("Ping time updated for %s" , apps [i ].name );
89
+ apps [i ].last_heartbeat = time (NULL );
90
+ LOGD ("Heartbeat time updated for %s" , apps [i ].name );
91
91
}
92
92
93
93
int find_pid (int pid )
@@ -103,39 +103,39 @@ int find_pid(int pid)
103
103
return -1 ;
104
104
}
105
105
106
- time_t get_ping_time (int i )
106
+ time_t get_heartbeat_time (int i )
107
107
{
108
108
time_t t = time (NULL );
109
- return t - apps [i ].last_ping ;
109
+ return t - apps [i ].last_heartbeat ;
110
110
}
111
111
112
112
bool is_timeup (int i )
113
113
{
114
114
bool ret = false;
115
115
time_t t = time (NULL );
116
116
117
- if (t < apps [i ].last_ping )
117
+ if (t < apps [i ].last_heartbeat )
118
118
{
119
- update_ping_time (i );
119
+ update_heartbeat_time (i );
120
120
}
121
121
122
- if (t - apps [i ].last_ping >= (apps [i ].first_ping ? apps [i ].ping_interval : apps [i ].ping_delay ))
122
+ if (t - apps [i ].last_heartbeat >= (apps [i ].first_heartbeat ? apps [i ].heartbeat_interval : apps [i ].heartbeat_delay ))
123
123
{
124
124
ret = true;
125
- LOGD ("Ping time up for %s" , apps [i ].name );
125
+ LOGD ("Heartbeat time up for %s" , apps [i ].name );
126
126
}
127
127
128
128
return ret ;
129
129
}
130
130
131
- void set_first_ping (int i )
131
+ void set_first_heartbeat (int i )
132
132
{
133
- apps [i ].first_ping = true;
133
+ apps [i ].first_heartbeat = true;
134
134
}
135
135
136
- bool get_first_ping (int i )
136
+ bool get_first_heartbeat (int i )
137
137
{
138
- return apps [i ].first_ping ;
138
+ return apps [i ].first_heartbeat ;
139
139
}
140
140
141
141
//------------------------------------------------------------------
@@ -218,18 +218,18 @@ static int handler(void *user, const char *section, const char *name, const char
218
218
apps [ini_index ].start_delay = atoi (value );
219
219
}
220
220
221
- SECTION (ini_index , "ping_delay " );
221
+ SECTION (ini_index , "heartbeat_delay " );
222
222
223
223
if (MATCH (_section , b ))
224
224
{
225
- apps [ini_index ].ping_delay = atoi (value );
225
+ apps [ini_index ].heartbeat_delay = atoi (value );
226
226
}
227
227
228
- SECTION (ini_index , "ping_interval " );
228
+ SECTION (ini_index , "heartbeat_interval " );
229
229
230
230
if (MATCH (_section , b ))
231
231
{
232
- apps [ini_index ].ping_interval = atoi (value );
232
+ apps [ini_index ].heartbeat_interval = atoi (value );
233
233
}
234
234
235
235
SECTION (ini_index , "cmd" ); // this always must be the last one
@@ -332,10 +332,10 @@ void start_application(int i)
332
332
{
333
333
// Parent process
334
334
apps [i ].started = true;
335
- apps [i ].first_ping = false;
335
+ apps [i ].first_heartbeat = false;
336
336
apps [i ].pid = pid ;
337
337
LOGI ("Process %s started (PID %d): %s" , apps [i ].name , apps [i ].pid , apps [i ].cmd );
338
- update_ping_time (i );
338
+ update_heartbeat_time (i );
339
339
}
340
340
}
341
341
@@ -426,7 +426,7 @@ void kill_application(int i)
426
426
if (killed )
427
427
{
428
428
apps [i ].started = false;
429
- apps [i ].first_ping = false;
429
+ apps [i ].first_heartbeat = false;
430
430
apps [i ].pid = 0 ;
431
431
}
432
432
}
@@ -454,8 +454,8 @@ void restart_application(int i)
454
454
}
455
455
else
456
456
{
457
- // Update the last_ping time to prevent immediate restart
458
- update_ping_time (i );
457
+ // Update the last_heartbeat time to prevent immediate restart
458
+ update_heartbeat_time (i );
459
459
// Log that the application has been successfully restarted
460
460
LOGI ("Process %s restarted successfully" , apps [i ].name );
461
461
}
0 commit comments