Commit 34d38f0b authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Expose the master and worker PIDs via the CLI

The change in u00011.vtc is the result of having two commands starting
with "pi", breaking auto-completion. Fortunately "pin\t" still does the
trick.
parent e95fda1d
......@@ -666,6 +666,31 @@ MCH_Running(void)
* CLI commands
*/
static void v_matchproto_(cli_func_t)
mch_pid(struct cli *cli, const char * const *av, void *priv)
{
(void)av;
(void)priv;
VCLI_Out(cli, "Master: %10jd\n", (intmax_t)getpid());
if (!MCH_Running())
return;
VCLI_Out(cli, "Worker: %10jd\n", (intmax_t)child_pid);
}
static void v_matchproto_(cli_func_t)
mch_pid_json(struct cli *cli, const char * const *av, void *priv)
{
(void)priv;
VCLI_JSON_begin(cli, 2, av);
VCLI_Out(cli, ",\n {\"master\": %jd", (intmax_t)getpid());
if (MCH_Running())
VCLI_Out(cli, ", \"worker\": %jd", (intmax_t)child_pid);
VCLI_Out(cli, "}");
VCLI_JSON_end(cli);
}
static void v_matchproto_(cli_func_t)
mch_cli_server_start(struct cli *cli, const char * const *av, void *priv)
{
......@@ -725,6 +750,7 @@ static struct cli_proto cli_mch[] = {
{ CLICMD_PANIC_SHOW, "", mch_cli_panic_show,
mch_cli_panic_show_json },
{ CLICMD_PANIC_CLEAR, "", mch_cli_panic_clear },
{ CLICMD_PID, "", mch_pid, mch_pid_json },
{ NULL }
};
......
varnishtest "varnish-cli pid command"
varnish v1 -cliexpect "^Master: +[0-9]+\n$" pid
varnish v1 -cliok "pid -j"
varnish v1 -vcl {backend be none;} -start
varnish v1 -cliexpect "^Master: +[0-9]+\nWorker: +[0-9]+\n$" pid
varnish v1 -cliok "pid -j"
......@@ -18,7 +18,7 @@ process p1 -log {varnishadm -n ${v1_name}} -start
process p1 -expect-text 0 1 "Type 'quit' to close CLI session."
process p1 -write "pi\t\r"
process p1 -write "pin\t\r"
process p1 -expect-text 0 1 "PONG"
......
......@@ -400,6 +400,14 @@ CLI_CMD(STORAGE_LIST,
0, 0
)
CLI_CMD(PID,
"pid",
"pid [-j]",
"Show the pid of the master process, and the worker if it's running.",
" ``-j`` specifies JSON output.",
0, 0
)
#undef CLI_CMD
/*lint -restore */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment