diff options
author | Pavan Deolasee | 2016-04-12 15:43:22 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-18 10:05:05 +0000 |
commit | 6d45f590e1a9c0737ef8b447c064d00c3765bdee (patch) | |
tree | 4fd8146d3b202ab1446625121aad83e08c6e1e7a | |
parent | 02a8860fa81810e40e93dc9d174a15137404eb5d (diff) |
Avoid removing directories for some pgxc_ctl calls, just as an added protection
if user makes a mistake
-rw-r--r-- | contrib/pgxc_ctl/coord_cmd.c | 20 | ||||
-rw-r--r-- | contrib/pgxc_ctl/datanode_cmd.c | 20 |
2 files changed, 36 insertions, 4 deletions
diff --git a/contrib/pgxc_ctl/coord_cmd.c b/contrib/pgxc_ctl/coord_cmd.c index b612a02385..eb45f77227 100644 --- a/contrib/pgxc_ctl/coord_cmd.c +++ b/contrib/pgxc_ctl/coord_cmd.c @@ -253,6 +253,7 @@ cmd_t *prepare_initCoordinatorSlave(char *nodeName) FILE *f; char localStdin[MAXPATH+1]; char timestamp[MAXTOKEN+1]; + char remoteDirCheck[MAXPATH * 2 + 128]; if ((idx = coordIdx(nodeName)) < 0) { @@ -265,10 +266,25 @@ cmd_t *prepare_initCoordinatorSlave(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 Coordinator slave initilialization'; exit; fi;", + aval(VAR_coordSlaveDirs)[idx], + aval(VAR_coordSlaveDirs)[idx] + ); + } + /* Build work directory */ cmd = cmdBuildDir = initCmd(aval(VAR_coordSlaveServers)[idx]); snprintf(newCommand(cmdBuildDir), MAXLINE, - "rm -rf %s;mkdir -p %s;chmod 0700 %s", + "%s" + "rm -rf %s;" + "mkdir -p %s;" + "chmod 0700 %s", + remoteDirCheck, aval(VAR_coordSlaveDirs)[idx], aval(VAR_coordSlaveDirs)[idx], aval(VAR_coordSlaveDirs)[idx]); /* * Check if the master is running --> May not need change if we have watchdog. This case, we need @@ -1293,7 +1309,7 @@ int add_coordinatorSlave(char *name, char *host, int port, int pooler_port, char snprintf(pooler_s, MAXTOKEN, "%d", pooler_port); /* Prepare the resources (directories) */ - doImmediate(host, NULL, "rm -rf %s; mkdir -p %s;chmod 0700 %s", dir, dir, dir); + doImmediate(host, NULL, "mkdir -p %s;chmod 0700 %s", dir, dir); doImmediate(host, NULL, "rm -rf %s; mkdir -p %s;chmod 0700 %s", archDir, archDir, archDir); /* Reconfigure the master with WAL archive */ /* Update the configuration and backup the configuration file */ diff --git a/contrib/pgxc_ctl/datanode_cmd.c b/contrib/pgxc_ctl/datanode_cmd.c index 838f060c9b..d97b577754 100644 --- a/contrib/pgxc_ctl/datanode_cmd.c +++ b/contrib/pgxc_ctl/datanode_cmd.c @@ -274,6 +274,7 @@ cmd_t *prepare_initDatanodeSlave(char *nodeName) int idx; int startMaster; char timestamp[MAXTOKEN+1]; + char remoteDirCheck[MAXPATH * 2 + 128]; if ((idx = datanodeIdx(nodeName)) < 0) { @@ -292,10 +293,25 @@ cmd_t *prepare_initDatanodeSlave(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 Datanode initilialization'; exit; fi", + aval(VAR_datanodeSlaveDirs)[idx], + aval(VAR_datanodeSlaveDirs)[idx] + ); + } + /* Build slave's directory -1- */ cmd = cmdBuildDir = initCmd(aval(VAR_datanodeSlaveServers)[idx]); snprintf(newCommand(cmdBuildDir), MAXLINE, - "rm -rf %s;mkdir -p %s; chmod 0700 %s", + "%s" + "rm -rf %s;" + "mkdir -p %s;" + "chmod 0700 %s", + remoteDirCheck, aval(VAR_datanodeSlaveDirs)[idx], aval(VAR_datanodeSlaveDirs)[idx], aval(VAR_datanodeSlaveDirs)[idx]); @@ -1347,7 +1363,7 @@ int add_datanodeSlave(char *name, char *host, int port, int pooler, char *dir, return 1; } /* Prepare the resources (directories) */ - doImmediate(host, NULL, "rm -rf %s; mkdir -p %s;chmod 0700 %s", dir, dir, dir); + doImmediate(host, NULL, "mkdir -p %s;chmod 0700 %s", dir, dir); doImmediate(host, NULL, "rm -rf %s; mkdir -p %s;chmod 0700 %s", archDir, archDir, archDir); doImmediate(host, NULL, "rm -rf %s; mkdir -p %s;chmod 0700 %s", walDir, walDir, walDir); |