summaryrefslogtreecommitdiff
path: root/src/biruda.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-11-30 16:42:35 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-11-30 16:42:35 +0100
commit55f9c3d2f3320917dba48c4c532c54483a0bce2b (patch)
treed28cac3ffca7e4467390149f15073d0530e730c8 /src/biruda.c
parent1cb35fad9924bfa1ae33a6e6aff2e6c5d5b5f454 (diff)
downloadbiruda-55f9c3d2f3320917dba48c4c532c54483a0bce2b.tar.gz
biruda-55f9c3d2f3320917dba48c4c532c54483a0bce2b.tar.bz2
updating worker state now in master from coordinator state messages
Diffstat (limited to 'src/biruda.c')
-rw-r--r--src/biruda.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/biruda.c b/src/biruda.c
index 3c108cb..ce49544 100644
--- a/src/biruda.c
+++ b/src/biruda.c
@@ -256,7 +256,8 @@ static void terminate_foreground_func( int sig )
typedef enum {
COMMAND, // command parsing
- WORKER_PARAM // worker command expecting a worker parameter
+ START_WORKER, // worker command expecting a worker parameter
+ STOP_WORKER
} command_state_t;
static char *commands[] = {
@@ -341,7 +342,8 @@ static void completion_func( const char *buf, linenoiseCompletions *lc )
}
break;
- case WORKER_PARAM:
+ case START_WORKER:
+ case STOP_WORKER:
get_workers( );
for( int i = 0; i < nof_worker_names; i++ ) {
linenoiseAddCompletion( lc, worker_names[i] );
@@ -423,6 +425,18 @@ static void start_worker( const char *worker_name )
}
}
+static void stop_worker( const char *worker_name )
+{
+ char url[128];
+ snprintf( url, sizeof( url ), "worker?op=stop&name=%s", worker_name );
+ http_retcode ret = http_post( url, "", 0, "Content-Type: text/plain" );
+ if( ret == 200 ) {
+ print_answer( "Request queued" );
+ } else {
+ print_error( "ERROR: HTTP error %d", ret );
+ }
+}
+
static int start_interactive( bool colors )
{
char history_filename[1024];
@@ -454,7 +468,8 @@ static int start_interactive( bool colors )
context = "biruda";
break;
- case WORKER_PARAM:
+ case START_WORKER:
+ case STOP_WORKER:
context = "worker";
break;
}
@@ -468,7 +483,8 @@ static int start_interactive( bool colors )
free( line );
return EXIT_SUCCESS;
- case WORKER_PARAM:
+ case START_WORKER:
+ case STOP_WORKER:
command_state = COMMAND;
continue;
}
@@ -508,16 +524,23 @@ static int start_interactive( bool colors )
} else if( strncasecmp( line, "status", 6 ) == 0 ) {
print_status( );
} else if( strncasecmp( line, "start", 5 ) == 0 ) {
- command_state = WORKER_PARAM;
+ command_state = START_WORKER;
+ } else if( strncasecmp( line, "stop", 5 ) == 0 ) {
+ command_state = STOP_WORKER;
} else {
print_error( "Bad command '%s'.", line );
}
break;
- case WORKER_PARAM:
+ case START_WORKER:
start_worker( line );
command_state = COMMAND;
break;
+
+ case STOP_WORKER:
+ stop_worker( line );
+ command_state = COMMAND;
+ break;
}
}