diff --git a/spectrum_manager/src/main.cpp b/spectrum_manager/src/main.cpp index 847ae648f5b97ce30f0066af1034f5d97cce3fa5..ee1a79971b8d243529947350c88d3b12a6992c36 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 c3785c214a594b84ff31dbfa232c7e76267ffc00..aa133f6b4076d8b21f0767dbbba5c39495f377a7 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 94fb17e8408f43219f23961c646e4112e3d02a97..28f499853cfff11d634c8877d46b4aab1fec7035 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 33849dd1b53867354f681b55e373061404eafa12..1fc90b7d90ed59b90d1d5fa0a7b3afb917f1be84 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