master & master tools can display the version of all services

This commit is contained in:
zsx 2018-01-23 18:57:29 +08:00
parent dbc586c33b
commit ea244a6673
24 changed files with 162 additions and 8 deletions

View File

@ -1,4 +1,7 @@
18) 2018.1.23
18.1) feature: web interface adds version info for every services.
17) 2018.1.19
17.1) log: don't save some command reply information

View File

@ -1391,6 +1391,11 @@ namespace acl
else
$node.add_text("notify_recipients", acl::get_value($obj.notify_recipients));
if (check_nullptr($obj.version))
$node.add_null("version");
else
$node.add_text("version", acl::get_value($obj.version));
if (check_nullptr($obj.env))
$node.add_null("env");
else
@ -1436,6 +1441,7 @@ namespace acl
acl::json_node *listen_fd_count = $node["listen_fd_count"];
acl::json_node *notify_addr = $node["notify_addr"];
acl::json_node *notify_recipients = $node["notify_recipients"];
acl::json_node *version = $node["version"];
acl::json_node *env = $node["env"];
acl::json_node *procs = $node["procs"];
std::pair<bool, std::string> $result;
@ -1485,6 +1491,9 @@ namespace acl
if(notify_recipients)
gson(*notify_recipients, &$obj.notify_recipients);
if(version)
gson(*version, &$obj.version);
if(!env ||!env->get_obj()||!($result = gson(*env->get_obj(), &$obj.env), $result.first))
return std::make_pair(false, "required [serv_info_t.env] failed:{"+$result.second+"}");

View File

@ -45,6 +45,8 @@ struct serv_info_t
acl::string notify_addr;
// Gson@optional
acl::string notify_recipients;
// Gson@optional
acl::string version;
std::map<acl::string, acl::string> env;
// Gson@optional
std::list<proc_info_t> procs;

View File

@ -45,6 +45,8 @@ struct serv_info_t
acl::string notify_addr;
// Gson@optional
acl::string notify_recipients;
// Gson@optional
acl::string version;
std::map<acl::string, acl::string> env;
// Gson@optional
std::list<proc_info_t> procs;

View File

@ -16,7 +16,7 @@
#include "master/master.h"
#include "manage/manager.h"
const char *var_master_version = "acl_master version 2.1.0-1 20180119 (acl)";
const char *var_master_version = "3.3.0-60 20180123";
char *var_master_procname;
/* usage - show hint and terminate */
@ -58,7 +58,8 @@ int main(int argc, char **argv)
acl_msg_verbose++;
break;
case 'v':
printf("%s\r\n", var_master_version);
printf("%s (acl_master, acl-%s)\r\n",
var_master_version, acl_version());
return 0;
case 'h':
usage(argv[0]);

View File

@ -25,6 +25,7 @@ void service_list::add_one(list_res_t& res, const ACL_MASTER_SERV* serv)
info.start = serv->start;
info.path = serv->path;
info.conf = serv->conf;
info.version = serv->version;
info.proc_max = serv->max_proc;
info.proc_prefork = serv->prefork_proc;
info.proc_total = serv->total_proc;

View File

@ -44,6 +44,8 @@ bool service_stat::stat_one(const char* path, serv_info_t& info)
if (serv->notify_recipients && *serv->notify_recipients)
info.notify_recipients = serv->notify_recipients;
info.version = serv->version;
ACL_ITER iter;
acl_foreach(iter, serv->children_env) {
ACL_MASTER_NV* v = (ACL_MASTER_NV *) iter.data;

View File

@ -46,6 +46,7 @@ typedef struct ACL_MASTER_SERV {
char *conf; /* service configure filepath */
char *notify_addr; /* warning address when not null */
char *notify_recipients; /* users warned to */
char *version; /* the service's version */
int avail_proc; /* idle processes */
int total_proc; /* number of processes */
int throttle_delay; /* failure recovery parameter */

View File

@ -83,6 +83,7 @@ int acl_master_refresh_service(ACL_MASTER_SERV *entry)
SWAP(char *, serv->cmdext, entry->cmdext);
SWAP(char *, serv->notify_addr, entry->notify_addr);
SWAP(char *, serv->notify_recipients, entry->notify_recipients);
SWAP(char *, serv->version, entry->version);
SWAP(ACL_ARGV *, serv->args, entry->args);
acl_master_service_restart(serv);

View File

@ -451,6 +451,7 @@ static int service_transport(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *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_STOP_KILL, "off");
if (EQ(ptr, "on") || EQ(ptr, "true") || atoi(ptr) > 1)
serv->flags |= ACL_MASTER_FLAG_STOP_KILL;
else
@ -463,6 +464,13 @@ static void service_control(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
serv->flags &= ~ACL_MASTER_FLAG_STOP_WAIT;
}
static void service_version(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
{
const char *ptr = get_str_ent(xcp, ACL_VAR_MASTER_SERV_VERSION, "none");
serv->version = acl_mystrdup(ptr);
}
static void service_wakeup_time(ACL_XINETD_CFG_PARSER *xcp,
ACL_MASTER_SERV *serv)
{
@ -802,6 +810,7 @@ ACL_MASTER_SERV *acl_master_ent_load(const char *filepath)
service_wakeup_time(xcp, serv);
service_proc(xcp, serv);
service_control(xcp, serv);
service_version(xcp, serv);
if (service_args(xcp, serv, filepath) < 0) {
acl_master_ent_free(serv);
@ -902,6 +911,8 @@ void acl_master_ent_free(ACL_MASTER_SERV *serv)
acl_myfree(serv->notify_addr);
if (serv->notify_recipients)
acl_myfree(serv->notify_recipients);
if (serv->version)
acl_myfree(serv->version);
if (serv->args)
acl_argv_free(serv->args);
if (serv->children_env)

View File

@ -157,6 +157,8 @@ extern int acl_var_master_start_timeo;
#define ACL_VAR_MASETR_SERV_STOP_KILL "master_stop_kill"
#define ACL_VAR_MASTER_SERV_STOP_WAIT "master_stop_wait"
#define ACL_VAR_MASTER_SERV_VERSION "master_version"
/**
* master_params.c
*/

View File

@ -128,6 +128,7 @@ static void println_server(const serv_info_t& server)
println("listen_fd_count", server.listen_fd_count);
println("notify_addr", server.notify_addr.c_str());
println("notify_recipients", server.notify_recipients.c_str());
println("version", server.version.c_str());
acl::string buf;
size_t i = 0;

View File

@ -1,11 +1,45 @@
#include "stdafx.h"
#include "master_service.h"
static const char *version = "1.0.0-0";
static const char *date = "20180123";
static const char *cmd = "master_ctld";
static void help(const char* procname)
{
printf("usage: %s -h [help]\r\n"
" -v [version]\r\n"
" alone %s.cf\r\n", procname, procname);
}
static void check_version(int argc, char* argv[])
{
for (int i = 0; i < argc; i++)
{
if (argv[i][0] != '-')
continue;
switch (argv[i][1])
{
case 'h':
help(argv[0]);
exit (0);
case 'v':
printf("%s %s (%s, acl-%s)\r\n", version, date,
cmd, acl_version());
exit (0);
default:
break;
}
}
}
int main(int argc, char* argv[])
{
// 初始化 acl 库
acl::acl_cpp_init();
check_version(argc, argv);
master_service& ms = acl::singleton2<master_service>::get_instance();
// 设置配置参数表

View File

@ -47,6 +47,7 @@ service master_ctld {
master_prefork = 1
# 进程程序名
master_command = master_ctld
master_version = 1.0.0-0
# 进程日志记录文件
master_log = {install_path}/var/log/master_ctld
# 调试日志方式格式tag:level; tag:level; tab:level, all:1; 101:2

View File

@ -14,6 +14,42 @@ service_list::service_list(const char* master_ctld, const char* guard_manager,
{
}
void service_list::get_version(ACL_VSTREAM* fp, acl::string& out)
{
char buf[8192];
int ret = acl_vstream_gets_nonl(fp, buf, sizeof(buf));
if (ret == ACL_VSTREAM_EOF)
logger_error("read error %s", acl::last_serror());
else
{
ACL_ARGV* tokens = acl_argv_split(buf, " \t");
out = tokens->argv[0];
acl_argv_free(tokens);
}
}
void service_list::get_version(const char* path, acl::string& out)
{
out = "unknown";
ACL_ARGV* args = acl_argv_alloc(1);
acl_argv_add(args, path, "-v", NULL);
ACL_VSTREAM* fp = acl_vstream_popen(O_RDWR,
ACL_VSTREAM_POPEN_ARGV, args->argv, ACL_VSTREAM_POPEN_END);
if (fp == NULL)
logger_error("popen error=%s, comd=%s",
acl::last_serror(), path);
else
{
get_version(fp, out);
acl_vstream_pclose(fp);
}
acl_argv_free(args);
}
bool service_list::run(void)
{
list_req_t req;
@ -35,6 +71,13 @@ bool service_list::run(void)
info.start = (*cit).start;
info.name = (*cit).name;
info.conf = (*cit).conf;
info.path = (*cit).path;
if ((*cit).version.empty())
info.version = "none";
else if ((*cit).version.equal("-v", false))
get_version((*cit).path, info.version);
else
info.version = (*cit).version;
list_res.data.push_back(info);
}
@ -108,12 +151,14 @@ bool service_list::udp_report(const acl::string& body)
const char* local_addr = "0.0.0.0:0";
acl::socket_stream stream;
if (stream.bind_udp(local_addr) == false) {
logger_error("bind_udp %s error %s", local_addr, acl::last_serror());
logger_error("bind_udp %s error %s",
local_addr, acl::last_serror());
return false;
}
stream.set_peer(ip);
if (stream.write(body) == false) {
logger_error("write %s error %s", body.c_str(), acl::last_serror());
logger_error("write %s error %s",
body.c_str(), acl::last_serror());
return false;
}

View File

@ -27,6 +27,8 @@ private:
int conn_timeout_;
int rw_timeout_;
void get_version(ACL_VSTREAM* fp, acl::string& out);
void get_version(const char* path, acl::string& out);
bool report(const acl::string& body);
bool tcp_report(const acl::string& body);
bool udp_report(const acl::string& body);

View File

@ -37,6 +37,7 @@ bool service_app::save(const char* ip, const service_list_res_t& res)
#define APP_START "start"
#define APP_STATUS "status"
#define APP_DATE "date"
#define APP_VER "version"
bool service_app::save_one(const char* ip, const service_info_t& info)
{
@ -45,6 +46,7 @@ bool service_app::save_one(const char* ip, const service_info_t& info)
attrs[APP_CONF] = info.conf;
attrs[APP_NAME] = info.name;
attrs[APP_STATUS] = acl::string::parse_int(info.status);
attrs[APP_VER] = info.version;
acl::rfc822 rfc;
char buf[128];

View File

@ -28,6 +28,16 @@ namespace acl
else
$node.add_text("conf", acl::get_value($obj.conf));
if (check_nullptr($obj.path))
$node.add_null("path");
else
$node.add_text("path", acl::get_value($obj.path));
if (check_nullptr($obj.version))
$node.add_null("version");
else
$node.add_text("version", acl::get_value($obj.version));
return $node;
}
@ -52,6 +62,8 @@ namespace acl
acl::json_node *start = $node["start"];
acl::json_node *name = $node["name"];
acl::json_node *conf = $node["conf"];
acl::json_node *path = $node["path"];
acl::json_node *version = $node["version"];
std::pair<bool, std::string> $result;
if(!status ||!($result = gson(*status, &$obj.status), $result.first))
@ -66,6 +78,12 @@ namespace acl
if(!conf ||!($result = gson(*conf, &$obj.conf), $result.first))
return std::make_pair(false, "required [service_info_t.conf] failed:{"+$result.second+"}");
if(path)
gson(*path, &$obj.path);
if(version)
gson(*version, &$obj.version);
return std::make_pair(true,"");
}

View File

@ -18,6 +18,10 @@ struct service_info_t
long start;
acl::string name;
acl::string conf;
// Gson@optional
acl::string path;
// Gson@optional
acl::string version;
};
struct service_list_res_t

View File

@ -18,6 +18,10 @@ struct service_info_t
long start;
acl::string name;
acl::string conf;
// Gson@optional
acl::string path;
// Gson@optional
acl::string version;
};
struct service_list_res_t

View File

@ -1,6 +1,10 @@
修改历史列表:
------------------------------------------------------------------------
621) 2018.1.23
621.1) bugfix: 当用 acl_vstream_fdopen 打开文件时,不应再判断是否是 SOCKET 类型,
否则会将文件句柄类型当作 SOCKET 类型,从而引发问题
620) 2018.1.16
620.1) bugfix: 重构 acl_ifconf.c 中的函数 acl_ifconf_search该函数存在一些
兼容性问题

View File

@ -24,7 +24,7 @@
#include "init.h"
static char *version = "acl_3.3.0";
static char *version = "3.3.0-60 20180123";
const char *acl_version(void)
{

View File

@ -2194,7 +2194,9 @@ ACL_VSTREAM *acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
if (fd == ACL_SOCKET_INVALID)
return fp;
if ((ret = acl_check_socket(fd)) == 1) {
if (fdtype & ACL_VSTREAM_TYPE_FILE) {
/* nothing */
} else if ((ret = acl_check_socket(fd)) == 1) {
ret = acl_getsocktype(fd);
#ifdef ACL_INET6
if (ret == AF_INET || ret == AF_INET6)
@ -3058,7 +3060,6 @@ static struct sockaddr *set_sock_addr(const char *addr, size_t *sa_size)
#endif
memcpy(un->sun_path, buf, len + 1);
*sa_size = sizeof(struct sockaddr_un);
printf("set sock addr=%s\r\n", buf);
return (struct sockaddr *) un;
}
#endif

View File

@ -1,7 +1,7 @@
Summary: The powerful c/c++ library and server framework
Name: acl-libs
Version: 3.3.0
Release: 59
Release: 60
Group: System/Libs
License: IBM
URL: http://cdnlog-web.qiyi.domain
@ -76,6 +76,9 @@ fi
/etc/init.d/master
%changelog
* Fri Jan 19 2018 zhengshuxin@qiyi.com 3.3.0-60-20180119.10
- master & master tools: support version manager
* Fri Jan 19 2018 zhengshuxin@qiyi.com 3.3.0-59-20180119.10
- fiber: remove valgrind debug by default in Makefile of fiber