mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 20:08:21 +08:00
all master templates support handling SIGTERM signal.
This commit is contained in:
parent
8582d02d2e
commit
3d02c72328
@ -67,6 +67,7 @@ typedef struct ACL_MASTER_SERV {
|
||||
#define ACL_MASTER_FLAG_RELOADING (1<<3) /* the service is reloading */
|
||||
#define ACL_MASTER_FLAG_STOPPING (1<<4) /* the service is stopping */
|
||||
#define ACL_MASTER_FLAG_KILLED (1<<5) /* the service is killed */
|
||||
#define ACL_MASTER_FLAG_KILL_ONEXIT (1<<6) /* the service can be killed on exit */
|
||||
|
||||
#define ACL_MASTER_THROTTLED(f) ((f)->flags & ACL_MASTER_FLAG_THROTTLE)
|
||||
#define ACL_MASTER_STOPPING(f) ((f)->flags & ACL_MASTER_FLAG_STOPPING)
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include "master_pathname.h"
|
||||
#include "master.h"
|
||||
|
||||
#define STR acl_vstring_str
|
||||
#define EQ !strcasecmp
|
||||
#define STR acl_vstring_str
|
||||
#define STR_SAME !strcasecmp
|
||||
|
||||
static char *__services_path = NULL; /* dir name of config files */
|
||||
@ -103,8 +104,6 @@ static int get_bool_ent(ACL_XINETD_CFG_PARSER *xcp,
|
||||
{
|
||||
const char *value;
|
||||
|
||||
#define EQ !strcasecmp
|
||||
|
||||
value = acl_xinetd_cfg_get(xcp, name);
|
||||
if (value == 0) {
|
||||
if (def_val == NULL) {
|
||||
@ -501,6 +500,17 @@ static int service_transport(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
|
||||
return init_listeners(serv);
|
||||
}
|
||||
|
||||
static void service_control(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
|
||||
{
|
||||
const char* ptr = get_str_ent(xcp, ACL_VAR_MASETR_SERV_KILL, "off");
|
||||
if (ptr == NULL || *ptr == 0)
|
||||
serv->flags &=~ ACL_MASTER_FLAG_KILL_ONEXIT;
|
||||
else if (EQ(ptr, "on") || EQ(ptr, "true") || EQ(ptr, "1"))
|
||||
serv->flags |= ACL_MASTER_FLAG_KILL_ONEXIT;
|
||||
else
|
||||
serv->flags &=~ ACL_MASTER_FLAG_KILL_ONEXIT;
|
||||
}
|
||||
|
||||
static void service_wakeup_time(ACL_XINETD_CFG_PARSER *xcp,
|
||||
ACL_MASTER_SERV *serv)
|
||||
{
|
||||
@ -793,8 +803,11 @@ ACL_MASTER_SERV *acl_master_ent_load(const char *filepath)
|
||||
acl_master_ent_free(serv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
service_wakeup_time(xcp, serv);
|
||||
service_proc(xcp, serv);
|
||||
service_control(xcp, serv);
|
||||
|
||||
if (service_args(xcp, serv, filepath) < 0) {
|
||||
acl_master_ent_free(serv);
|
||||
return NULL;
|
||||
|
@ -133,6 +133,7 @@ extern char *acl_var_master_manage_addr;
|
||||
#define ACL_VAR_MASTER_SERV_REUSEPORT "master_reuseport"
|
||||
#define ACL_VAR_MASTER_SERV_FASTOPEN "master_fastopen"
|
||||
#define ACL_VAR_MASTER_SERV_NBLOCK "master_nonblock"
|
||||
#define ACL_VAR_MASETR_SERV_KILL "master_kill"
|
||||
|
||||
/**
|
||||
* master_params.c
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
/* Application-specific. */
|
||||
|
||||
#include "master_api.h"
|
||||
#include "master_params.h"
|
||||
#include "master.h"
|
||||
|
||||
@ -97,19 +98,28 @@ void acl_master_service_stop(ACL_MASTER_SERV *serv)
|
||||
|
||||
void acl_master_service_restart(ACL_MASTER_SERV *serv)
|
||||
{
|
||||
/* Undo some of the things that master_service_start() did. */
|
||||
acl_master_wakeup_cleanup(serv);
|
||||
acl_master_status_cleanup(serv);
|
||||
if ((serv->flags & ACL_MASTER_FLAG_KILL_ONEXIT) != 0) {
|
||||
char *path = acl_mystrdup(serv->conf);
|
||||
acl_master_kill(path);
|
||||
if (acl_master_start(path) == NULL)
|
||||
acl_msg_error("can't start service=%s", path);
|
||||
else
|
||||
acl_msg_info("start %s ok", path);
|
||||
acl_myfree(path);
|
||||
} else {
|
||||
/* Undo some of the things that master_service_start() did. */
|
||||
acl_master_wakeup_cleanup(serv);
|
||||
acl_master_status_cleanup(serv);
|
||||
|
||||
/* Now undo the undone. */
|
||||
acl_master_status_init(serv);
|
||||
/* Now undo the undone. */
|
||||
acl_master_status_init(serv);
|
||||
|
||||
/* set ACL_MASTER_FLAG_RELOADING flag */
|
||||
serv->flags |= ACL_MASTER_FLAG_RELOADING;
|
||||
/* set ACL_MASTER_FLAG_RELOADING flag */
|
||||
serv->flags |= ACL_MASTER_FLAG_RELOADING;
|
||||
|
||||
acl_master_avail_listen(serv);
|
||||
acl_master_avail_listen(serv);
|
||||
|
||||
/* ACL_MASTER_FLAG_RELOADING will be remove in acl_master_spawn */
|
||||
|
||||
acl_master_wakeup_init(serv);
|
||||
/* ACL_MASTER_FLAG_RELOADING will be remove in acl_master_spawn */
|
||||
acl_master_wakeup_init(serv);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
修改历史列表:
|
||||
|
||||
------------------------------------------------------------------------
|
||||
606) 2017.9.5
|
||||
606.1) feature: master 服务器模板支持收到 SIGTERM 信号后的后续处理过程
|
||||
|
||||
605) 2017.8.29
|
||||
605.1) feature: acl_mbox.c 中的 acl_mbox_read 函数读超时单位由秒级调整为毫秒级
|
||||
605.2) bugfix: acl_aqueue.c 中的 acl_aqueue_pop_timedwait 函数计算超时时间方式有误
|
||||
|
@ -182,6 +182,7 @@ ACL_API ACL_EVENT *acl_trigger_server_event(void);
|
||||
*/
|
||||
extern ACL_API int acl_var_server_gotsighup;
|
||||
ACL_API void acl_server_sighup_setup(void);
|
||||
ACL_API void acl_server_sigterm_setup(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ void acl_server_sighup_setup(void)
|
||||
#ifdef ACL_WINDOWS
|
||||
signal(1, server_sighup);
|
||||
#else
|
||||
const char *myname = "acl_server_sighup_setup";
|
||||
struct sigaction action;
|
||||
|
||||
sigemptyset(&action.sa_mask);
|
||||
@ -57,6 +56,41 @@ void acl_server_sighup_setup(void)
|
||||
|
||||
if (sigaction(SIGHUP, &action, (struct sigaction *) 0) < 0)
|
||||
acl_msg_fatal("%s: sigaction(%d): %s",
|
||||
myname, SIGHUP, strerror(errno));
|
||||
__FUNCTION__, SIGHUP, strerror(errno));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ACL_UNIX
|
||||
static void server_sigterm(int sig acl_unused)
|
||||
{
|
||||
int i = 0, max = 1024;
|
||||
|
||||
acl_msg_info("%s(%d), %s: got SIGTERM, close from %d to %d",
|
||||
__FILE__, __LINE__, __FUNCTION__, i, max);
|
||||
|
||||
for (; i < max; i++)
|
||||
close(i);
|
||||
acl_doze(100);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void acl_server_sigterm_setup(void)
|
||||
{
|
||||
#ifdef ACL_UNIX
|
||||
struct sigaction action;
|
||||
|
||||
sigemptyset(&action.sa_mask);
|
||||
action.sa_flags = 0;
|
||||
|
||||
#ifdef SA_RESTART
|
||||
action.sa_flags |= SA_RESTART;
|
||||
#endif
|
||||
action.sa_handler = server_sigterm;
|
||||
|
||||
if (sigaction(SIGTERM, &action, (struct sigaction *) 0) < 0)
|
||||
acl_msg_fatal("%s: sigaction(%d): %s",
|
||||
__FUNCTION__, SIGTERM, strerror(errno));
|
||||
#endif
|
||||
}
|
||||
|
@ -1256,6 +1256,7 @@ static void run_loop(const char *procname)
|
||||
*/
|
||||
|
||||
acl_server_sighup_setup();
|
||||
acl_server_sigterm_setup();
|
||||
|
||||
while (1) {
|
||||
if (acl_var_aio_max_threads == 0) /* single thread mode */
|
||||
|
@ -685,6 +685,7 @@ void acl_single_server_main(int argc, char **argv, ACL_SINGLE_SERVER_FN service,
|
||||
post_init(__service_ctx);
|
||||
|
||||
acl_server_sighup_setup();
|
||||
acl_server_sigterm_setup();
|
||||
|
||||
/* The event loop, at last. */
|
||||
while (acl_var_single_use_limit == 0 ||
|
||||
|
@ -1471,6 +1471,7 @@ void acl_threads_server_main(int argc, char * argv[],
|
||||
#endif
|
||||
|
||||
acl_server_sighup_setup();
|
||||
acl_server_sigterm_setup();
|
||||
|
||||
acl_msg_info("%s(%d), %s daemon started, log: %s",
|
||||
myname, __LINE__, argv[0], acl_var_threads_log_file);
|
||||
|
@ -688,6 +688,7 @@ void acl_trigger_server_main(int argc, char **argv, ACL_TRIGGER_SERVER_FN servic
|
||||
(ACL_WATCHDOG_FN) 0, (char *) 0);
|
||||
|
||||
acl_server_sighup_setup();
|
||||
acl_server_sigterm_setup();
|
||||
|
||||
/*
|
||||
* The event loop, at last.
|
||||
|
@ -859,6 +859,7 @@ void acl_udp_server_main(int argc, char **argv, ACL_UDP_SERVER_FN service, ...)
|
||||
|
||||
/* 设置 SIGHUP 信号 */
|
||||
acl_server_sighup_setup();
|
||||
acl_server_sigterm_setup();
|
||||
|
||||
acl_msg_info("%s -- %s: daemon started", argv[0], myname);
|
||||
|
||||
|
@ -36,8 +36,10 @@ static ACL_SOCKET inet_listen(const char *addr, const struct addrinfo *res,
|
||||
{
|
||||
ACL_SOCKET sock = acl_inet_bind(res, flag);
|
||||
|
||||
if (sock == ACL_SOCKET_INVALID)
|
||||
if (sock == ACL_SOCKET_INVALID) {
|
||||
acl_msg_error("bind addr=%s error=%s", addr, acl_last_serror());
|
||||
return ACL_SOCKET_INVALID;
|
||||
}
|
||||
|
||||
#if defined(TCP_FASTOPEN)
|
||||
if (flag & ACL_INET_FLAG_FASTOPEN) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
Summary: The powerful c/c++ library and server framework
|
||||
Name: acl-libs
|
||||
Version: 3.3.0
|
||||
Release: 9
|
||||
Release: 10
|
||||
Group: System/Libs
|
||||
License: IBM
|
||||
URL: http://cdnlog-web.qiyi.domain
|
||||
|
Loading…
Reference in New Issue
Block a user