mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-08 10:11:40 +00:00
REORG: mworker/cli: move CLI functions to mworker.c
Move the CLI functions of the master worker to mworker.c
This commit is contained in:
parent
7175e6861e
commit
88dc7c5de9
75
src/cli.c
75
src/cli.c
@ -1324,16 +1324,6 @@ static int cli_parse_set_lvl(char **args, char *payload, struct appctx *appctx,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reload the master process */
|
|
||||||
static int cli_parse_reload(char **args, char *payload, struct appctx *appctx, void *private)
|
|
||||||
{
|
|
||||||
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
mworker_reload();
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cli_parse_default(char **args, char *payload, struct appctx *appctx, void *private)
|
int cli_parse_default(char **args, char *payload, struct appctx *appctx, void *private)
|
||||||
{
|
{
|
||||||
@ -1461,66 +1451,6 @@ static int bind_parse_severity_output(char **args, int cur_arg, struct proxy *px
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Displays workers and processes */
|
|
||||||
static int cli_io_handler_show_proc(struct appctx *appctx)
|
|
||||||
{
|
|
||||||
struct stream_interface *si = appctx->owner;
|
|
||||||
struct mworker_proc *child;
|
|
||||||
int old = 0;
|
|
||||||
int up = now.tv_sec - proc_self->timestamp;
|
|
||||||
|
|
||||||
if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
chunk_reset(&trash);
|
|
||||||
|
|
||||||
chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>");
|
|
||||||
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", getpid(), "master", 0, proc_self->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
|
|
||||||
|
|
||||||
/* displays current processes */
|
|
||||||
|
|
||||||
chunk_appendf(&trash, "# workers\n");
|
|
||||||
list_for_each_entry(child, &proc_list, list) {
|
|
||||||
up = now.tv_sec - child->timestamp;
|
|
||||||
|
|
||||||
if (child->type != 'w')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (child->reloads > 0) {
|
|
||||||
old++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", child->relative_pid, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* displays old processes */
|
|
||||||
|
|
||||||
if (old) {
|
|
||||||
char *msg = NULL;
|
|
||||||
|
|
||||||
chunk_appendf(&trash, "# old workers\n");
|
|
||||||
list_for_each_entry(child, &proc_list, list) {
|
|
||||||
up = now.tv_sec - child->timestamp;
|
|
||||||
|
|
||||||
if (child->type != 'w')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (child->reloads > 0) {
|
|
||||||
memprintf(&msg, "[was: %u]", child->relative_pid);
|
|
||||||
chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", msg, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ci_putchk(si_ic(si), &trash) == -1) {
|
|
||||||
si_rx_room_blk(si);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* dump complete */
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Send all the bound sockets, always returns 1 */
|
/* Send all the bound sockets, always returns 1 */
|
||||||
static int _getsocks(char **args, char *payload, struct appctx *appctx, void *private)
|
static int _getsocks(char **args, char *payload, struct appctx *appctx, void *private)
|
||||||
@ -2615,9 +2545,6 @@ static struct applet cli_applet = {
|
|||||||
|
|
||||||
/* register cli keywords */
|
/* register cli keywords */
|
||||||
static struct cli_kw_list cli_kws = {{ },{
|
static struct cli_kw_list cli_kws = {{ },{
|
||||||
{ { "@<relative pid>", NULL }, "@<relative pid> : send a command to the <relative pid> process", NULL, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
|
|
||||||
{ { "@!<pid>", NULL }, "@!<pid> : send a command to the <pid> process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
|
|
||||||
{ { "@master", NULL }, "@master : send a command to the master process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
|
|
||||||
{ { "help", NULL }, NULL, cli_parse_simple, NULL },
|
{ { "help", NULL }, NULL, cli_parse_simple, NULL },
|
||||||
{ { "prompt", NULL }, NULL, cli_parse_simple, NULL },
|
{ { "prompt", NULL }, NULL, cli_parse_simple, NULL },
|
||||||
{ { "quit", NULL }, NULL, cli_parse_simple, NULL },
|
{ { "quit", NULL }, NULL, cli_parse_simple, NULL },
|
||||||
@ -2630,10 +2557,8 @@ static struct cli_kw_list cli_kws = {{ },{
|
|||||||
{ { "show", "cli", "level", NULL }, "show cli level : display the level of the current CLI session", cli_parse_show_lvl, NULL, NULL, NULL, ACCESS_MASTER},
|
{ { "show", "cli", "level", NULL }, "show cli level : display the level of the current CLI session", cli_parse_show_lvl, NULL, NULL, NULL, ACCESS_MASTER},
|
||||||
{ { "show", "fd", NULL }, "show fd [num] : dump list of file descriptors in use", cli_parse_show_fd, cli_io_handler_show_fd, NULL },
|
{ { "show", "fd", NULL }, "show fd [num] : dump list of file descriptors in use", cli_parse_show_fd, cli_io_handler_show_fd, NULL },
|
||||||
{ { "show", "activity", NULL }, "show activity : show per-thread activity stats (for support/developers)", cli_parse_default, cli_io_handler_show_activity, NULL },
|
{ { "show", "activity", NULL }, "show activity : show per-thread activity stats (for support/developers)", cli_parse_default, cli_io_handler_show_activity, NULL },
|
||||||
{ { "show", "proc", NULL }, "show proc : show processes status", cli_parse_default, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
|
|
||||||
{ { "operator", NULL }, "operator : lower the level of the current CLI session to operator", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
|
{ { "operator", NULL }, "operator : lower the level of the current CLI session to operator", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
|
||||||
{ { "user", NULL }, "user : lower the level of the current CLI session to user", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
|
{ { "user", NULL }, "user : lower the level of the current CLI session to user", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
|
||||||
{ { "reload", NULL }, "reload : reload haproxy", cli_parse_reload, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
|
|
||||||
{ { "_getsocks", NULL }, NULL, _getsocks, NULL },
|
{ { "_getsocks", NULL }, NULL, _getsocks, NULL },
|
||||||
{{},}
|
{{},}
|
||||||
}};
|
}};
|
||||||
|
101
src/mworker.c
101
src/mworker.c
@ -17,18 +17,24 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#include <common/initcall.h>
|
||||||
#include <common/mini-clist.h>
|
#include <common/mini-clist.h>
|
||||||
|
|
||||||
|
#include <types/cli.h>
|
||||||
|
#include <types/global.h>
|
||||||
|
#include <types/peers.h>
|
||||||
|
#include <types/signal.h>
|
||||||
|
|
||||||
|
#include <proto/cli.h>
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
#include <proto/listener.h>
|
#include <proto/listener.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/mworker.h>
|
#include <proto/mworker.h>
|
||||||
#include <proto/signal.h>
|
|
||||||
|
|
||||||
#include <types/global.h>
|
|
||||||
#include <types/peers.h>
|
|
||||||
#include <proto/proxy.h>
|
#include <proto/proxy.h>
|
||||||
#include <types/signal.h>
|
#include <proto/signal.h>
|
||||||
|
#include <proto/stream.h>
|
||||||
|
#include <proto/stream_interface.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(USE_SYSTEMD)
|
#if defined(USE_SYSTEMD)
|
||||||
#include <systemd/sd-daemon.h>
|
#include <systemd/sd-daemon.h>
|
||||||
@ -374,3 +380,88 @@ void mworker_cleanlisteners()
|
|||||||
curproxy->state = PR_STSTOPPED;
|
curproxy->state = PR_STSTOPPED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Displays workers and processes */
|
||||||
|
static int cli_io_handler_show_proc(struct appctx *appctx)
|
||||||
|
{
|
||||||
|
struct stream_interface *si = appctx->owner;
|
||||||
|
struct mworker_proc *child;
|
||||||
|
int old = 0;
|
||||||
|
int up = now.tv_sec - proc_self->timestamp;
|
||||||
|
|
||||||
|
if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
chunk_reset(&trash);
|
||||||
|
|
||||||
|
chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>");
|
||||||
|
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", getpid(), "master", 0, proc_self->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
|
||||||
|
|
||||||
|
/* displays current processes */
|
||||||
|
|
||||||
|
chunk_appendf(&trash, "# workers\n");
|
||||||
|
list_for_each_entry(child, &proc_list, list) {
|
||||||
|
up = now.tv_sec - child->timestamp;
|
||||||
|
|
||||||
|
if (child->type != 'w')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (child->reloads > 0) {
|
||||||
|
old++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", child->relative_pid, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* displays old processes */
|
||||||
|
|
||||||
|
if (old) {
|
||||||
|
char *msg = NULL;
|
||||||
|
|
||||||
|
chunk_appendf(&trash, "# old workers\n");
|
||||||
|
list_for_each_entry(child, &proc_list, list) {
|
||||||
|
up = now.tv_sec - child->timestamp;
|
||||||
|
|
||||||
|
if (child->type != 'w')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (child->reloads > 0) {
|
||||||
|
memprintf(&msg, "[was: %u]", child->relative_pid);
|
||||||
|
chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", msg, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ci_putchk(si_ic(si), &trash) == -1) {
|
||||||
|
si_rx_room_blk(si);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dump complete */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reload the master process */
|
||||||
|
static int cli_parse_reload(char **args, char *payload, struct appctx *appctx, void *private)
|
||||||
|
{
|
||||||
|
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
mworker_reload();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* register cli keywords */
|
||||||
|
static struct cli_kw_list cli_kws = {{ },{
|
||||||
|
{ { "@<relative pid>", NULL }, "@<relative pid> : send a command to the <relative pid> process", NULL, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
|
||||||
|
{ { "@!<pid>", NULL }, "@!<pid> : send a command to the <pid> process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
|
||||||
|
{ { "@master", NULL }, "@master : send a command to the master process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
|
||||||
|
{ { "show", "proc", NULL }, "show proc : show processes status", cli_parse_default, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
|
||||||
|
{ { "reload", NULL }, "reload : reload haproxy", cli_parse_reload, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
|
||||||
|
{{},}
|
||||||
|
}};
|
||||||
|
|
||||||
|
INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
|
||||||
|
Loading…
Reference in New Issue
Block a user