mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-22 16:15:05 +08:00
Add support for systemd watchdog.
This is a reworked version of https://github.com/eclipse-mosquitto/mosquitto/pull/3158 by Gaël PORTAY.
This commit is contained in:
+2
-1
@@ -77,7 +77,8 @@ Broker:
|
||||
- Add suport for PROXY protocol v1 and v2.
|
||||
- Log message if a client attempts to connect with TLS to a non-TLS listener.
|
||||
- Add `listener_allow_anonymous` option.
|
||||
- Add `listener_auto_id_prefix` ` option.
|
||||
- Add `listener_auto_id_prefix` option.
|
||||
- Add support for systemd watchdog.
|
||||
|
||||
Plugins / plugin interface:
|
||||
- Add persist-sqlite plugin.
|
||||
|
||||
@@ -73,6 +73,7 @@ add_executable(mosquitto
|
||||
../lib/tls_mosq.c
|
||||
topic_tok.c
|
||||
../lib/util_mosq.c ../lib/util_mosq.h
|
||||
watchdog.c
|
||||
websockets.c
|
||||
will_delay.c
|
||||
../lib/will_mosq.c ../lib/will_mosq.h
|
||||
|
||||
@@ -109,6 +109,7 @@ OBJS= mosquitto.o \
|
||||
subs.o \
|
||||
sys_tree.o \
|
||||
topic_tok.o \
|
||||
watchdog.o \
|
||||
websockets.o \
|
||||
will_delay.o \
|
||||
xtreport.o
|
||||
|
||||
@@ -170,6 +170,7 @@ int mosquitto_main_loop(struct mosquitto__listener_sock *listensock, int listens
|
||||
int rc;
|
||||
|
||||
|
||||
watchdog__init();
|
||||
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS && LWS_LIBRARY_VERSION_NUMBER == 3002000
|
||||
memset(&sul, 0, sizeof(struct lws_sorted_usec_list));
|
||||
#endif
|
||||
@@ -194,6 +195,7 @@ int mosquitto_main_loop(struct mosquitto__listener_sock *listensock, int listens
|
||||
#endif
|
||||
|
||||
keepalive__check();
|
||||
watchdog__check();
|
||||
|
||||
#ifdef WITH_BRIDGE
|
||||
bridge_check();
|
||||
|
||||
@@ -949,6 +949,12 @@ void service_run(char *name);
|
||||
DWORD WINAPI SigThreadProc(void* data);
|
||||
#endif
|
||||
|
||||
/* ============================================================
|
||||
* Watchdog
|
||||
* ============================================================ */
|
||||
void watchdog__init(void);
|
||||
void watchdog__check(void);
|
||||
|
||||
/* ============================================================
|
||||
* Websockets related functions
|
||||
* ============================================================ */
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright (c) 2009-2020 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License 2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
Tatsuzo Osawa - Add epoll.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <time.h>
|
||||
#include "mosquitto.h"
|
||||
|
||||
#ifdef WITH_SYSTEMD
|
||||
# include <systemd/sd-daemon.h>
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SYSTEMD
|
||||
static time_t next_ping = 0;
|
||||
static time_t ping_sec = 0;
|
||||
#endif
|
||||
|
||||
void watchdog__init(void)
|
||||
{
|
||||
#ifdef WITH_SYSTEMD
|
||||
char *watchdog_usec = getenv("WATCHDOG_USEC");
|
||||
time_t next_ping = mosquitto_time();
|
||||
time_t ping_sec = 0;
|
||||
|
||||
if(watchdog_usec){
|
||||
char *endptr = NULL;
|
||||
long usec = strtol(watchdog_usec, &endptr, 10);
|
||||
if(watchdog_usec[0] != '\0' && endptr[0] == '\0' && usec > 0){
|
||||
ping_sec = (usec / 1000000) / 2;
|
||||
}
|
||||
next_ping = mosquito_time();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void watchdog__check(void)
|
||||
{
|
||||
#ifdef WITH_SYSTEMD
|
||||
if(ping_sec){
|
||||
time_t now = mosquitto_time();
|
||||
if(now > next_ping){
|
||||
sd_notify(0, "WATCHDOG=1");
|
||||
next_ping = now + ping_sec;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user