Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BDFF69DEB for ; Thu, 7 Jun 2012 22:08:46 +0000 (UTC) Received: (qmail 52517 invoked by uid 500); 7 Jun 2012 22:08:45 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 52448 invoked by uid 500); 7 Jun 2012 22:08:45 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 52435 invoked by uid 99); 7 Jun 2012 22:08:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2012 22:08:45 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mgainty@hotmail.com designates 65.55.116.105 as permitted sender) Received: from [65.55.116.105] (HELO blu0-omc3-s30.blu0.hotmail.com) (65.55.116.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2012 22:08:35 +0000 Received: from BLU142-W13 ([65.55.116.72]) by blu0-omc3-s30.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 7 Jun 2012 15:08:15 -0700 Message-ID: Content-Type: multipart/alternative; boundary="_3cddd44b-fac9-4871-ba67-13f5a836de79_" X-Originating-IP: [74.104.173.229] From: Martin Gainty To: Subject: RE: Commons daemon - stop the service Date: Thu, 7 Jun 2012 18:08:13 -0400 Importance: Normal In-Reply-To: <788314C6235F5C45A717DD34D68872BB0369FF@USALWEXMBX1.infor.com> References: <788314C6235F5C45A717DD34D68872BB036379@USALWEXMBX1.infor.com>,<4FC7990B.4050808@apache.org>,<788314C6235F5C45A717DD34D68872BB036451@USALWEXMBX1.infor.com>,<4FC7B559.50800@apache.org>,<788314C6235F5C45A717DD34D68872BB0369FF@USALWEXMBX1.infor.com> MIME-Version: 1.0 X-OriginalArrivalTime: 07 Jun 2012 22:08:15.0555 (UTC) FILETIME=[0980A130:01CD44FA] --_3cddd44b-fac9-4871-ba67-13f5a836de79_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable a quick scan of the source gives us some cluesif PID is not there procrun = exits with a -1fd =3D open(args->pidf=2C O_RDONLY=2C 0)=3B if (!quiet) log_debug("get_pidf: %d in %s"=2C fd=2C args->pidf)=3B if (fd < 0) { /* something has gone wrong the JVM has stopped */ return -1=3B } later on with wait_child we check again if PID is not alive in which = case a 1 is returned /* check if the pid file process exists */ fd =3D open(args->pidf=2C O_RDONLY)=3B if (fd < 0 && havejvm) { /* something has gone wrong the JVM has stopped */ return 1=3B }else{ ...return 0=3B /* ready JVM started ..0 is returned to inter= nal functions*/} /*if procrun returns 0 internally you're JVM is started*/ = /*.. the chronology for procrun denoument..*/ stop_child() while (count > = 0) { sleep(1)=3B pid =3D get_pidf(args=2C true)=3B if (pid <=3D 0) { /* JVM has stopped... the pid is non-existent*/ return 0=3B } count--=3B } signal(SIGTERM=2C controller)=3B signal(SIGINT=2C controller)=3B while (waitpid(pid=2C &statu= s=2C 0) !=3D pid) { /* Waith for process */ } /* The child must have exited cleanly */ if (WIFEXITED(status)) { status =3D WEXITSTATUS(status)=3B /* Delete the pid = file */ if (args->vers !=3D true && args->chck !=3D true && status !=3D= 122) unlink(args->pidf)=3B /* If the child got out wi= th 123 he wants to be restarted */ /* See java_abort123 (we use this return code to restart when t= he JVM aborts) */ if (status =3D=3D 123) { log_debug("Reloading service")=3B /* prevent looping */ if (laststart + 60 > time(NULL)) { log_debug("Waiting 60 s to prevent looping")=3B sleep(60)=3B } continue=3B } /* If the child got out with 0 he is shutting down */ if (status =3D=3D 0) { log_debug("Service shut down")=3B return 0=3B } remove_tmp_file(args)=3B log_debug("Shutdown or reload requested: exiting")=3B /* Stop the se= rvice */ if (java_stop() !=3D true) return 6=3B /*cannot stop java*/ if (doreload =3D=3D true) ret =3D 123=3B else ret =3D 0=3B /* Destroy the service */ java_destroy()=3B /* Destroy the Java VM */ if (JVM_destroy(ret) !=3D true) return 7=3B yes if all goes well the JVM should be destroyed Martin Gainty=20 ______________________________________________=20 Verzicht und Vertraulichkeitanmerkung/Note de d=E9ni et de confidentialit= =E9 Ez az =FCzenet bizalmas. Ha nem =F6n az akinek sz=E1nva volt=2C akkor k=E9rj=FCk= =2C hogy jelentse azt nek=FCnk vissza. Semmif=E9le tov=E1bb=EDt=E1sa vagy m=E1solat= =E1nak k=E9sz=EDt=E9se nem megengedett. Ez az =FCzenet csak ismeret cser=E9t szol= g=E1l =E9s semmif=E9le jogi alkalmazhat=F3s=E1ga sincs. Mivel az electronikus =FCzene= tek k=F6nnyen megv=E1ltoztathat=F3ak=2C ez=E9rt minket semmi felel=F6s=E9g nem = terhelhet ezen =FCzenet tartalma miatt. Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaeng= er sein=2C so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiter= leitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient l= ediglich dem Austausch von Informationen und entfaltet keine rechtliche Bin= dungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen w= ir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut =EAtre privil=E9gi=E9. Si vous n'=EAtes= pas le destinataire pr=E9vu=2C nous te demandons avec bont=E9 que pour sat= isfaire informez l'exp=E9diteur. N'importe quelle diffusion non autoris=E9e= ou la copie de ceci est interdite. Ce message sert =E0 l'information seule= ment et n'aura pas n'importe quel effet l=E9galement obligatoire. =C9tant d= onn=E9 que les email peuvent facilement =EAtre sujets =E0 la manipulation= =2C nous ne pouvons accepter aucune responsabilit=E9 pour le contenu fourni= . > From: James.Wang@infor.com > To: user@commons.apache.org > Subject: RE: Commons daemon - stop the service > Date: Thu=2C 7 Jun 2012 18:06:03 +0000 >=20 > I have played with procrun a bit more and realized that SCM waits for at = most two minutes. After that=2C it shows a message saying it got no respons= e from the process and displays "stopping" as status on the service. But wh= en the process finally ends=2C it shows "stopped" status (you have to manua= lly refresh the SCM).=20 > Procrun has a parameter "StopTimeout"=2C which "Defines the timeout in se= conds that procrun waits for service to exit gracefully." What happens aft= er the timeout period? Does procrun shut down the JVM? > Thanks. >=20 > James >=20 > -----Original Message----- > From: Mladen Turk [mailto:mturk@apache.org]=20 > Sent: Thursday=2C May 31=2C 2012 2:16 PM > To: user@commons.apache.org > Subject: Re: Commons daemon - stop the service >=20 > On 05/31/2012 07:53 PM=2C James Wang wrote: > > Thanks for the comments. > > I set both start mode and stop mode to JVM. >=20 > OK. >=20 > > What will happen when a thread needs 20 more minutes to complete its jo= b? >=20 > Well for something like that procrun is not the toolkit to use. > First of all=2C if you need to frequently start/stop service why using th= e service at the first place? > The sole purpose of service concept is to start the application at boot m= ode or on demand and to start them in correct order. >=20 > Then there is absolute limit which OS imposes on the service shutdown tim= eout=2C and this is for all services on the system=2C see http://support.mi= crosoft.com/kb/Q146092 >=20 > So the only clean solution is that your shutdown code does the actual cle= anup causing the clean exit. >=20 > By spec=2C JVM won't exit if you have non-daemon threads running=2C so if= you cant make them exit=2C then the only solution is System.exit=2C which = calls OS process _exit() which causes the SCM to think service failed. >=20 > Also you should design your application differently for service and comma= nd line mode. >=20 > Procrun does not need to call the main() method. > Take a look at Tomcat. We call Bootstrap start/stop methods and main() ca= lls Bootstrap.start (after setting correct mode) >=20 >=20 >=20 > Regards > -- > ^TM >=20 > --------------------------------------------------------------------- > To unsubscribe=2C e-mail: user-unsubscribe@commons.apache.org > For additional commands=2C e-mail: user-help@commons.apache.org >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe=2C e-mail: user-unsubscribe@commons.apache.org > For additional commands=2C e-mail: user-help@commons.apache.org >=20 = --_3cddd44b-fac9-4871-ba67-13f5a836de79_--