diff --git a/spectrum_manager/src/main.cpp b/spectrum_manager/src/main.cpp index 847ae648..ee1a7997 100644 --- a/spectrum_manager/src/main.cpp +++ b/spectrum_manager/src/main.cpp @@ -185,7 +185,7 @@ int main(int argc, char **argv) elapsed = 1000000.0 * (td_end.tv_sec -td_start.tv_sec); \ elapsed += (td_end.tv_usec - td_start.tv_usec); \ elapsed = elapsed / 1000 / 1000; \ - std::cout << "Response received after " << (elapsed) << " seconds\n"; +// std::cout << "Response received after " << (elapsed) << " seconds\n"; } } } diff --git a/spectrum_manager/src/methods.cpp b/spectrum_manager/src/methods.cpp index c3785c21..aa133f6b 100644 --- a/spectrum_manager/src/methods.cpp +++ b/spectrum_manager/src/methods.cpp @@ -176,10 +176,12 @@ void start_instances(ManagerConfig *config, const std::string &_jid) { int pid = isRunning(CONFIG_STRING(&vhostCfg, "service.pidfile")); if (pid == 0) { + response = "Starting " + itr->path().string() + ": OK\n"; std::cout << "Starting " << itr->path() << ": OK\n"; exec_(spectrum2_binary, itr->path().string(), vhost); } else { + response = "Starting " + itr->path().string() + ": Already started (PID=" + boost::lexical_cast(pid) + ")\n"; std::cout << "Starting " << itr->path() << ": Already started (PID=" << pid << ")\n"; } } @@ -232,6 +234,7 @@ void stop_instances(ManagerConfig *config, const std::string &_jid) { int pid = isRunning(CONFIG_STRING(&vhostCfg, "service.pidfile")); if (pid) { + response ="Stopping " + itr->path().string() + ": "; std::cout << "Stopping " << itr->path() << ": "; kill(pid, SIGTERM); @@ -243,13 +246,16 @@ void stop_instances(ManagerConfig *config, const std::string &_jid) { count--; } if (count == 0) { + response += "ERROR (timeout)\n"; std::cout << " ERROR (timeout)\n"; } else { + response += "OK\n"; std::cout << " OK\n"; } } else { + response = "Stopping " + itr->path().string() + ": Not running\n"; std::cout << "Stopping " << itr->path() << ": Not running\n"; } } diff --git a/spectrum_manager/src/server.cpp b/spectrum_manager/src/server.cpp index 94fb17e8..28f49985 100644 --- a/spectrum_manager/src/server.cpp +++ b/spectrum_manager/src/server.cpp @@ -306,6 +306,28 @@ void Server::serve_login(struct mg_connection *conn, const struct mg_request_inf print_html(conn, request_info, html); } +void Server::serve_start(struct mg_connection *conn, const struct mg_request_info *request_info) { + std::string html= get_header() ; + char jid[255]; + get_qsvar(request_info, "jid", jid, sizeof(jid)); + + start_instances(m_config, jid); + html += "" + get_response() + ""; + html += ""; + print_html(conn, request_info, html); +} + +void Server::serve_stop(struct mg_connection *conn, const struct mg_request_info *request_info) { + std::string html= get_header(); + char jid[255]; + get_qsvar(request_info, "jid", jid, sizeof(jid)); + + stop_instances(m_config, jid); + html += "" + get_response() + ""; + html += ""; + print_html(conn, request_info, html); +} + void Server::serve_root(struct mg_connection *conn, const struct mg_request_info *request_info) { std::vector list = show_list(m_config, false); std::string html= get_header() + "

List of instances

"; @@ -348,6 +370,10 @@ void *Server::event_handler(enum mg_event event, struct mg_connection *conn) { serve_login(conn, request_info); } else if (strcmp(request_info->uri, "/") == 0) { serve_root(conn, request_info); + } else if (strcmp(request_info->uri, "/start") == 0) { + serve_start(conn, request_info); + } else if (strcmp(request_info->uri, "/stop") == 0) { + serve_stop(conn, request_info); } else { // No suitable handler found, mark as not processed. Mongoose will // try to serve the request. diff --git a/spectrum_manager/src/server.h b/spectrum_manager/src/server.h index 33849dd1..1fc90b7d 100644 --- a/spectrum_manager/src/server.h +++ b/spectrum_manager/src/server.h @@ -53,6 +53,8 @@ class Server { private: void serve_login(struct mg_connection *conn, const struct mg_request_info *request_info); void serve_root(struct mg_connection *conn, const struct mg_request_info *request_info); + void serve_start(struct mg_connection *conn, const struct mg_request_info *request_info); + void serve_stop(struct mg_connection *conn, const struct mg_request_info *request_info); void print_html(struct mg_connection *conn, const struct mg_request_info *request_info, const std::string &html); private:
JIDStatusCommand