pgpool2.git / summary / log / commit / refs

commit    9896acb459e0c8a377604d5c6ba5f13d172e91c3
Author:   at.mitani <at.mitani@gmail.com>
Date:     Thu Jul 12 05:40:31 2012 +0000

    Merged watchdog branch with master.


doc/wd-en.html | 7 ++++++ doc/wd-ja.html | 7 ++++++ main.c | 17 +++++++++++++- pgpool.conf | 2 ++ pgpool.conf.sample | 2 ++ pgpool.conf.sample-master-slave | 2 ++ pgpool.conf.sample-replication | 2 ++ pgpool.conf.sample-stream | 2 ++ pool_config.c | 52 ++++++++++++++++++++++++++++++++++------- pool_config.h | 1 + pool_config.l | 52 ++++++++++++++++++++++++++++++++++------- watchdog/wd_init.c | 2 +- watchdog/wd_packet.c | 2 +- 13 files changed, 129 insertions(+), 21 deletions(-) diff --git a/doc/wd-en.html b/doc/wd-en.html index 1fcbb26f7..1c017f8cc 100644 --- a/doc/wd-en.html +++ b/doc/wd-en.html @@ -104,6 +104,13 @@ If on, activates watchdog. Default is off. </p> </dd> +<dt><a name="WD_HOSTNAME"></a>wd_hostname</dt> +<dd> +<p> + Specifies the hostname or IP address for mutual monitoring of watchdog processes. +</p> +</dd> + <dt><a name="WD_PORT"></a>wd_port</dt> <dd> <p> diff --git a/doc/wd-ja.html b/doc/wd-ja.html index 962dae334..031b3b68c 100644 --- a/doc/wd-ja.html +++ b/doc/wd-ja.html @@ -93,6 +93,13 @@ root権限で </p> </dd> +<dt><a name="WD_HOSTNAME"></a>wd_hostname</dt> +<dd> +<p> + watchdogプロセスが相互監視を受信する為のホスト名またはIPアドレスです。 +</p> +</dd> + <dt><a name="WD_PORT"></a>wd_port</dt> <dd> <p> diff --git a/main.c b/main.c index 32cb77b18..3a2ea6ac4 100644 --- a/main.c +++ b/main.c @@ -35,6 +35,7 @@ #endif #include <sys/stat.h> +#include <sys/types.h> #include <fcntl.h> #include <sys/wait.h> @@ -610,7 +611,21 @@ int main(int argc, char **argv) } /* start watchdog */ - watchdog_pid = wd_main(1); + if (pool_config->use_watchdog ) + { + /* check root */ + if (geteuid() != 0) + { + pool_error("watchdog must be started under the privileged user ID to up/down virtual network interface."); + myexit(1); + } + watchdog_pid = wd_main(1); + if (watchdog_pid == 0) + { + pool_error("wd_main error"); + myexit(1); + } + } /* * We need to block signal here. Otherwise child might send some diff --git a/pgpool.conf b/pgpool.conf index eb0b1d8a8..303ecf3c4 100644 --- a/pgpool.conf +++ b/pgpool.conf @@ -429,6 +429,8 @@ trusted_servers = '192.168.122.1' # (hostA,hostB,hostC,...) delegate_IP = '192.168.122.80' # delegate IP address +wd_hostname = 'vm1' + # Host name or IP address of this watchdog wd_port = 9000 # port number for watchdog service wd_interval = 10 diff --git a/pgpool.conf.sample b/pgpool.conf.sample index 157eb7f2c..43e1e53ae 100644 --- a/pgpool.conf.sample +++ b/pgpool.conf.sample @@ -429,6 +429,8 @@ trusted_servers = '' # (hostA,hostB,hostC,...) delegate_IP = '' # delegate IP address +wd_hostname = '' + # Host name or IP address of this watchdog wd_port = 9000 # port number for watchdog service wd_interval = 10 diff --git a/pgpool.conf.sample-master-slave b/pgpool.conf.sample-master-slave index c22dd7643..2228232b8 100644 --- a/pgpool.conf.sample-master-slave +++ b/pgpool.conf.sample-master-slave @@ -425,6 +425,8 @@ trusted_servers = '' # (hostA,hostB,hostC,...) delegate_IP = '' # delegate IP address +wd_hostname = '' + # Host name or IP address of this watchdog wd_port = 9000 # port number for watchdog service wd_interval = 10 diff --git a/pgpool.conf.sample-replication b/pgpool.conf.sample-replication index 9756c35fc..fc798b4f9 100644 --- a/pgpool.conf.sample-replication +++ b/pgpool.conf.sample-replication @@ -424,6 +424,8 @@ trusted_servers = '' # (hostA,hostB,hostC,...) delegate_IP = '' # delegate IP address +wd_hostname = '' + # Host name or IP address of this watchdog wd_port = 9000 # port number for watchdog service wd_interval = 10 diff --git a/pgpool.conf.sample-stream b/pgpool.conf.sample-stream index 399ba0412..140acb52e 100644 --- a/pgpool.conf.sample-stream +++ b/pgpool.conf.sample-stream @@ -424,6 +424,8 @@ trusted_servers = '' # (hostA,hostB,hostC,...) delegate_IP = '' # delegate IP address +wd_hostname = '' + # Host name or IP address of this watchdog wd_port = 9000 # port number for watchdog service wd_interval = 10 diff --git a/pool_config.c b/pool_config.c index 45c4ec896..ebfbfb621 100644 --- a/pool_config.c +++ b/pool_config.c @@ -1960,6 +1960,12 @@ int pool_init_config(void) pool_config->use_watchdog = 0; pool_config->trusted_servers = NULL; pool_config->delegate_IP = NULL; + res = gethostname(localhostname,sizeof(localhostname)); + if(res !=0 ) + { + pool_debug("faild to get this hostname"); + } + pool_config->wd_hostname = localhostname; pool_config->wd_port = 9000; pool_config->other_wd->num_wd = 0; pool_config->wd_interval = 10; @@ -3694,7 +3700,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->trusted_servers = str; + if(strlen(str)) + pool_config->trusted_servers = str; } else if (!strcmp(key, "delegate_IP") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -3712,7 +3719,27 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->delegate_IP = str; + if(strlen(str)) + pool_config->delegate_IP = str; + } + else if (!strcmp(key, "wd_hostname") && CHECK_CONTEXT(INIT_CONFIG, context)) + { + char *str; + + if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY) + { + PARSE_ERROR(); + fclose(fd); + return(-1); + } + str = extract_string(yytext, token); + if (str == NULL) + { + fclose(fd); + return(-1); + } + if(strlen(str)) + pool_config->wd_hostname = str; } else if (!strcmp(key, "wd_port") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -3754,7 +3781,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->ping_path = str; + if(strlen(str)) + pool_config->ping_path = str; } else if (!strcmp(key, "ifconfig_path") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -3772,7 +3800,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->ifconfig_path = str; + if(strlen(str)) + pool_config->ifconfig_path = str; } else if (!strcmp(key, "if_up_cmd") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -3790,7 +3819,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->if_up_cmd = str; + if(strlen(str)) + pool_config->if_up_cmd = str; } else if (!strcmp(key, "if_down_cmd") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -3808,7 +3838,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->if_down_cmd = str; + if(strlen(str)) + pool_config->if_down_cmd = str; } else if (!strcmp(key, "arping_path") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -3826,7 +3857,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->arping_path = str; + if(strlen(str)) + pool_config->arping_path = str; } else if (!strcmp(key, "arping_cmd") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -3844,7 +3876,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->arping_cmd = str; + if(strlen(str)) + pool_config->arping_cmd = str; } else if (!strcmp(key, "wd_life_point") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -3874,7 +3907,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->wd_lifecheck_query = str; + if(strlen(str)) + pool_config->wd_lifecheck_query = str; } diff --git a/pool_config.h b/pool_config.h index 4321d1c04..9f91ef4c5 100644 --- a/pool_config.h +++ b/pool_config.h @@ -220,6 +220,7 @@ typedef struct { * add for watchdog */ int use_watchdog; /* if non 0, use watchdog */ + char *wd_hostname; /* watchdog hostname */ int wd_port; /* watchdog port */ WdDesc * other_wd; /* watchdog lists */ char * trusted_servers; /* icmp reachable server list (A,B,C) */ diff --git a/pool_config.l b/pool_config.l index abb75bdc0..e59b4f946 100644 --- a/pool_config.l +++ b/pool_config.l @@ -235,6 +235,12 @@ int pool_init_config(void) pool_config->use_watchdog = 0; pool_config->trusted_servers = NULL; pool_config->delegate_IP = NULL; + res = gethostname(localhostname,sizeof(localhostname)); + if(res !=0 ) + { + pool_debug("faild to get this hostname"); + } + pool_config->wd_hostname = localhostname; pool_config->wd_port = 9000; pool_config->other_wd->num_wd = 0; pool_config->wd_interval = 10; @@ -1969,7 +1975,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->trusted_servers = str; + if(strlen(str)) + pool_config->trusted_servers = str; } else if (!strcmp(key, "delegate_IP") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -1987,7 +1994,27 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->delegate_IP = str; + if(strlen(str)) + pool_config->delegate_IP = str; + } + else if (!strcmp(key, "wd_hostname") && CHECK_CONTEXT(INIT_CONFIG, context)) + { + char *str; + + if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY) + { + PARSE_ERROR(); + fclose(fd); + return(-1); + } + str = extract_string(yytext, token); + if (str == NULL) + { + fclose(fd); + return(-1); + } + if(strlen(str)) + pool_config->wd_hostname = str; } else if (!strcmp(key, "wd_port") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -2029,7 +2056,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->ping_path = str; + if(strlen(str)) + pool_config->ping_path = str; } else if (!strcmp(key, "ifconfig_path") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -2047,7 +2075,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->ifconfig_path = str; + if(strlen(str)) + pool_config->ifconfig_path = str; } else if (!strcmp(key, "if_up_cmd") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -2065,7 +2094,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->if_up_cmd = str; + if(strlen(str)) + pool_config->if_up_cmd = str; } else if (!strcmp(key, "if_down_cmd") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -2083,7 +2113,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->if_down_cmd = str; + if(strlen(str)) + pool_config->if_down_cmd = str; } else if (!strcmp(key, "arping_path") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -2101,7 +2132,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->arping_path = str; + if(strlen(str)) + pool_config->arping_path = str; } else if (!strcmp(key, "arping_cmd") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -2119,7 +2151,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->arping_cmd = str; + if(strlen(str)) + pool_config->arping_cmd = str; } else if (!strcmp(key, "wd_life_point") && CHECK_CONTEXT(INIT_CONFIG, context)) { @@ -2149,7 +2182,8 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) fclose(fd); return(-1); } - pool_config->wd_lifecheck_query = str; + if(strlen(str)) + pool_config->wd_lifecheck_query = str; } diff --git a/watchdog/wd_init.c b/watchdog/wd_init.c index f1f63b31d..4f3cb8415 100644 --- a/watchdog/wd_init.c +++ b/watchdog/wd_init.c @@ -65,7 +65,7 @@ wd_init(void) memset(WD_Node_List, 0, sizeof(unsigned char) * MAX_NUM_BACKENDS); } /* set myself to watchdog list */ - wd_set_wd_list(pool_config->pgpool2_hostname, pool_config->port, pool_config->wd_port, &tv, WD_NORMAL); + wd_set_wd_list(pool_config->wd_hostname, pool_config->port, pool_config->wd_port, &tv, WD_NORMAL); /* set other pgpools to watchdog list */ wd_add_wd_list(pool_config->other_wd); diff --git a/watchdog/wd_packet.c b/watchdog/wd_packet.c index a39631ffc..1d2887a52 100644 --- a/watchdog/wd_packet.c +++ b/watchdog/wd_packet.c @@ -757,7 +757,7 @@ wd_escalation(void) /* interface up as delegate IP */ wd_IP_up(); /* set master status to the wd list */ - wd_set_wd_list(pool_config->pgpool2_hostname, pool_config->port, pool_config->wd_port, NULL, WD_MASTER); + wd_set_wd_list(pool_config->wd_hostname, pool_config->port, pool_config->wd_port, NULL, WD_MASTER); /* send declare packet */ rtn = wd_declare(); [parent: b2cb770be96b]