Re: [Cppcms-users] some graceful way to close the CppCMS app
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-07-02 19:02:02
|
For this case I'd suggest to install signal handler for SIGHUP static cppcms::service *srv; static bool got_sighup; handler() { got_sighup = true; the_service->shutdown(); } And in main() while(1) { cppcms::service srv(...) srv.run(); if(got_sighup) { got_sighup = false; continue; } break; } So when application gets SIGHUP it restarts / reloads and upon SIGTERM exits. This is what SIGHUP is usually used - reload configuration. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: Lee Elenbaas <lee...@gm...> >To: Artyom Beilis <art...@ya...>; cpp...@li... >Sent: Monday, July 2, 2012 12:12 PM >Subject: Re: [Cppcms-users] some graceful way to close the CppCMS app > > >This opens up a much better option - performing my loop inside the C++ code and no in the shell script running it. >And i can also return a shutdown reason using some static variable in order to control that loop - somewhat ugly this usage of static but works, and better then sending it over to the shell. > >the main will be something like below >and the usage will be something like: > > >runflag = 2; // reconfig >srv.shutdown(); > > >On Mon, Jul 2, 2012 at 11:57 AM, Artyom Beilis <art...@ya...> wrote: > >Like any other process: >> >> >> >>Do stuff like this: >> >> >static int runflag = 1; // 1 for initial run - enum will probably be a better solution in a real code > >int main(...) >>{ >> >> try { > while (runflag) { > runflag=0; > cppcms::service srv(...) >> srv.run(); > if (runflag == 2) { > // apply reconfiguration to disk > } > } > } >> catch(std::exception const &) { >> //Some problem >> return 1; >> >> } >> return 0; // exited normally >> >>} >> >> >>srv.run() returns upon srv.shutdown() (that is called by SIGTERM handler) >> >> >>Artyom Beilis >>-------------- >>CppCMS - C++ Web Framework: http://cppcms.com/ >>CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >> >> >> >>>________________________________ >>> From: Lee Elenbaas <lee...@gm...> >>>To: Artyom Beilis <art...@ya...>; cpp...@li... >>>Sent: Monday, July 2, 2012 10:53 AM >>>Subject: Re: [Cppcms-users] some graceful way to close the CppCMS app >>> >>> >>> >>>Is there some way to return an error code to the program that run the cppcms app? >>>i would like to provide some conditioned loop in my batch/shell script >>> >>> >>>thanks >>> >>> >>>On Mon, Jul 2, 2012 at 10:34 AM, Artyom Beilis <art...@ya...> wrote: >>> >>>Two options: >>>> >>>> >>>>1. Send a SIGTERM signal to the application service it will shutdown gracefully. >>>>2. >From the application itself, use cppcms::service::shutdown() >>>> >>>> >>>>The open requests that started processing .i.e. it is processed in the thread_pool >>>>would be completed. The connections that had not got to thread pool (not started processing) >>>> >>>>and asynchronous connections will be closed. >>>> >>>>Artyom Beilis >>>>-------------- >>>>CppCMS - C++ Web Framework: http://cppcms.com/ >>>>CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >>>> >>>> >>>> >>>>>________________________________ >>>>> From: Lee Elenbaas <lee...@gm...> >>>>>To: cpp...@li... >>>>>Sent: Monday, July 2, 2012 10:17 AM >>>>>Subject: [Cppcms-users] some graceful way to close the CppCMS app >>>>> >>>>> >>>>> >>>>>Hi All, >>>>> >>>>> >>>>>Is there some gracefull way to close the CppCMS so that it will stop accepting new requests, finish handle the currently open requests and then close down with a given error code. >>>>>In my situation i sometimes need to close the app change the configuration and then run it again. And i am looking for a gracefull way to perform that. >>>>>(Yes i know that the embeded web server is not for production - but for my case i think it is the best option right now. I would have to bundle a webserver with my app anyway, so using this and configuring it to answer only localhost seems like a good enough option for now) >>>>> >>>>>-- >>>>>-- >>>>>lee >>>>>Lee Elenbaas >>>>>lee...@gm... >>>>> >>>>> >>>>>------------------------------------------------------------------------------ >>>>>Live Security Virtual Conference >>>>>Exclusive live event will cover all the ways today's security and >>>>>threat landscape has changed and how IT managers can respond. Discussions >>>>>will include endpoint security, mobile security and the latest in malware >>>>>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >>>>>_______________________________________________ >>>>>Cppcms-users mailing list >>>>>Cpp...@li... >>>>>https://lists.sourceforge.net/lists/listinfo/cppcms-users >>>>> >>>>> >>>>> >>>>------------------------------------------------------------------------------ >>>>Live Security Virtual Conference >>>>Exclusive live event will cover all the ways today's security and >>>>threat landscape has changed and how IT managers can respond. Discussions >>>>will include endpoint security, mobile security and the latest in malware >>>>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >>>>_______________________________________________ >>>>Cppcms-users mailing list >>>>Cpp...@li... >>>>https://lists.sourceforge.net/lists/listinfo/cppcms-users >>>> >>>> >>> >>> >>> >>>-- >>>-- >>>lee >>>Lee Elenbaas >>>lee...@gm... >>> >>> >>>------------------------------------------------------------------------------ >>>Live Security Virtual Conference >>>Exclusive live event will cover all the ways today's security and >>>threat landscape has changed and how IT managers can respond. Discussions >>>will include endpoint security, mobile security and the latest in malware >>>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >>>_______________________________________________ >>>Cppcms-users mailing list >>>Cpp...@li... >>>https://lists.sourceforge.net/lists/listinfo/cppcms-users >>> >>> >>> >>------------------------------------------------------------------------------ >>Live Security Virtual Conference >>Exclusive live event will cover all the ways today's security and >>threat landscape has changed and how IT managers can respond. Discussions >>will include endpoint security, mobile security and the latest in malware >>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >>_______________________________________________ >>Cppcms-users mailing list >>Cpp...@li... >>https://lists.sourceforge.net/lists/listinfo/cppcms-users >> >> > > > >-- >-- >lee >Lee Elenbaas >lee...@gm... > > >------------------------------------------------------------------------------ >Live Security Virtual Conference >Exclusive live event will cover all the ways today's security and >threat landscape has changed and how IT managers can respond. Discussions >will include endpoint security, mobile security and the latest in malware >threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |