diff options
| author | luqiuwen <[email protected]> | 2019-09-23 16:10:53 +0800 |
|---|---|---|
| committer | luqiuwen <[email protected]> | 2019-09-23 16:10:53 +0800 |
| commit | cd0fd187ad184543febd704c66b91bb73f326d27 (patch) | |
| tree | 564036875740295eecce9de2da854be3a5be1ee6 /platform/src/proxy.cpp | |
| parent | 721820e37a476798ab05d96a80ed151eda72c7ba (diff) | |
#165 调整TFE进程的启动方式,使用notify方式启动;v4.1.4-20190923
* 调整notify超时时间为300秒;
* 调整日志的记录方式,当使用notify方式启动时,初始化完毕后不在向标准输出写入日志。
Diffstat (limited to 'platform/src/proxy.cpp')
| -rw-r--r-- | platform/src/proxy.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/platform/src/proxy.cpp b/platform/src/proxy.cpp index 2b99268..919426e 100644 --- a/platform/src/proxy.cpp +++ b/platform/src/proxy.cpp @@ -45,10 +45,13 @@ #include <acceptor_kni_v2.h> #include <watchdog_kni.h> #include <key_keeper.h> + /* Breakpad */ #include <client/linux/handler/exception_handler.h> #include <common/linux/http_upload.h> +/* Systemd */ +#include <systemd/sd-daemon.h> extern struct ssl_policy_enforcer* ssl_policy_enforcer_create(void* logger); extern enum ssl_stream_action ssl_policy_enforce(struct ssl_stream *upstream, void* u_para); @@ -58,6 +61,8 @@ static int signals[] = {SIGHUP, SIGPIPE, SIGUSR1}; /* Global Resource */ void * g_default_logger = NULL; struct tfe_proxy * g_default_proxy = NULL; +bool g_print_to_stderr = true; + /* Per thread resource */ thread_local unsigned int __currect_thread_id = 0; thread_local void * __currect_default_logger = NULL; @@ -109,6 +114,13 @@ void tfe_proxy_thread_ctx_release(struct tfe_thread_ctx * thread_ctx) ATOMIC_DEC(&thread_ctx->load); } +/* 检查本进程是否通过SYSTEMD启动 */ +static int check_is_started_by_notify() +{ + char * notify_socket = getenv("NOTIFY_SOCKET"); + return notify_socket == NULL ? 0 : 1; +} + int tfe_proxy_fds_accept(struct tfe_proxy * ctx, int fd_downstream, int fd_upstream, struct tfe_cmsg * cmsg) { struct tfe_thread_ctx * worker_thread_ctx = tfe_proxy_thread_ctx_acquire(ctx); @@ -618,6 +630,8 @@ int main(int argc, char * argv[]) } } + fprintf(stderr, "Tango Frontend Engine, Version: %s", __tfe_version); + /* adds locking, only required if accessed from separate threads */ evthread_use_pthreads(); unsigned int __log_level = RLOG_LV_INFO; @@ -713,7 +727,17 @@ int main(int argc, char * argv[]) g_default_proxy->watchdog_kni = watchdog_kni_create(g_default_proxy, main_profile, g_default_logger); CHECK_OR_EXIT(g_default_proxy->watchdog_kni != NULL, "Failed at creating KNI watchdog, Exit."); - TFE_LOG_ERROR(g_default_logger, "Tango Frontend Engine initialized. "); + TFE_LOG_ERROR(g_default_logger, "Tango Frontend Engine initialized, Version: %s.", __tfe_version); + + /* If TFE is run by systemd's notify, then tell the systemd our tfe is ready. + * and disable the stderr log, only print logs into files */ + if(check_is_started_by_notify()) + { + sd_notify(0, "READY=1"); + g_print_to_stderr = false; + sleep(1); + } + event_base_dispatch(g_default_proxy->evbase); return 0; } |
