I would like to know how to run a shell script on Tomcat startup, when that catalina.log prints "info: server Thank you in advance, bye
7 on the Tomcat, you will find a custom listener in the server.exml file in the Tomcat configuration. Can accomplish this via:
& lt ;? xml version = "1.0" encoding = "UTF-8"? & Gt; Server port = "8005" shutdown = "Shut down" & gt; & Lt; Lister Classname = "your.domain.CustomEventHookListener" / & gt; & Lt; Lister Classname = "org.apache.catalina.core.AprLifecycleListener" on SSLEngine = "" / & gt; & Lt; Lister Classname = "org .apache.catalina.core.JasperListener "/ & gt; & Lt; Lister Classname =" org.apache.catalina.core.JreMemoryLeakPreventionListener "/ & gt; & Lt; Lister Classname =" org.apache.catalina.mbeans.GlobalResourcesLifecycleListener "/> & Lt; Connector Port = "8009" Protocol = "AJP / 1.3" Redirection = "8443" /> & Lt; Engine name = "Catalina" defaulthost = "default" & gt; & Lt; Hostname = "default" appbase = "webapps" unpack wars = "wrong" autodinev = "false" & gt; & Lt; Reference path = "docBase =" / opt / www / application ">
CustomEventHootListener.java: package your.domain;
Import org.apache.catalina.Lifecycle; import org. apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleListener; public class custom Aevent Huklaistr lifecycle Listnr @Override {public void lifecycle events (life Size Aevent Arjiiel) {lifecycle lifecycle = Arg0kget lifecycle (); if ( Life cycle == zero) {Return;} string type = Arg0kgetType (); if (type == null) {return;} string Rajyanam = Lifecycle KgetStateName (); if (Rajyanam == null) {return;} If (type.equals ( "after_start") and amp; amp; stateName.equals ( "STARTED")) {startPostInitScript ();}} private void startPostInitScript () {// non-blocking please Thread t = new Thread () {@Override public void run ( } {Try {super.run ()} string script = "/ path / to / your-script.sh"; // JVM is the new process builder for output items (). Command (script) Inheritio () Start (). WaitFor (); } Hold (Throbable E) {e.printStackTrace (); }}}; T.setDaemon (true); T.start (); }}
You can see a functional example at
No comments:
Post a Comment