Main  /  Edit version 4  /  Edit version 5  /   /  Users Area

Difference "Reload the application" ver. 4 versus ver. 5

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:
static cppcms::service* srv;
static volatile bool got_sighup;
handler()
bool handler()
{
got_sighup = true;
srv->shutdown();
}
And in main():
while(1) {
cppcms::service srv(...)
srv.run();
srv = new cppcms::service(...);
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

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0