Fix broken stopfile logic

'start' command removes stopfile just before starting
'stop' command removes stopfile after stopping
This commit is contained in:
Andrew Bettison 2012-05-08 12:53:59 +09:30
parent 329189ec8c
commit 391e8d7056
3 changed files with 20 additions and 6 deletions

View File

@ -570,6 +570,8 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti
instance directory when it starts up. instance directory when it starts up.
We can just become the server process ourselves --- no need to fork. We can just become the server process ourselves --- no need to fork.
*/ */
if (server_remove_stopfile() == -1)
return -1;
rhizome_datastore_path = serval_instancepath(); rhizome_datastore_path = serval_instancepath();
rhizome_opendb(); rhizome_opendb();
overlayMode = 1; overlayMode = 1;
@ -678,6 +680,7 @@ int app_server_stop(int argc, const char *const *argv, struct command_line_optio
nanosleep(&delay, NULL); nanosleep(&delay, NULL);
} while ((running = server_pid()) == pid && overlay_gettime_ms() < timeout); } while ((running = server_pid()) == pid && overlay_gettime_ms() < timeout);
} }
server_remove_stopfile();
cli_puts("tries"); cli_puts("tries");
cli_delim(":"); cli_delim(":");
cli_printf("%d", tries); cli_printf("%d", tries);

View File

@ -400,6 +400,7 @@ int server_pid();
int server(char *backing_file); int server(char *backing_file);
void server_shutdown_check(); void server_shutdown_check();
int server_create_stopfile(); int server_create_stopfile();
int server_remove_stopfile();
int server_check_stopfile(); int server_check_stopfile();
void serverCleanUp(); void serverCleanUp();
int isTransactionInCache(unsigned char *transaction_id); int isTransactionInCache(unsigned char *transaction_id);

View File

@ -212,11 +212,24 @@ int server_create_stopfile()
return -1; return -1;
FILE *f; FILE *f;
if ((f = fopen(stopfile, "w")) == NULL) if ((f = fopen(stopfile, "w")) == NULL)
return WHYF("Could not create stopfile '%s'", stopfile); return WHYF("Could not create stopfile '%s': %s [errno=%d]", stopfile, strerror(errno), errno);
fclose(f); fclose(f);
return 0; return 0;
} }
int server_remove_stopfile()
{
char stopfile[1024];
if (!FORM_SERVAL_INSTANCE_PATH(stopfile, STOPFILE_NAME))
return -1;
if (unlink(stopfile) == -1) {
if (errno == ENOENT)
return 0;
return WHYF("Could not unlink stopfile '%s': %s [errno=%d]", stopfile, strerror(errno), errno);
}
return 1;
}
int server_check_stopfile() int server_check_stopfile()
{ {
char stopfile[1024]; char stopfile[1024];
@ -234,13 +247,10 @@ int server_check_stopfile()
void serverCleanUp() void serverCleanUp()
{ {
/* Try to remove shutdown and PID files and exit */ /* Try to remove shutdown and PID files and exit */
server_remove_stopfile();
char filename[1024]; char filename[1024];
if (FORM_SERVAL_INSTANCE_PATH(filename, STOPFILE_NAME)) { if (FORM_SERVAL_INSTANCE_PATH(filename, PIDFILE_NAME))
unlink(filename); unlink(filename);
}
if (FORM_SERVAL_INSTANCE_PATH(filename, PIDFILE_NAME)) {
unlink(filename);
}
if (mdp_client_socket==-1) { if (mdp_client_socket==-1) {
if (FORM_SERVAL_INSTANCE_PATH(filename, "mdp.socket")) { if (FORM_SERVAL_INSTANCE_PATH(filename, "mdp.socket")) {
unlink(filename); unlink(filename);