mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 15:16:29 +00:00
Add test_ssh_connection
The feature was written by Jaime and reworked by me to fix https://github.com/greg2ndQuadrant/repmgr/issues/5
This commit is contained in:
committed by
Jaime Casanova
parent
17a160e970
commit
6e9e4e05ae
1
HISTORY
1
HISTORY
@@ -37,6 +37,7 @@
|
||||
Improve performance of repl_status view (Jaime)
|
||||
|
||||
1.2.0 2012-04-28
|
||||
Test ssh connection before trying to rsync (Cédric)
|
||||
Add CLUSTER SHOW command (Carlo Ascani)
|
||||
Add CLUSTER CLEANUP command (Jaime)
|
||||
Add function write_primary_conninfo (Marco Nenciarini)
|
||||
|
||||
28
repmgr.c
28
repmgr.c
@@ -50,6 +50,7 @@
|
||||
|
||||
static void help(const char *progname);
|
||||
static bool create_recovery_file(const char *data_dir, char *master_conninfo);
|
||||
static int test_ssh_connection(char *host, char *remote_user);
|
||||
static int copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||
char *local_path, bool is_directory);
|
||||
static bool check_parameters_for_action(const int action);
|
||||
@@ -1007,6 +1008,15 @@ do_standby_clone(void)
|
||||
}
|
||||
}
|
||||
|
||||
r = test_ssh_connection(runtime_options.host, runtime_options.remote_user);
|
||||
if (r != 0)
|
||||
{
|
||||
log_err(_("%s: Aborting, remote host %s is not reachable.\n"), progname, runtime_options.host);
|
||||
PQclear(res);
|
||||
PQfinish(conn);
|
||||
exit(ERR_DB_CON);
|
||||
}
|
||||
|
||||
log_notice("Starting backup...\n");
|
||||
|
||||
/* Get the data directory full path and the configuration files location */
|
||||
@@ -1564,6 +1574,24 @@ create_recovery_file(const char *data_dir, char *master_conninfo)
|
||||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
test_ssh_connection(char *host, char *remote_user)
|
||||
{
|
||||
char script[MAXLEN];
|
||||
int r;
|
||||
|
||||
/* Check if we have ssh connectivity to host before trying to rsync */
|
||||
if (!remote_user[0])
|
||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s /bin/true", host);
|
||||
else
|
||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s -l %s /bin/true", host, remote_user);
|
||||
|
||||
log_debug(_("command is: %s"), script);
|
||||
r = system(script);
|
||||
if (r != 0)
|
||||
log_info(_("Can not connect to the remote host (%s)\n"), host);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||
|
||||
Reference in New Issue
Block a user