mirror of
https://github.com/emqx/neuron.git
synced 2026-10-30 07:45:59 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb6e92665a | ||
|
|
d7929b5553 | ||
|
|
a11d622fa6 | ||
|
|
c3ed9cc69d | ||
|
|
54dfc3709e | ||
|
|
253f254bd3 | ||
|
|
214c82b508 | ||
|
|
fdfc819c25 | ||
|
|
2ba608f9fe | ||
|
|
89069da064 | ||
|
|
aec03ecaf9 | ||
|
|
40fdc17b57 | ||
|
|
dda1007c50 | ||
|
|
da4295aec9 | ||
|
|
cfb3d073c5 | ||
|
|
cc86ffd497 | ||
|
|
f32188e3c1 | ||
|
|
93af6bfe76 | ||
|
|
5c543e0077 | ||
|
|
f6c591e951 | ||
|
|
eb332bd745 | ||
|
|
d026d1f754 | ||
|
|
fd6c3aca96 | ||
|
|
faee3ab68c | ||
|
|
68587420e0 | ||
|
|
af5195cfb9 | ||
|
|
157dd2521a |
@@ -8,8 +8,8 @@ on:
|
||||
- published
|
||||
|
||||
env:
|
||||
VERSION: 2.3.6
|
||||
UI_VERSION: 2.3.5
|
||||
VERSION: 2.3.9
|
||||
UI_VERSION: 2.3.8
|
||||
BRANCH: v2.3
|
||||
|
||||
jobs:
|
||||
|
||||
+6
-6
@@ -59,6 +59,9 @@ else()
|
||||
link_directories(/usr/local/lib)
|
||||
endif()
|
||||
|
||||
set(PERSIST_SOURCES
|
||||
src/persist/persist.c
|
||||
src/persist/json/persist_json_plugin.c)
|
||||
aux_source_directory(src/parser NEURON_SRC_PARSE)
|
||||
set(NEURON_BASE_SOURCES
|
||||
src/base/tag.c
|
||||
@@ -74,7 +77,8 @@ set(NEURON_BASE_SOURCES
|
||||
src/utils/neu_jwt.c
|
||||
src/utils/base64.c
|
||||
src/utils/async_queue.c
|
||||
src/utils/mem_cache.c)
|
||||
src/utils/mem_cache.c
|
||||
${PERSIST_SOURCES})
|
||||
|
||||
add_library(neuron-base SHARED)
|
||||
target_sources(neuron-base PRIVATE ${NEURON_BASE_SOURCES} ${NEURON_SRC_PARSE})
|
||||
@@ -89,9 +93,6 @@ add_dependencies(neuron-base neuron-version)
|
||||
#find_package(MbedTLS)
|
||||
target_link_libraries(neuron-base mbedtls mbedx509 mbedcrypto)
|
||||
|
||||
set(PERSIST_SOURCES
|
||||
src/persist/persist.c
|
||||
src/persist/json/persist_json_plugin.c)
|
||||
set(NEURON_SOURCES
|
||||
src/main.c
|
||||
src/argparse.c
|
||||
@@ -123,8 +124,7 @@ set(NEURON_SOURCES
|
||||
plugins/restful/proxy.c
|
||||
plugins/restful/websocket.c
|
||||
plugins/monitor/monitor.c
|
||||
plugins/monitor/metric_handle.c
|
||||
${PERSIST_SOURCES})
|
||||
plugins/monitor/metric_handle.c)
|
||||
|
||||
set(CMAKE_BUILD_RPATH ./)
|
||||
add_executable(neuron)
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "adapter/adapter_info.h"
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "adapter_info.h"
|
||||
#include "persist/json/persist_json_plugin.h"
|
||||
|
||||
typedef neu_json_plugin_req_plugin_t neu_persist_plugin_info_t;
|
||||
@@ -84,12 +86,14 @@ static inline void neu_persist_user_info_fini(neu_persist_user_info_t *info)
|
||||
* Create persister.
|
||||
* @return 0 on success, -1 otherwise.
|
||||
*/
|
||||
int neu_persister_create();
|
||||
int neu_persister_create(const char *schema_dir);
|
||||
/**
|
||||
* Destroy perister.
|
||||
*/
|
||||
void neu_persister_destroy();
|
||||
|
||||
sqlite3 *neu_persister_get_db();
|
||||
|
||||
/**
|
||||
* Persist nodes.
|
||||
* @param node_info neu_persist_node_info_t.
|
||||
@@ -306,4 +310,4 @@ int neu_persister_delete_user(const char *user_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -50,25 +50,43 @@ static int http_resp_files(nng_aio *aio, void *data, size_t len,
|
||||
|
||||
void handle_logs_files(nng_aio *aio)
|
||||
{
|
||||
char path[128] = { 0 };
|
||||
char disp[128] = { 0 };
|
||||
void * data = NULL;
|
||||
size_t len = 0;
|
||||
int rv = 0;
|
||||
void * data = NULL;
|
||||
size_t len = 0;
|
||||
int rv = 0;
|
||||
|
||||
VALIDATE_JWT(aio);
|
||||
|
||||
rv = mkdir("neuron_logs", S_IRWXU);
|
||||
if (0 != rv && EEXIST == errno) {
|
||||
rv = 0;
|
||||
/* check whether the neuron directory exists */
|
||||
rv = access("../neuron", F_OK);
|
||||
if (0 != rv) {
|
||||
nlog_error("The neuron directory does not exists");
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_NOT_EXIST, {
|
||||
http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// check if coredump exists
|
||||
rv = access("./core", F_OK);
|
||||
if (0 == rv) {
|
||||
rv = system("cp -r ./core neuron_logs");
|
||||
if (0 != rv) {
|
||||
nlog_error("failed to copy coredump file");
|
||||
/* tar the neuron directory */
|
||||
rv = system("tar -zcvf /tmp/neuron_debug.tar.gz ../neuron");
|
||||
if (rv == -1) {
|
||||
nlog_error("failed to create neuron_debug.tar.gz, rv: %d", rv);
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
|
||||
http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
if (WIFEXITED(rv)) {
|
||||
if (WEXITSTATUS(rv) != 0) {
|
||||
nlog_error("failed to create neuron_debug.tar.gz, rv: %d",
|
||||
WEXITSTATUS(rv));
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
|
||||
http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
nlog_error("failed to create neuron_debug.tar.gz, rv: %d",
|
||||
WEXITSTATUS(rv));
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
|
||||
http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
@@ -76,48 +94,18 @@ void handle_logs_files(nng_aio *aio)
|
||||
}
|
||||
}
|
||||
|
||||
rv = system("cp -r ./logs neuron_logs");
|
||||
if (0 != rv) {
|
||||
nlog_error("failed to copy logs file");
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
|
||||
http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
rv = system("tar -zcvf neuron_logs.tar.gz neuron_logs");
|
||||
if (0 != rv) {
|
||||
nlog_error("failed to create neuron_logs.tar.gz");
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
|
||||
http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(path, "neuron_logs.tar.gz");
|
||||
rv = read_file(path, &data, &len);
|
||||
rv = read_file("/tmp/neuron_debug.tar.gz", &data, &len);
|
||||
if (0 != rv) {
|
||||
NEU_JSON_RESPONSE_ERROR(
|
||||
rv, { http_response(aio, error_code.error, result_error); });
|
||||
return;
|
||||
}
|
||||
|
||||
// delete neuron_logs folder from build
|
||||
rv = system("rm -rf neuron_logs.tar.gz neuron_logs");
|
||||
if (0 != rv) {
|
||||
nlog_error("failed to delete neuron_logs folder");
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
|
||||
http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
/* handle http response */
|
||||
rv = http_resp_files(aio, data, len,
|
||||
"attachment; filename=neuron_debug.tar.gz");
|
||||
|
||||
// handle http response
|
||||
strcpy(disp, "attachment; filename=neuron_logs.tar.gz");
|
||||
rv = http_resp_files(aio, data, len, disp);
|
||||
if (0 != rv) {
|
||||
return;
|
||||
}
|
||||
nlog_notice("download neuron_debug.tar.gz, ret: %d", rv);
|
||||
}
|
||||
|
||||
void handle_log_level(nng_aio *aio)
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ static inline int reset_password()
|
||||
"$5$PwFeXpBBIBZuZdZl$fP8fFPWCLoaWcnVXVSR.3Xi8TEqCvX92gjhowNNn6S4",
|
||||
};
|
||||
|
||||
int rv = neu_persister_create();
|
||||
int rv = neu_persister_create(g_config_dir);
|
||||
if (0 != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ ssize_t neu_conn_recv(neu_conn_t *conn, uint8_t *buf, ssize_t len)
|
||||
conn->fd, len, ret, strerror(errno), errno);
|
||||
}
|
||||
|
||||
if (errno == EPIPE || ret == -1) {
|
||||
if (errno == EPIPE || ret == -1 || ret == 0) {
|
||||
conn_disconnect(conn);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,11 @@ static void *event_loop(void *arg)
|
||||
if (ret == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ret == -1 && errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ret == -1 || events->stop) {
|
||||
zlog_warn(neuron, "event loop exit, errno: %s(%d), stop: %d",
|
||||
strerror(errno), errno, events->stop);
|
||||
|
||||
+3
-2
@@ -42,7 +42,7 @@ static void sig_handler(int sig)
|
||||
{
|
||||
nlog_warn("recv sig: %d", sig);
|
||||
|
||||
if (sig != SIGABRT) {
|
||||
if (sig == SIGINT || sig == SIGTERM) {
|
||||
neu_manager_destroy(g_manager);
|
||||
neu_persister_destroy();
|
||||
}
|
||||
@@ -58,6 +58,7 @@ static int neuron_run(const neu_cli_args_t *args)
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGTERM, sig_handler);
|
||||
signal(SIGABRT, sig_handler);
|
||||
signal(SIGSEGV, sig_handler);
|
||||
|
||||
// try to enable core dump
|
||||
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
|
||||
@@ -65,7 +66,7 @@ static int neuron_run(const neu_cli_args_t *args)
|
||||
nlog_warn("neuron process failed enable core dump, ignore");
|
||||
}
|
||||
|
||||
rv = neu_persister_create();
|
||||
rv = neu_persister_create(args->config_dir);
|
||||
assert(rv == 0);
|
||||
|
||||
zlog_notice(neuron, "neuron process, daemon: %d, version: %s (%s %s)",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "persist_json_plugin.h"
|
||||
#include "persist/json/persist_json_plugin.h"
|
||||
|
||||
int neu_json_decode_plugin_req(char *buf, neu_json_plugin_req_t **result)
|
||||
{
|
||||
|
||||
@@ -430,7 +430,7 @@ static int apply_schemas(sqlite3 *db, const char *dir)
|
||||
return rv;
|
||||
}
|
||||
|
||||
int neu_persister_create()
|
||||
int neu_persister_create(const char *schema_dir)
|
||||
{
|
||||
int rv = sqlite3_open(db_file, &global_db);
|
||||
|
||||
@@ -455,7 +455,7 @@ int neu_persister_create()
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = apply_schemas(global_db, g_config_dir);
|
||||
rv = apply_schemas(global_db, schema_dir);
|
||||
if (rv != 0) {
|
||||
nlog_fatal("db apply schemas fail");
|
||||
sqlite3_close(global_db);
|
||||
@@ -465,6 +465,11 @@ int neu_persister_create()
|
||||
return 0;
|
||||
}
|
||||
|
||||
sqlite3 *neu_persister_get_db()
|
||||
{
|
||||
return global_db;
|
||||
}
|
||||
|
||||
void neu_persister_destroy()
|
||||
{
|
||||
sqlite3_close(global_db);
|
||||
|
||||
Reference in New Issue
Block a user