]> err.no Git - varnish/commitdiff
Implement vcl.reload <name> <path> command
authorTollef Fog Heen <tfheen@err.no>
Sun, 16 Nov 2008 18:34:00 +0000 (19:34 +0100)
committerTollef Fog Heen <tfheen@err.no>
Fri, 30 Jan 2009 12:01:35 +0000 (12:01 +0000)
varnish-cache/bin/varnishd/cache_vcl.c
varnish-cache/bin/varnishd/mgt_cli.c
varnish-cache/bin/varnishd/mgt_cli.h
varnish-cache/bin/varnishd/mgt_vcc.c
varnish-cache/include/cli.h

index fb65a2aef018441cc79f6b0e6e43c27f2cf612dc..64c34680478d4596698fbba0223cfc1d46f798d2 100644 (file)
@@ -239,6 +239,37 @@ ccf_config_list(struct cli *cli, const char * const *av, void *priv)
        }
 }
 
+static void
+ccf_config_reload(struct cli *cli, const char * const *av, void *priv)
+{
+       char *t;
+       struct vcls *vcl, *vcl_discard;
+       (void)av;
+       (void)priv;
+       ASSERT_CLI();
+
+       asprintf(&t, "vcltmp-%d", random());
+       if (VCL_Load(av[3], t, cli))
+               cli_result(cli, CLIS_PARAM);
+
+       vcl = vcl_find(t);
+       vcl_discard = vcl_find(av[2]);
+       REPLACE(vcl->name, av[2]);
+
+       Lck_Lock(&vcl_mtx);
+       vcl_active = vcl;
+       Lck_Unlock(&vcl_mtx);
+
+       VSL_stats->n_vcl_discard++;
+       VSL_stats->n_vcl_avail--;
+       vcl_discard->conf->discard = 1;
+
+       if (vcl_discard->conf->busy == 0)
+               VCL_Nuke(vcl_discard);
+
+       return;
+}
+
 static void
 ccf_config_load(struct cli *cli, const char * const *av, void *priv)
 {
@@ -322,6 +353,7 @@ VCL_##func##_method(struct sess *sp)                                        \
 
 static struct cli_proto vcl_cmds[] = {
        { CLI_VCL_LOAD,         ccf_config_load },
+       { CLI_VCL_RELOAD,       ccf_config_reload },
        { CLI_VCL_LIST,         ccf_config_list },
        { CLI_VCL_DISCARD,      ccf_config_discard },
        { CLI_VCL_USE,          ccf_config_use },
index 07b5ce48a8dd536ede7c5a7457a1e1aaf08889f0..75223a20eb1e958a1c9e0b5494914d5ca65736a4 100644 (file)
@@ -135,6 +135,7 @@ static struct cli_proto cli_proto[] = {
        { CLI_SERVER_STOP,      mcf_server_startstop, cli_proto },
        { CLI_STATS,            mcf_stats, NULL },
        { CLI_VCL_LOAD,         mcf_config_load, NULL },
+       { CLI_VCL_RELOAD,       mcf_config_reload, NULL },
        { CLI_VCL_INLINE,       mcf_config_inline, NULL },
        { CLI_VCL_USE,          mcf_config_use, NULL },
        { CLI_VCL_DISCARD,      mcf_config_discard, NULL },
index b26dafe3f1d37f13214a36e95ad1ff794d9bdd2a..e1e04bfe19f0893f7465d952f6f443f15038d62e 100644 (file)
@@ -39,6 +39,7 @@ cli_func_t mcf_param_set;
 
 /* mgt_vcc.c */
 cli_func_t mcf_config_load;
+cli_func_t mcf_config_reload;
 cli_func_t mcf_config_inline;
 cli_func_t mcf_config_use;
 cli_func_t mcf_config_discard;
index c782e71957d1155cfb028ed60ba0dfeab96f8d10..b713dea1a9cf209736feddf951591aa01ef76b72 100644 (file)
@@ -488,6 +488,51 @@ mcf_config_inline(struct cli *cli, const char * const *av, void *priv)
        free(p);
 }
 
+void
+mcf_config_reload(struct cli *cli, const char *const *av, void *priv)
+{
+       char *vf;
+       struct vsb *sb;
+       unsigned status;
+       char *p = NULL;
+       struct vclprog *vp;
+       int active;
+
+       vp = mgt_vcc_byname(av[2]);
+       if (vp == NULL) {
+               cli_out(cli, "No VCL program named %s, use vcl.load", av[2]);
+               cli_result(cli, CLIS_PARAM);
+               return;
+       }
+
+       sb = vsb_newauto();
+       XXXAN(sb);
+       vf = mgt_VccCompileFile(sb, av[3], 0, -1);
+       vsb_finish(sb);
+       AZ(vsb_overflowed(sb));
+       if (vsb_len(sb) > 0)
+               cli_out(cli, "%s", vsb_data(sb));
+       vsb_delete(sb);
+       if (vf == NULL) {
+               cli_out(cli, "VCL compilation failed");
+               cli_result(cli, CLIS_PARAM);
+               return;
+       }
+
+       if (child_pid >= 0 &&
+           mgt_cli_askchild(&status, &p, "vcl.reload %s %s\n", av[2], vf)) {
+               cli_result(cli, status);
+               cli_out(cli, "%s", p);
+       } else {
+               active = vp->active;
+               mgt_vcc_del(vp);
+               vp = mgt_vcc_add(av[2], vf);
+               vp->active = active;
+       }
+       cli_out(cli, "VCL %s reloaded.", av[2]);
+       free(p);
+}
+
 void
 mcf_config_load(struct cli *cli, const char * const *av, void *priv)
 {
index 6c1602c07c3897d19fe4a05b1424fe88780dcf1d..8aa2fa80cea271f5145081188c8216990f7d3a23 100644 (file)
        "\tCompile and load the VCL file under the name provided.",     \
        2, 2
 
+#define CLI_VCL_RELOAD                                                 \
+       "vcl.reload",                                                   \
+       "vcl.reload <configname> <filename>",                           \
+       "\tLoad the VCL file under the name provided, discarding the old VCL",  \
+       2, 2
+
 #define CLI_VCL_INLINE                                                 \
        "vcl.inline",                                                   \
        "vcl.inline <configname> <quoted_VCLstring>",                   \