diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..9005e20 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,58 @@ +#include <cppcms/service.h> +#include <cppcms/applications_pool.h> +#include <booster/log.h> + +#include <signal.h> + +#include "strusCms.hpp" + +static bool terminate = false; +static bool got_sighup = false; +static cppcms::service *global_srv = 0; + +static void handle_signal( int sig ) +{ + switch( sig ) { + case SIGHUP: + got_sighup = true; + if( global_srv ) global_srv->shutdown( ); + break; + + default: + // unknown signal, ignore + break; + } +} + +int main( int argc, char *argv[] ) +{ + signal( SIGHUP, handle_signal ); + while( !terminate ) { + cppcms::service srv( argc, argv ); + global_srv = &srv; + + try { + BOOSTER_INFO( "strusCms" ) << "Restarting application.."; + + srv.applications_pool( ).mount( cppcms::applications_factory<strusCms>( ) ); + + srv.run( ); + + if( got_sighup ) { + BOOSTER_INFO( "strusCms" ) << "Reloading configuration on SIGHUP.."; + got_sighup = false; + } else { + terminate = true; + } + + } catch( std::exception const &e ) { + BOOSTER_ERROR( "strusCms" ) << e.what() ; + srv.shutdown( ); + continue; + } + + srv.shutdown( ); + } + + return 0; +} |