Message shutdown request (#168)

* Set server version

* Message shutdown request

* Update messaging example

* Set server verion in generic example

* Allow shutdown with NOHTTP=1
This commit is contained in:
Yorick de Wid 2017-01-17 18:18:01 +01:00 committed by Joris Vink
parent 565bf5bdec
commit 86d85dd10b
5 changed files with 31 additions and 1 deletions

View File

@ -58,6 +58,9 @@ example_load(int state)
switch (state) {
case KORE_MODULE_LOAD:
kore_log(LOG_NOTICE, "module loading");
/* Set server version */
http_server_version("Server/0.1");
break;
case KORE_MODULE_UNLOAD:
kore_log(LOG_NOTICE, "module unloading");

View File

@ -8,5 +8,6 @@ workers 4
domain 127.0.0.1 {
certfile cert/server.crt
certkey cert/server.key
static / page
static / page
static /shutdown page_shutdown
}

View File

@ -28,6 +28,7 @@
int init(int);
int page(struct http_request *);
int page_shutdown(struct http_request *req);
void received_message(struct kore_msg *, const void *);
/* Initialization callback. */
@ -73,3 +74,17 @@ page(struct http_request *req)
http_response(req, 200, NULL, 0);
return (KORE_RESULT_OK);
}
/*
* Page request which will send a message to the parent
* requesting process shutdown.
*/
int
page_shutdown(struct http_request *req)
{
/* Send shutdown request to parent. */
kore_msg_send(KORE_MSG_PARENT, KORE_MSG_SHUTDOWN, "1", 1);
http_response(req, 200, NULL, 0);
return (KORE_RESULT_OK);
}

View File

@ -380,6 +380,7 @@ struct kore_timer {
#define KORE_MSG_WEBSOCKET 2
#define KORE_MSG_KEYMGR_REQ 3
#define KORE_MSG_KEYMGR_RESP 4
#define KORE_MSG_SHUTDOWN 5
/* Predefined message targets. */
#define KORE_MSG_PARENT 1000

View File

@ -34,6 +34,7 @@ static int msg_recv_packet(struct netbuf *);
static int msg_recv_data(struct netbuf *);
static void msg_disconnected_parent(struct connection *);
static void msg_disconnected_worker(struct connection *);
static void msg_type_shutdown(struct kore_msg *msg, const void *data);
#if !defined(KORE_NO_HTTP)
static void msg_type_accesslog(struct kore_msg *, const void *);
@ -57,6 +58,8 @@ kore_msg_parent_init(void)
kore_msg_parent_add(kw);
}
kore_msg_register(KORE_MSG_SHUTDOWN, msg_type_shutdown);
#if !defined(KORE_NO_HTTP)
kore_msg_register(KORE_MSG_ACCESSLOG, msg_type_accesslog);
#endif
@ -207,6 +210,13 @@ msg_disconnected_worker(struct connection *c)
c->hdlr_extra = NULL;
}
static void
msg_type_shutdown(struct kore_msg *msg, const void *data)
{
kore_log(LOG_NOTICE, "worker requested shutdown");
kore_signal(SIGQUIT);
}
#if !defined(KORE_NO_HTTP)
static void
msg_type_accesslog(struct kore_msg *msg, const void *data)