Reload the application
Sometimes you want to update the configuration file and gracefully reload the application. Here is a way to do so.
Among Unix Signals, SIGHUP can be used to restart an application (SIGHUP allows child processes to gracefully exist after they have completed the current job).
Place the code below in the global scope, before the application main(int argc,char ** argv) function:
static cppcms::service* srv; static volatile bool got_sighup; bool handler() { got_sighup = true; srv->shutdown(); }
And in main():
while(1) { srv = new cppcms::service(argc,argv); srv->applications_pool().mount( cppcms::applications_factory<my_application>()); srv->run(); if(got_sighup) { got_sighup = false; continue; } break; }
So when the application gets SIGHUP, it restarts and reloads the configuration file. It exits upon SIGTERM.
Important note (to be confirmed by Artyom): the above method does not work if in your configuration file (config.js) you have service.api = "http", i.e. if you use the internal browser. If you do, you will encounter the error: "system: Address already in use", meaning that the internal http server cannot reuse the IP same address (e.g. 127.0.0.1:8080). The method works with fastcgi or cgi.
← Encoding and UTF-8 | Top | Howto →