Difference "Reload the application" ver. 5 versus ver. 6
Content:
Sometimes you want to update the configuration file and gracefully reload the application. Here is a way to do so.
|
|
Among [Unix Signals](http://en.wikipedia.org/wiki/Unix_signal), [SIGHUP](http://en.wikipedia.org/wiki/SIGHUP) can be used to restart an application (SIGHUP allows child processes to gracefully exist after they have completed the current job).
|
|
Here is how you can use it it your application's code:
|
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(...);
|
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][prev]
|
| [Top](#maincontent)
|
| [Howto][next] →
|
|
[prev]: /wikipp/en/page/cppcms_1x_encoding_and_utf8
|
[next]: /wikipp/en/page/cppcms_1x_howto |
About
CppCMS is a web development framework for performance demanding applications.
Support This Project
Navigation
Main Page
Valid CSS
| Valid XHTML 1.0