summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavan Deolasee2016-06-14 06:22:13 +0000
committerPavan Deolasee2016-10-18 10:05:08 +0000
commit1eee97d47ffedabcc7928187814a2a5492dced48 (patch)
treeb4b95138516d41f9526138f280c0267bc5ad18a9
parent8ac140524d964573e76f2c830a99288642c3d3d5 (diff)
Ensure "init all" (and other init commands too) does not remove existing data
directories unless "force" option is used We'd tried to fix this earlier, but looks like double quote is not getting passed to the shell correctly. Instead use a single quote. Report by Pallavi Sontakke during QA testing.
-rw-r--r--contrib/pgxc_ctl/coord_cmd.c8
-rw-r--r--contrib/pgxc_ctl/datanode_cmd.c17
-rw-r--r--contrib/pgxc_ctl/gtm_cmd.c20
3 files changed, 30 insertions, 15 deletions
diff --git a/contrib/pgxc_ctl/coord_cmd.c b/contrib/pgxc_ctl/coord_cmd.c
index aa68a9aed5..ec69a35760 100644
--- a/contrib/pgxc_ctl/coord_cmd.c
+++ b/contrib/pgxc_ctl/coord_cmd.c
@@ -82,9 +82,9 @@ cmd_t *prepare_initCoordinatorMaster(char *nodeName)
remoteDirCheck[0] = '\0';
if (!forceInit)
{
- sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: "
+ sprintf(remoteDirCheck, "if [ '$(ls -A %s 2> /dev/null)' ]; then echo 'ERROR: "
"target directory (%s) exists and not empty. "
- "Skip Coordinator initilialization'; exit; fi",
+ "Skip Coordinator initilialization'; exit; fi;",
aval(VAR_coordMasterDirs)[jj],
aval(VAR_coordMasterDirs)[jj]
);
@@ -92,7 +92,7 @@ cmd_t *prepare_initCoordinatorMaster(char *nodeName)
cmd = cmdInitdb = initCmd(aval(VAR_coordMasterServers)[jj]);
snprintf(newCommand(cmdInitdb), MAXLINE,
- "%s;"
+ "%s"
"rm -rf %s;"
"mkdir -p %s;"
"PGXC_CTL_SILENT=1 initdb --nodename %s -D %s",
@@ -269,7 +269,7 @@ cmd_t *prepare_initCoordinatorSlave(char *nodeName)
remoteDirCheck[0] = '\0';
if (!forceInit)
{
- sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: "
+ sprintf(remoteDirCheck, "if [ '$(ls -A %s 2> /dev/null)' ]; then echo 'ERROR: "
"target directory (%s) exists and not empty. "
"Skip Coordinator slave initilialization'; exit; fi;",
aval(VAR_coordSlaveDirs)[idx],
diff --git a/contrib/pgxc_ctl/datanode_cmd.c b/contrib/pgxc_ctl/datanode_cmd.c
index 109c0f5a06..dff0001e76 100644
--- a/contrib/pgxc_ctl/datanode_cmd.c
+++ b/contrib/pgxc_ctl/datanode_cmd.c
@@ -65,6 +65,7 @@ cmd_t *prepare_initDatanodeMaster(char *nodeName)
FILE *f;
char timeStamp[MAXTOKEN+1];
char remoteDirCheck[MAXPATH * 2 + 128];
+ char remoteWalDirCheck[MAXPATH * 2 + 128];
bool wal;
if ((idx = datanodeIdx(nodeName)) < 0)
@@ -78,19 +79,20 @@ cmd_t *prepare_initDatanodeMaster(char *nodeName)
wal = false;
remoteDirCheck[0] = '\0';
+ remoteWalDirCheck[0] = '\0';
if (!forceInit)
{
- sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: "
+ sprintf(remoteDirCheck, "if [ '$(ls -A %s 2> /dev/null)' ]; then echo 'ERROR: "
"target directory (%s) exists and not empty. "
- "Skip Datanode initilialization'; exit; fi",
+ "Skip Datanode initilialization'; exit; fi;",
aval(VAR_datanodeMasterDirs)[idx],
aval(VAR_datanodeMasterDirs)[idx]
);
if (wal)
{
- sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: "
+ sprintf(remoteWalDirCheck, "if [ '$(ls -A %s 2> /dev/null)' ]; then echo 'ERROR: "
"target directory (%s) exists and not empty. "
- "Skip Datanode initilialization'; exit; fi",
+ "Skip Datanode initilialization'; exit; fi;",
aval(VAR_datanodeMasterWALDirs)[idx],
aval(VAR_datanodeMasterWALDirs)[idx]
);
@@ -101,10 +103,11 @@ cmd_t *prepare_initDatanodeMaster(char *nodeName)
/* Build each datanode's initialize command */
cmd = cmdInitdb = initCmd(aval(VAR_datanodeMasterServers)[idx]);
snprintf(newCommand(cmdInitdb), MAXLINE,
- "%s;"
+ "%s %s"
"rm -rf %s;"
"mkdir -p %s; PGXC_CTL_SILENT=1 initdb --nodename %s %s %s -D %s",
remoteDirCheck,
+ remoteWalDirCheck,
aval(VAR_datanodeMasterDirs)[idx], aval(VAR_datanodeMasterDirs)[idx],
aval(VAR_datanodeNames)[idx],
wal ? "-X" : "",
@@ -296,9 +299,9 @@ cmd_t *prepare_initDatanodeSlave(char *nodeName)
remoteDirCheck[0] = '\0';
if (!forceInit)
{
- sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: "
+ sprintf(remoteDirCheck, "if [ '$(ls -A %s 2> /dev/null)' ]; then echo 'ERROR: "
"target directory (%s) exists and not empty. "
- "Skip Datanode initilialization'; exit; fi",
+ "Skip Datanode initilialization'; exit; fi;",
aval(VAR_datanodeSlaveDirs)[idx],
aval(VAR_datanodeSlaveDirs)[idx]
);
diff --git a/contrib/pgxc_ctl/gtm_cmd.c b/contrib/pgxc_ctl/gtm_cmd.c
index 3994bda73a..8371e101c0 100644
--- a/contrib/pgxc_ctl/gtm_cmd.c
+++ b/contrib/pgxc_ctl/gtm_cmd.c
@@ -58,9 +58,9 @@ cmd_t *prepare_initGtmMaster(bool stop)
remoteDirCheck[0] = '\0';
if (!forceInit)
{
- sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: "
+ sprintf(remoteDirCheck, "set -x; if [ '$(ls -A %s 2> /dev/null)' ]; then echo 'ERROR: "
"target directory (%s) exists and not empty. "
- "Skip GTM initilialization'; exit; fi",
+ "Skip GTM initilialization'; exit; fi;",
sval(VAR_gtmMasterDir),
sval(VAR_gtmMasterDir)
);
@@ -69,7 +69,7 @@ cmd_t *prepare_initGtmMaster(bool stop)
/* Kill current gtm, bild work directory and run initgtm */
cmdInitGtmMaster = initCmd(sval(VAR_gtmMasterServer));
snprintf(newCommand(cmdInitGtmMaster), MAXLINE,
- "%s;"
+ "%s"
"[ -f %s/gtm.pid ] && gtm_ctl -D %s -m immediate -Z gtm stop;"
"rm -rf %s;"
"mkdir -p %s;"
@@ -567,7 +567,6 @@ cmd_t *prepare_stopGtmMaster(void)
cmdGtmCtl = initCmd(sval(VAR_gtmMasterServer));
snprintf(newCommand(cmdGtmCtl), MAXLINE,
"gtm_ctl stop -Z gtm -D %s",
- sval(VAR_gtmMasterDir),
sval(VAR_gtmMasterDir));
return(cmdGtmCtl);
}
@@ -1043,6 +1042,7 @@ cmd_t *prepare_initGtmProxy(char *nodeName)
FILE *f;
char timestamp[MAXTOKEN+1];
char **fileList = NULL;
+ char remoteDirCheck[MAXPATH * 2 + 128];
if ((idx = gtmProxyIdx(nodeName)) < 0)
{
@@ -1050,13 +1050,25 @@ cmd_t *prepare_initGtmProxy(char *nodeName)
return NULL;
}
+ remoteDirCheck[0] = '\0';
+ if (!forceInit)
+ {
+ sprintf(remoteDirCheck, "if [ '$(ls -A %s 2> /dev/null)' ]; then echo 'ERROR: "
+ "target directory (%s) exists and not empty. "
+ "Skip GTM proxy initilialization'; exit; fi;",
+ aval(VAR_gtmProxyDirs)[idx],
+ aval(VAR_gtmProxyDirs)[idx]);
+ }
+
/* Build directory and run initgtm */
cmdInitGtm = initCmd(aval(VAR_gtmProxyServers)[idx]);
snprintf(newCommand(cmdInitGtm), MAXLINE,
+ "%s"
"[ -f %s/gtm_proxy.pid ] && gtm_ctl -D %s -m immediate -Z gtm_proxy stop;"
"rm -rf %s;"
"mkdir -p %s;"
"PGXC_CTL_SILENT=1 initgtm -Z gtm_proxy -D %s",
+ remoteDirCheck,
aval(VAR_gtmProxyDirs)[idx],
aval(VAR_gtmProxyDirs)[idx],
aval(VAR_gtmProxyDirs)[idx],