#165 调整TFE进程的启动方式,使用notify方式启动;
* 调整notify超时时间为300秒; * 调整日志的记录方式,当使用notify方式启动时,初始化完毕后不在向标准输出写入日志。
This commit is contained in:
@@ -31,7 +31,7 @@ env | sort
|
|||||||
: "${COMPILER_IS_GNUCXX:=OFF}"
|
: "${COMPILER_IS_GNUCXX:=OFF}"
|
||||||
|
|
||||||
# Install dependency from YUM
|
# Install dependency from YUM
|
||||||
yum install -y mrzcpd framework numactl-devel zlib-devel librdkafka-devel
|
yum install -y mrzcpd framework numactl-devel zlib-devel librdkafka-devel systemd-devel
|
||||||
mkdir build || true
|
mkdir build || true
|
||||||
cd build
|
cd build
|
||||||
|
|
||||||
|
|||||||
39
cmake/FindSYSTEMD.cmake
Normal file
39
cmake/FindSYSTEMD.cmake
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# - Find SystemdDaemon
|
||||||
|
# Find the systemd daemon library
|
||||||
|
#
|
||||||
|
# This module defines the following variables:
|
||||||
|
# SYSTEMD_FOUND - True if library and include directory are found
|
||||||
|
# If set to TRUE, the following are also defined:
|
||||||
|
# SYSTEMD_INCLUDE_DIRS - The directory where to find the header file
|
||||||
|
# SYSTEMD_LIBRARIES - Where to find the library file
|
||||||
|
#
|
||||||
|
# For conveniance, these variables are also set. They have the same values
|
||||||
|
# than the variables above. The user can thus choose his/her prefered way
|
||||||
|
# to write them.
|
||||||
|
# SYSTEMD_LIBRARY
|
||||||
|
# SYSTEMD_INCLUDE_DIR
|
||||||
|
#
|
||||||
|
# This file is in the public domain
|
||||||
|
|
||||||
|
include(FindPkgConfig)
|
||||||
|
pkg_check_modules(SYSTEMD libsystemd)
|
||||||
|
|
||||||
|
if(NOT SYSTEMD_FOUND)
|
||||||
|
find_path(SYSTEMD_INCLUDE_DIRS NAMES systemd/sd-daemon.h
|
||||||
|
DOC "The Systemd include directory")
|
||||||
|
|
||||||
|
find_library(SYSTEMD_LIBRARIES NAMES systemd
|
||||||
|
DOC "The Systemd library")
|
||||||
|
|
||||||
|
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
|
||||||
|
# set SYSTEMD_FOUND to TRUE if these two variables are set.
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(SYSTEMD REQUIRED_VARS SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS)
|
||||||
|
|
||||||
|
if(SYSTEMD_FOUND)
|
||||||
|
set(SYSTEMD_LIBRARY ${SYSTEMD_LIBRARIES})
|
||||||
|
set(SYSTEMD_INCLUDE_DIR ${SYSTEMD_INCLUDE_DIRS})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
mark_as_advanced(SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES)
|
||||||
@@ -33,12 +33,14 @@
|
|||||||
#define UNUSED __attribute__((unused))
|
#define UNUSED __attribute__((unused))
|
||||||
|
|
||||||
extern void * g_default_logger;
|
extern void * g_default_logger;
|
||||||
|
extern bool g_print_to_stderr;
|
||||||
|
|
||||||
#define TFE_LOG_ERROR(handler, fmt, ...) \
|
#define TFE_LOG_ERROR(handler, fmt, ...) \
|
||||||
do { fprintf(stderr, fmt "\n" , ##__VA_ARGS__); \
|
do { if(g_print_to_stderr) fprintf(stderr, fmt "\n" , ##__VA_ARGS__); \
|
||||||
MESA_handle_runtime_log(handler, RLOG_LV_FATAL, __FUNCTION__, fmt, ##__VA_ARGS__); } while(0)
|
MESA_handle_runtime_log(handler, RLOG_LV_FATAL, __FUNCTION__, fmt, ##__VA_ARGS__); } while(0)
|
||||||
|
|
||||||
#define TFE_LOG_INFO(handler, fmt, ...) \
|
#define TFE_LOG_INFO(handler, fmt, ...) \
|
||||||
do { fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
|
do { if(g_print_to_stderr) fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
|
||||||
MESA_handle_runtime_log(handler, RLOG_LV_INFO, __FUNCTION__, fmt, ##__VA_ARGS__); } while(0) \
|
MESA_handle_runtime_log(handler, RLOG_LV_INFO, __FUNCTION__, fmt, ##__VA_ARGS__); } while(0) \
|
||||||
|
|
||||||
#define TFE_LOG_DEBUG(handler, fmt, ...) \
|
#define TFE_LOG_DEBUG(handler, fmt, ...) \
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
find_package(SYSTEMD REQUIRED)
|
||||||
|
|
||||||
add_executable(tfe src/acceptor_kni_v1.cpp src/acceptor_kni_v2.cpp src/ssl_stream.cpp src/key_keeper.cpp
|
add_executable(tfe src/acceptor_kni_v1.cpp src/acceptor_kni_v2.cpp src/ssl_stream.cpp src/key_keeper.cpp
|
||||||
src/ssl_sess_cache.cpp src/ssl_sess_ticket.cpp src/ssl_service_cache.cpp
|
src/ssl_sess_cache.cpp src/ssl_sess_ticket.cpp src/ssl_service_cache.cpp
|
||||||
src/ssl_trusted_cert_storage.cpp src/ev_root_ca_metadata.cpp src/ssl_utils.cpp
|
src/ssl_trusted_cert_storage.cpp src/ev_root_ca_metadata.cpp src/ssl_utils.cpp
|
||||||
@@ -5,6 +7,7 @@ add_executable(tfe src/acceptor_kni_v1.cpp src/acceptor_kni_v2.cpp src/ssl_strea
|
|||||||
|
|
||||||
target_include_directories(tfe PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/external)
|
target_include_directories(tfe PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/external)
|
||||||
target_include_directories(tfe PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include/internal)
|
target_include_directories(tfe PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include/internal)
|
||||||
|
target_include_directories(tfe PRIVATE ${SYSTEMD_INCLUDE_DIRS})
|
||||||
|
|
||||||
target_link_libraries(tfe common tango-cache-client)
|
target_link_libraries(tfe common tango-cache-client)
|
||||||
target_link_libraries(tfe pthread dl
|
target_link_libraries(tfe pthread dl
|
||||||
@@ -21,7 +24,8 @@ target_link_libraries(tfe pthread dl
|
|||||||
MESA_htable wiredcfg
|
MESA_htable wiredcfg
|
||||||
MESA_field_stat
|
MESA_field_stat
|
||||||
gperftools-static
|
gperftools-static
|
||||||
breakpad-client-static)
|
breakpad-client-static
|
||||||
|
${SYSTEMD_LIBRARIES})
|
||||||
|
|
||||||
if(ENABLE_PLUGIN_HTTP)
|
if(ENABLE_PLUGIN_HTTP)
|
||||||
target_link_libraries(tfe -Wl,--whole-archive http -Wl,--no-whole-archive)
|
target_link_libraries(tfe -Wl,--whole-archive http -Wl,--no-whole-archive)
|
||||||
@@ -84,27 +88,23 @@ install(TARGETS tfe RUNTIME DESTINATION bin COMPONENT Program)
|
|||||||
# MESA_field_stat)
|
# MESA_field_stat)
|
||||||
#
|
#
|
||||||
#### test_chello_parse
|
#### test_chello_parse
|
||||||
add_executable(test_chello_parse test/test_chello_parse.cpp src/ssl_utils.cpp)
|
#add_executable(test_chello_parse test/test_chello_parse.cpp src/ssl_utils.cpp)
|
||||||
|
#target_include_directories(test_chello_parse PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include/internal)
|
||||||
|
#target_link_libraries(test_chello_parse common)
|
||||||
|
#target_link_libraries(test_chello_parse pthread dl
|
||||||
|
# openssl-ssl-static
|
||||||
|
# openssl-crypto-static
|
||||||
|
# pthread libevent-static
|
||||||
|
# libevent-static-openssl
|
||||||
|
# libevent-static-pthreads
|
||||||
|
# MESA_handle_logger
|
||||||
|
# MESA_prof_load
|
||||||
|
# MESA_htable wiredcfg
|
||||||
|
# cjson
|
||||||
|
# MESA_field_stat)
|
||||||
|
|
||||||
target_include_directories(test_chello_parse PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include/internal)
|
##### test_sender_scm
|
||||||
|
#add_executable(test_sender_scm src/sender_scm.cpp test/test_sender_scm.cpp)
|
||||||
target_link_libraries(test_chello_parse common)
|
#target_include_directories(test_sender_scm PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include/internal)
|
||||||
target_link_libraries(test_chello_parse pthread dl
|
#target_link_libraries(test_sender_scm common)
|
||||||
openssl-ssl-static
|
#target_link_libraries(test_sender_scm pthread dl MESA_prof_load MESA_handle_logger)
|
||||||
openssl-crypto-static
|
|
||||||
pthread libevent-static
|
|
||||||
libevent-static-openssl
|
|
||||||
libevent-static-pthreads
|
|
||||||
MESA_handle_logger
|
|
||||||
MESA_prof_load
|
|
||||||
MESA_htable wiredcfg
|
|
||||||
cjson
|
|
||||||
MESA_field_stat)
|
|
||||||
|
|
||||||
#### test_sender_scm
|
|
||||||
add_executable(test_sender_scm src/sender_scm.cpp test/test_sender_scm.cpp)
|
|
||||||
|
|
||||||
target_include_directories(test_sender_scm PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include/internal)
|
|
||||||
|
|
||||||
target_link_libraries(test_sender_scm common)
|
|
||||||
target_link_libraries(test_sender_scm pthread dl MESA_prof_load MESA_handle_logger)
|
|
||||||
|
|||||||
@@ -45,10 +45,13 @@
|
|||||||
#include <acceptor_kni_v2.h>
|
#include <acceptor_kni_v2.h>
|
||||||
#include <watchdog_kni.h>
|
#include <watchdog_kni.h>
|
||||||
#include <key_keeper.h>
|
#include <key_keeper.h>
|
||||||
|
|
||||||
/* Breakpad */
|
/* Breakpad */
|
||||||
#include <client/linux/handler/exception_handler.h>
|
#include <client/linux/handler/exception_handler.h>
|
||||||
#include <common/linux/http_upload.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 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);
|
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 */
|
/* Global Resource */
|
||||||
void * g_default_logger = NULL;
|
void * g_default_logger = NULL;
|
||||||
struct tfe_proxy * g_default_proxy = NULL;
|
struct tfe_proxy * g_default_proxy = NULL;
|
||||||
|
bool g_print_to_stderr = true;
|
||||||
|
|
||||||
/* Per thread resource */
|
/* Per thread resource */
|
||||||
thread_local unsigned int __currect_thread_id = 0;
|
thread_local unsigned int __currect_thread_id = 0;
|
||||||
thread_local void * __currect_default_logger = NULL;
|
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);
|
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)
|
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);
|
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 */
|
/* adds locking, only required if accessed from separate threads */
|
||||||
evthread_use_pthreads();
|
evthread_use_pthreads();
|
||||||
unsigned int __log_level = RLOG_LV_INFO;
|
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);
|
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.");
|
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);
|
event_base_dispatch(g_default_proxy->evbase);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ unsigned int monkey_gz_len = 407;
|
|||||||
unsigned int monkey_len = 843;
|
unsigned int monkey_len = 843;
|
||||||
unsigned int __64x_len = 64;
|
unsigned int __64x_len = 64;
|
||||||
unsigned int __64x_gz_len = 28;
|
unsigned int __64x_gz_len = 28;
|
||||||
|
bool g_print_to_stderr = true;
|
||||||
|
|
||||||
struct callback_ctx
|
struct callback_ctx
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <http_half.h>
|
#include <http_half.h>
|
||||||
|
|
||||||
|
bool g_print_to_stderr = true;
|
||||||
|
|
||||||
static const char * __identify_http_request =
|
static const char * __identify_http_request =
|
||||||
"POST /gen_204 HTTP/1.1\r\n"
|
"POST /gen_204 HTTP/1.1\r\n"
|
||||||
"Host: www.google.com\r\n"
|
"Host: www.google.com\r\n"
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include <nghttp2/nghttp2.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
|
|
||||||
#include "test_http2_stream.h"
|
#include "test_http2_stream.h"
|
||||||
|
bool g_print_to_stderr = true;
|
||||||
|
|
||||||
/********* stub function ******************************/
|
/********* stub function ******************************/
|
||||||
const char * tfe_version()
|
const char * tfe_version()
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ Requires=tfe-env.service
|
|||||||
After=tfe-env.service
|
After=tfe-env.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=notify
|
||||||
ExecStart=/opt/tsg/tfe/bin/tfe
|
ExecStart=/opt/tsg/tfe/bin/tfe
|
||||||
WorkingDirectory=/opt/tsg/tfe/
|
WorkingDirectory=/opt/tsg/tfe/
|
||||||
TimeoutSec=180s
|
TimeoutSec=300s
|
||||||
RestartSec=10s
|
RestartSec=10s
|
||||||
Restart=always
|
Restart=always
|
||||||
LimitNOFILE=524288
|
LimitNOFILE=524288
|
||||||
|
|||||||
Reference in New Issue
Block a user