"\r\n" \
"REINDEXING\n"
-#define READY_RESPONSE \
+#define BMODE_RESPONSE \
"HTTP/1.1 200 OK\r\n" \
"Content-Type: text/plain\r\n" \
- "Content-Length: 6\r\n" \
+ "Content-Length: 12\r\n" \
"\r\n" \
- "READY\n"
+ "BACKUP MODE\n"
/* static response buffers */
-static uv_buf_t web__uv_ok_buf;
-static uv_buf_t web__uv_nok_buf;
-static uv_buf_t web__uv_nfound_buf;
-static uv_buf_t web__uv_sync_buf;
-static uv_buf_t web__uv_reidx_buf;
-static uv_buf_t web__uv_ready_buf;
+static uv_buf_t health__uv_ok_buf;
+static uv_buf_t health__uv_nok_buf;
+static uv_buf_t health__uv_nfound_buf;
+static uv_buf_t health__uv_sync_buf;
+static uv_buf_t health__uv_reidx_buf;
+static uv_buf_t health__uv_bmode_buf;
-static uv_tcp_t web__uv_server;
-static http_parser_settings web__settings;
+static uv_tcp_t health__uv_server;
+static http_parser_settings health__settings;
-static void web__close_cb(uv_handle_t * handle)
+static void health__close_cb(uv_handle_t * handle)
{
siri_health_request_t * web_request = handle->data;
free(web_request);
}
-static void web__alloc_cb(
+static void health__alloc_cb(
uv_handle_t * handle __attribute__((unused)),
size_t sugsz __attribute__((unused)),
uv_buf_t * buf)
buf->len = buf->base ? HTTP_MAX_HEADER_SIZE : 0;
}
-static void web__data_cb(
+static void health__data_cb(
uv_stream_t * uvstream,
ssize_t n,
const uv_buf_t * buf)
parsed = http_parser_execute(
&web_request->parser,
- &web__settings,
+ &health__settings,
buf->base, n);
if (web_request->parser.upgrade)
free(buf->base);
}
-static uv_buf_t * web__get_status_response(void)
+static uv_buf_t * health__get_status_response(void)
{
siridb_t * siridb;
- uint8_t flags = 0;
+ uint8_t flags = SERVER_FLAG_RUNNING;
llist_node_t * siridb_node;
siridb_node = siri.siridb_list->first;
if (flags & SERVER_FLAG_SYNCHRONIZING)
{
- return &web__uv_sync_buf;
+ return &health__uv_sync_buf;
}
if (flags & SERVER_FLAG_REINDEXING)
{
- return &web__uv_sync_buf;
+ return &health__uv_reidx_buf;
}
- return &web__uv_nok_buf;
+ if (flags & SERVER_FLAG_BACKUP_MODE)
+ {
+ return &health__uv_bmode_buf;
+ }
+ return flags == SERVER_FLAG_RUNNING
+ ? &health__uv_ok_buf
+ : &health__uv_nok_buf;
}
-static uv_buf_t * web__get_ready_response(void)
+static uv_buf_t * health__get_ready_response(void)
{
siridb_t * siridb;
- uint8_t flags = 0;
+ uint8_t flags = SERVER_FLAG_RUNNING;
llist_node_t * siridb_node;
siridb_node = siri.siridb_list->first;
siridb_node = siridb_node->next;
}
- return flags == SERVER_FLAG_RUNNING ? &web__uv_ok_buf : &web__uv_nok_buf;
+ return flags == SERVER_FLAG_RUNNING
+ ? &health__uv_ok_buf
+ : &health__uv_nok_buf;
}
-static int web__url_cb(http_parser * parser, const char * at, size_t length)
+static int health__url_cb(http_parser * parser, const char * at, size_t length)
{
siri_health_request_t * web_request = parser->data;
/* status response */
= ((length == 1 && *at == '/') ||
(length == 7 && memcmp(at, "/status", 7) == 0))
- ? web__get_status_response()
+ ? health__get_status_response()
/* ready response */
: (length == 6 && memcmp(at, "/ready", 6) == 0)
- ? web__get_ready_response()
+ ? health__get_ready_response()
/* healthy response */
: (length == 8 && memcmp(at, "/healthy", 8) == 0)
- ? &web__uv_ok_buf
+ ? &health__uv_ok_buf
/* everything else */
- : &web__uv_nfound_buf;
+ : &health__uv_nfound_buf;
return 0;
}
-static void web__write_cb(uv_write_t * req, int status)
+static void health__write_cb(uv_write_t * req, int status)
{
if (status)
log_error("error writing HTTP response: `%s`", uv_strerror(status));
siri_health_close((siri_health_request_t *) req->handle->data);
}
-static int web__message_complete_cb(http_parser * parser)
+static int health__message_complete_cb(http_parser * parser)
{
siri_health_request_t * web_request = parser->data;
if (!web_request->response)
- web_request->response = &web__uv_nfound_buf;
+ web_request->response = &health__uv_nfound_buf;
(void) uv_write(
&web_request->req,
&web_request->uvstream,
web_request->response, 1,
- web__write_cb);
+ health__write_cb);
return 0;
}
-static void web__connection_cb(uv_stream_t * server, int status)
+static void health__connection_cb(uv_stream_t * server, int status)
{
int rc;
siri_health_request_t * web_request;
http_parser_init(&web_request->parser, HTTP_REQUEST);
- rc = uv_read_start(&web_request->uvstream, web__alloc_cb, web__data_cb);
+ rc = uv_read_start(&web_request->uvstream, health__alloc_cb, health__data_cb);
if (rc)
{
log_error("cannot read HTTP request: `%s`", uv_strerror(rc));
(void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr);
- web__uv_ok_buf =
+ health__uv_ok_buf =
uv_buf_init(OK_RESPONSE, strlen(OK_RESPONSE));
- web__uv_nok_buf =
+ health__uv_nok_buf =
uv_buf_init(NOK_RESPONSE, strlen(NOK_RESPONSE));
- web__uv_nfound_buf =
+ health__uv_nfound_buf =
uv_buf_init(NFOUND_RESPONSE, strlen(NFOUND_RESPONSE));
- web__uv_sync_buf =
+ health__uv_sync_buf =
uv_buf_init(SYNC_RESPONSE, strlen(SYNC_RESPONSE));
- web__uv_reidx_buf =
+ health__uv_reidx_buf =
uv_buf_init(REIDX_RESPONSE, strlen(REIDX_RESPONSE));
- web__uv_ready_buf =
- uv_buf_init(READY_RESPONSE, strlen(READY_RESPONSE));
+ health__uv_bmode_buf =
+ uv_buf_init(BMODE_RESPONSE, strlen(BMODE_RESPONSE));
- web__settings.on_url = web__url_cb;
- web__settings.on_message_complete = web__message_complete_cb;
+ health__settings.on_url = health__url_cb;
+ health__settings.on_message_complete = health__message_complete_cb;
if (
- (rc = uv_tcp_init(siri.loop, &web__uv_server)) ||
+ (rc = uv_tcp_init(siri.loop, &health__uv_server)) ||
(rc = uv_tcp_bind(
- &web__uv_server,
+ &health__uv_server,
(const struct sockaddr *) &addr,
0)) ||
(rc = uv_listen(
- (uv_stream_t *) &web__uv_server,
+ (uv_stream_t *) &health__uv_server,
128,
- web__connection_cb)))
+ health__connection_cb)))
{
log_error("error initializing HTTP status server on port %u: `%s`",
port,
return -1;
}
- log_info("start listening for HTTP status requests on TCP port %u", port);
+ log_info("Start listening for HTTP status requests on TCP port %u", port);
return 0;
}
if (!web_request || web_request->is_closed)
return;
web_request->is_closed = true;
- uv_close((uv_handle_t *) &web_request->uvstream, web__close_cb);
+ uv_close((uv_handle_t *) &web_request->uvstream, health__close_cb);
}