From ce82d1f18920e089efc8851557c958aeda40bc6d Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 24 May 2012 15:51:25 -0500 Subject: [PATCH] Add ability to recover somewhat from a dead master node --- raptorsmiface/libraptorsmiface.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/raptorsmiface/libraptorsmiface.c b/raptorsmiface/libraptorsmiface.c index ead1fd06..7ea3de09 100644 --- a/raptorsmiface/libraptorsmiface.c +++ b/raptorsmiface/libraptorsmiface.c @@ -103,6 +103,35 @@ char raptor_sm_deallocate_session(char* username) { return 1; } + pid_t serverpid = raptor_sm_get_pid_for_username(username); + if (serverpid >= 0) { + // Verify existence of PID on remote server + dprint("Verifying process %d on %s...\n\r", serverpid, row[1]); + char* ip = raptor_sm_get_ip_for_hostname(row[1], 0); + char* command_string; + asprintf(&command_string, "ssh root@%s \'ps -p %d | grep %d\'", ip, serverpid, serverpid); + FILE *fp; + char output[1024]; + // Open the command for reading + fp = popen(command_string, "r"); + if (fp == NULL) { + mysql_close(conn); + return -1; + } + // Read the output a line at a time + fgets(output, sizeof(output)-1, fp); + // Close output + pclose(fp); + free(command_string); + free(ip); + dprint("...result was %s\n\r", output); + if (strcmp(output, "") != 0) { + mysql_free_result(res); + mysql_close(conn); + return 0; + } + } + // Remove the user from the system char* safe_username = get_mysql_escaped_string(conn, username); asprintf(&query, "DELETE FROM sessions WHERE username='%s'", safe_username);