From 9e38b8e0bad111b4a4867792fee23e0976a5061f Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 15 Jun 2008 21:25:41 +0000 Subject: [PATCH] Allow varnishd to be started with neither -b nor -f, this is useful where a central facility is used to push VCL's to a number of Varnish hosts. Until a VCL is loaded, the child process cannot be started. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2699 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/mgt.h | 1 + varnish-cache/bin/varnishd/mgt_child.c | 15 +++++++++++---- varnish-cache/bin/varnishd/mgt_vcc.c | 9 +++++++++ varnish-cache/bin/varnishd/varnishd.c | 9 +++------ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/varnish-cache/bin/varnishd/mgt.h b/varnish-cache/bin/varnishd/mgt.h index 7922f152..3335d090 100644 --- a/varnish-cache/bin/varnishd/mgt.h +++ b/varnish-cache/bin/varnishd/mgt.h @@ -59,6 +59,7 @@ void MCF_ParamSet(struct cli *, const char *param, const char *val); void mgt_vcc_init(void); int mgt_vcc_default(const char *bflag, const char *fflag, int f_fd, int Cflag); int mgt_push_vcls_and_start(unsigned *status, char **p); +int mgt_has_vcl(void); extern char *mgt_cc_cmd; #include "hash_slinger.h" diff --git a/varnish-cache/bin/varnishd/mgt_child.c b/varnish-cache/bin/varnishd/mgt_child.c index 005a8826..660ae902 100644 --- a/varnish-cache/bin/varnishd/mgt_child.c +++ b/varnish-cache/bin/varnishd/mgt_child.c @@ -438,7 +438,9 @@ mgt_run(int dflag, const char *T_arg) printf("rolling(1)...\n"); fprintf(stderr, "rolling(2)...\n"); - if (!dflag) + if (!dflag && !mgt_has_vcl()) + fprintf(stderr, "No VCL loaded yet\n"); + else if (!dflag) start_child(); else fprintf(stderr, @@ -460,9 +462,14 @@ mcf_server_startstop(struct cli *cli, const char * const *av, void *priv) (void)av; if (priv != NULL && child_state == CH_RUNNING) stop_child(); - else if (priv == NULL && child_state == CH_STOPPED) - start_child(); - else { + else if (priv == NULL && child_state == CH_STOPPED) { + if (mgt_has_vcl()) + start_child(); + else { + cli_result(cli, CLIS_CANT); + cli_out(cli, "No VCL available"); + } + } else { cli_result(cli, CLIS_CANT); cli_out(cli, "Child in state %s", ch_state[child_state]); } diff --git a/varnish-cache/bin/varnishd/mgt_vcc.c b/varnish-cache/bin/varnishd/mgt_vcc.c index d513d757..2f95b21d 100644 --- a/varnish-cache/bin/varnishd/mgt_vcc.c +++ b/varnish-cache/bin/varnishd/mgt_vcc.c @@ -459,6 +459,15 @@ mgt_vcc_default(const char *b_arg, const char *f_arg, int f_fd, int C_flag) /*--------------------------------------------------------------------*/ +int +mgt_has_vcl() +{ + + return (!VTAILQ_EMPTY(&vclhead)); +} + +/*--------------------------------------------------------------------*/ + int mgt_push_vcls_and_start(unsigned *status, char **p) { diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index b84f21fe..a71a3c91 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -494,10 +494,6 @@ main(int argc, char *argv[]) fprintf(stderr, "Only one of -b or -f can be specified\n"); usage(); } - if (b_arg == NULL && f_arg == NULL) { - fprintf(stderr, "One of -b or -f must be specified\n"); - usage(); - } if (f_arg != NULL) { f_fd = open(f_arg, O_RDONLY); @@ -533,8 +529,9 @@ main(int argc, char *argv[]) exit(1); } - if (mgt_vcc_default(b_arg, f_arg, f_fd, C_flag)) - exit (2); + if (b_arg != NULL || f_arg != NULL) + if (mgt_vcc_default(b_arg, f_arg, f_fd, C_flag)) + exit (2); if (C_flag) exit (0); -- 2.39.5