dovecot-2.0: doveadm: Added "director dump" command.
dovecot at dovecot.org
dovecot at dovecot.org
Tue May 3 19:41:24 EEST 2011
details: http://hg.dovecot.org/dovecot-2.0/rev/c838d40bd38e
changeset: 12764:c838d40bd38e
user: Timo Sirainen <tss at iki.fi>
date: Tue May 03 18:41:10 2011 +0200
description:
doveadm: Added "director dump" command.
It outputs doveadm director commands to add/remove the current host
configuration, so if all directors are stopped, their state can be easily
restored by running the commands.
diffstat:
src/director/doveadm-connection.c | 40 +++++++++++++++++++++++++++++++
src/doveadm/doveadm-director.c | 50 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 89 insertions(+), 1 deletions(-)
diffs (138 lines):
diff -r 036260ae0261 -r c838d40bd38e src/director/doveadm-connection.c
--- a/src/director/doveadm-connection.c Tue May 03 09:58:11 2011 +0200
+++ b/src/director/doveadm-connection.c Tue May 03 18:41:10 2011 +0200
@@ -53,6 +53,44 @@
o_stream_send(conn->output, str_data(str), str_len(str));
}
+static void doveadm_cmd_host_list_removed(struct doveadm_connection *conn)
+{
+ struct mail_host_list *orig_hosts_list;
+ struct mail_host *const *orig_hosts, *const *cur_hosts;
+ unsigned int i, j, orig_hosts_count, cur_hosts_count;
+ string_t *str = t_str_new(1024);
+ int ret;
+
+ orig_hosts_list = mail_hosts_init();
+ (void)mail_hosts_parse_and_add(orig_hosts_list,
+ conn->dir->set->director_mail_servers);
+
+ orig_hosts = array_get(mail_hosts_get(orig_hosts_list),
+ &orig_hosts_count);
+ cur_hosts = array_get(mail_hosts_get(conn->dir->mail_hosts),
+ &cur_hosts_count);
+
+ /* the hosts are sorted by IP */
+ for (i = j = 0; i < orig_hosts_count && j < cur_hosts_count; ) {
+ ret = net_ip_cmp(&orig_hosts[i]->ip, &cur_hosts[j]->ip);
+ if (ret == 0)
+ i++, j++;
+ else if (ret > 0)
+ j++;
+ else {
+ str_printfa(str, "%s\n",
+ net_ip2addr(&orig_hosts[i]->ip));
+ i++;
+ }
+ }
+ for (; i < orig_hosts_count; i++)
+ str_printfa(str, "%s\n", net_ip2addr(&orig_hosts[i]->ip));
+ str_append_c(str, '\n');
+ o_stream_send(conn->output, str_data(str), str_len(str));
+
+ mail_hosts_deinit(&orig_hosts_list);
+}
+
static void doveadm_cmd_director_list(struct doveadm_connection *conn)
{
struct director_host *const *hostp;
@@ -263,6 +301,8 @@
if (strcmp(cmd, "HOST-LIST") == 0)
doveadm_cmd_host_list(conn);
+ else if (strcmp(cmd, "HOST-LIST-REMOVED") == 0)
+ doveadm_cmd_host_list_removed(conn);
else if (strcmp(cmd, "DIRECTOR-LIST") == 0)
doveadm_cmd_director_list(conn);
else if (strcmp(cmd, "HOST-SET") == 0)
diff -r 036260ae0261 -r c838d40bd38e src/doveadm/doveadm-director.c
--- a/src/doveadm/doveadm-director.c Tue May 03 09:58:11 2011 +0200
+++ b/src/doveadm/doveadm-director.c Tue May 03 18:41:10 2011 +0200
@@ -20,6 +20,7 @@
const char *socket_path;
const char *users_path;
struct istream *input;
+ bool explicit_socket_path;
};
struct user_list {
@@ -91,6 +92,7 @@
switch (c) {
case 'a':
ctx->socket_path = optarg;
+ ctx->explicit_socket_path = TRUE;
break;
case 'f':
ctx->users_path = optarg;
@@ -465,6 +467,50 @@
director_disconnect(ctx);
}
+static void ATTR_FORMAT(3, 4)
+director_dump_cmd(struct director_context *ctx,
+ const char *cmd, const char *args, ...)
+{
+ va_list va;
+
+ va_start(va, args);
+ printf("doveadm director %s ", cmd);
+ if (ctx->explicit_socket_path)
+ printf("-a %s ", ctx->socket_path);
+ vprintf(args, va);
+ putchar('\n');
+ va_end(va);
+}
+
+static void cmd_director_dump(int argc, char *argv[])
+{
+ struct director_context *ctx;
+ const char *line, *const *args;
+
+ ctx = cmd_director_init(argc, argv, "a:", cmd_director_dump);
+
+ director_send(ctx, "HOST-LIST\n");
+ while ((line = i_stream_read_next_line(ctx->input)) != NULL) {
+ if (*line == '\0')
+ break;
+ T_BEGIN {
+ args = t_strsplit(line, "\t");
+ if (str_array_length(args) >= 2) {
+ director_dump_cmd(ctx, "add", "%s %s",
+ args[0], args[1]);
+ }
+ } T_END;
+ }
+
+ director_send(ctx, "HOST-LIST-REMOVED\n");
+ while ((line = i_stream_read_next_line(ctx->input)) != NULL) {
+ if (*line == '\0')
+ break;
+ director_dump_cmd(ctx, "remove", "%s", line);
+ }
+ director_disconnect(ctx);
+}
+
struct doveadm_cmd doveadm_cmd_director[] = {
{ cmd_director_status, "director status",
"[-a <director socket path>] [<user>]" },
@@ -475,7 +521,9 @@
{ cmd_director_remove, "director remove",
"[-a <director socket path>] <host>" },
{ cmd_director_flush, "director flush",
- "[-a <director socket path>] <host>|all" }
+ "[-a <director socket path>] <host>|all" },
+ { cmd_director_dump, "director dump",
+ "[-a <director socket path>]" }
};
static void director_cmd_help(doveadm_command_t *cmd)
More information about the dovecot-cvs
mailing list