costin 01/02/19 11:48:51
Modified: src/share/org/apache/tomcat/startup StopTomcat.java
Log:
Guess tomcat.home using introspection utils.
Now "java -jar ~/dist/tomcat/lib/stop-tomcat.jar" is all you need,
no more scripts ( "cd", -DTOMCAT_HOME, etc )
( or double-click if your file manager supports it )
( I use some gnome .desktop actions in a panel menu - less typing :-)
Revision Changes Path
1.4 +83 -33
jakarta-tomcat/src/share/org/apache/tomcat/startup/StopTomcat.java
Index: StopTomcat.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/StopTomcat.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StopTomcat.java 2001/02/07 07:01:29 1.3
+++ StopTomcat.java 2001/02/19 19:48:50 1.4
@@ -59,10 +59,10 @@
package org.apache.tomcat.startup;
import org.apache.tomcat.util.StringManager;
+import org.apache.tomcat.util.IntrospectionUtils;
import java.io.*;
import java.net.*;
import java.util.*;
-
// Depends: StringManager, resources
@@ -77,6 +77,10 @@
StringManager.getManager("org.apache.tomcat.resources");
String tomcatHome;
+
+ String host=null;
+ int port=-1;
+ String secret;
public StopTomcat()
{
@@ -94,6 +98,23 @@
System.getProperties().put("tomcat.home", s);
}
+ public void setHost( String h ) {
+ host=h;
+ }
+
+ public void setPort( int port ) {
+ this.port=port;
+ }
+
+ /** When tomcat is started, a secret ( random ) key will be generated
+ in ajp12.id. If you run StopTomcat from the same host, it'll
+ read the key and use it. If you run from a different host, you'll
+ have to specify it manually
+ */
+ public void setSecret( String s ) {
+ secret=s;
+ }
+
// -------------------- Ant execute --------------------
public void execute() throws Exception {
@@ -112,45 +133,54 @@
// -------------------- Implementation --------------------
void stopTomcat() throws Exception {
- String tchome=getTomcatInstall();
- int port=8007;
- InetAddress address=null;
+ String tchome=getTomcatHome();
+
+ if( secret==null ) {
+ try {
+ BufferedReader rd=new BufferedReader
+ ( new FileReader( tchome + "/conf/ajp12.id"));
+ String line=rd.readLine();
+
+ if( port < 0 ) {
+ try {
+ port=Integer.parseInt( line );
+ } catch(NumberFormatException ex ) {
+ ex.printStackTrace();
+ }
+ }
+
+ line=rd.readLine();
+ if( host==null ) host=line;
+ line=rd.readLine();
+ if( secret==null ) secret=line;
+ if( "".equals( secret ) )
+ secret=null;
+
+ } catch( IOException ex ) {
+ //ex.printStackTrace();
+ System.out.println("Can't read " + tchome + "/conf/ajp12.id");
+ System.out.println(ex.toString());
+ return;
+ }
+ }
- try {
- BufferedReader rd=new BufferedReader
- ( new FileReader( tchome + "/conf/ajp12.id"));
- String portLine=rd.readLine();
-
+ System.out.println("Stoping tomcat on " + host + ":" +port +" "
+ + secret);
+ InetAddress address=null;
+ if( host!=null && !"".equals( host )) {
try {
- port=Integer.parseInt( portLine );
- } catch(NumberFormatException ex ) {
+ address=InetAddress.getByName( host );
+ } catch( UnknownHostException ex ) {
ex.printStackTrace();
}
- String addLine=rd.readLine();
- if( addLine!=null && !"".equals( addLine )) {
- try {
- address=InetAddress.getByName( addLine );
- } catch( UnknownHostException ex ) {
- ex.printStackTrace();
- }
- }
- String secret=rd.readLine();
- if( "".equals( secret ) )
- secret=null;
-
- System.out.println("Stoping tomcat on " + address + ":" +port +" "
- + secret);
- stopTomcat( address,port, secret );
-
- } catch( IOException ex ) {
- ex.printStackTrace();
}
-
+ stopTomcat( address,port, secret );
}
- public String getTomcatInstall() {
+ public String getTomcatHome() {
// Use the "tomcat.home" property to resolve the default filename
- String tchome = System.getProperty("tomcat.home");
+ String tchome=IntrospectionUtils.guessHome("tomcat.home",
+ "stop-tomcat.jar");
if (tchome == null) {
System.out.println(sm.getString("tomcat.nohome"));
tchome = ".";
@@ -179,7 +209,6 @@
} catch(IOException ex ) {
System.out.println("Error stopping Tomcat with Ajp12 on " +
address + ":" + portInt + " " + ex);
- throw ex;
}
}
@@ -220,6 +249,27 @@
i++;
if (i < args.length)
System.getProperties().put("tomcat.home", args[i]);
+ else
+ return false;
+ }
+ if (arg.equals("-host") ) {
+ i++;
+ if (i < args.length)
+ host=args[i];
+ else
+ return false;
+ }
+ if (arg.equals("-port") ) {
+ i++;
+ if (i < args.length)
+ port=Integer.parseInt( args[i] );
+ else
+ return false;
+ }
+ if (arg.equals("-pass") ) {
+ i++;
+ if (i < args.length)
+ secret=args[i];
else
return false;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]