Hmmm, the socket listener connected to a 'System.exit(0);' seems a lot
cleaner, to my mind.
Tom
[EMAIL PROTECTED] writes:
> Let me preface this by saying that this is a horrible hack--it seems to
> work for me today, but if you're interested, try it out and let me know...
>
> This is NOT 100% pure java. (there's a 4 line C program--ick!)
>
> I have done some research, and it doesn't appear that there is anyway to
> get the current process id from within java any other way. If anybody
> knows otherwise, let me know -- it will make this a lot simpler.
>
> The solution consists of 3 parts:
> a 4-line C program
> a couple of mods to org.jboss.Main
> some mods to run.sh and a new shutdown.sh and setvars.sh
>
> The source for the C program is as follows:
> int main() {
> printf("%i", getppid());
> return 0;
> }
>
> All this does is print out the process id of the process calling it (the
> parent process). Compile this, and put it in JBOSS_HOME/bin with the name
> 'getppid'
>
> in org.jboss.Main, add this to the beginning of the constructor:
> Runtime r = Runtime.getRuntime();
> Process p = r.exec(System.getProperty("jboss.home") +
> "/bin/getppid");
> BufferedReader bin = new BufferedReader(new
> InputStreamReader(p.getInputStream()));
> String line = bin.readLine();
> int pid = Integer.parseInt(line);
> PrintWriter out = new PrintWriter(new BufferedWriter(new
> FileWriter(System.getProperty("jboss.home") + "/tmp/jboss.pid")));
> out.print(pid);
>
> in.close();
> out.close();
>
> r = null;
> line = null;
>
>
> You'll also need to add an import for java.io.BufferedWriter to Main.java
> This calls our C program from above, and writes the output to a file in
> JBOSS_HOME/tmp/jboss.pid
>
>
> Next, create a file in JBOSS_HOME/bin called setvars.sh. Currently it
> consists of this:
> #!/bin/sh
>
> JBOSS_HOME=/opt/jboss
> export JBOSS_HOME
>
> Be sure to make it executable (chmod +x setvars.sh), and change to the
> actual location of your JBOSS_HOME.
>
> Add this near the top of run.sh:
> . ./setvars.sh
>
> Edit the last line of run.sh (where the java vm is launched) to include a
> '-Djboss.home=$JBOSS_HOME' (put it somewhere around the tomcat.home var)
>
> Create a new file called shutdown.sh, executable with these contents:
> #!/bin/sh
>
> . ./setvars.sh
>
> getpid() {
> pid=`cat $JBOSS_HOME/tmp/jboss.pid`
> echo $pid
> return 0
> }
>
> thispid=`getpid`
> kill $thispid
>
>
> This seems to do the trick. There's some obvious room for improvement
> here and there.... (such as cleaning up the .pid file, etc.) I have no
> idea if this will work under Windows or not (I don't have a C compiler for
> windows)--anybody care to comment?
>
> It should now be trivial to set up start and stop scripts for your system
> that just call run.sh and shutdown.sh....
>
> -Jason
> <br><font size=2 face="sans-serif">Let me preface this by saying that this is a
>horrible hack--it seems to work for me today, but if you're interested, try it out
>and let me know...</font>
> <br>
> <br><font size=2 face="sans-serif">This is NOT 100% pure java. (there's a 4
>line C program--ick!)</font>
> <br>
> <br><font size=2 face="sans-serif">I have done some research, and it doesn't appear
>that there is anyway to get the current process id from within java any other way.
> If anybody knows otherwise, let me know -- it will make this a lot
>simpler.</font>
> <br>
> <br><font size=2 face="sans-serif">The solution consists of 3 parts:</font>
> <br><font size=2 face="sans-serif"> a 4-line C program</font>
> <br><font size=2 face="sans-serif"> a couple of mods to
>org.jboss.Main</font>
> <br><font size=2 face="sans-serif"> some mods to run.sh and a new
>shutdown.sh and setvars.sh</font>
> <br>
> <br><font size=2 face="sans-serif">The source for the C program is as follows:</font>
> <br><font size=2 face="Courier">int main() {</font>
> <br><font size=2 face="Courier"> printf("%i", getppid());</font>
> <br><font size=2 face="Courier"> return 0;</font>
> <br><font size=2 face="Courier">}</font>
> <br>
> <br><font size=2 face="sans-serif">All this does is print out the process id of the
>process calling it (the parent process). Compile this, and put it in
>JBOSS_HOME/bin with the name 'getppid'</font>
> <br>
> <br><font size=2 face="sans-serif">in org.jboss.Main, add this to the beginning of
>the constructor:</font>
> <br><font size=2 face="Courier"> Runtime r =
>Runtime.getRuntime();</font>
> <br><font size=2 face="Courier"> Process p =
>r.exec(System.getProperty("jboss.home") + "/bin/getppid");</font>
> <br><font size=2 face="Courier"> BufferedReader bin = new
>BufferedReader(new InputStreamReader(p.getInputStream()));</font>
> <br><font size=2 face="Courier"> String line =
>bin.readLine();</font>
> <br><font size=2 face="Courier"> int pid =
>Integer.parseInt(line);</font>
> <br><font size=2 face="Courier"> PrintWriter out = new
>PrintWriter(new BufferedWriter(new
>FileWriter(System.getProperty("jboss.home") +
>"/tmp/jboss.pid")));</font>
> <br><font size=2 face="Courier"> out.print(pid);</font>
> <br>
> <br><font size=2 face="Courier"> in.close();</font>
> <br><font size=2 face="Courier"> out.close();</font>
> <br>
> <br><font size=2 face="Courier"> r = null;</font>
> <br><font size=2 face="Courier"> line = null;</font>
> <br>
> <br>
> <br><font size=2 face="sans-serif">You'll also need to add an import for
>java.io.BufferedWriter to Main.java</font>
> <br><font size=2 face="sans-serif">This calls our C program from above, and writes
>the output to a file in JBOSS_HOME/tmp/jboss.pid</font>
> <br>
> <br>
> <br><font size=2 face="sans-serif">Next, create a file in JBOSS_HOME/bin called
>setvars.sh. Currently it consists of this:</font>
> <br><font size=2 face="sans-serif">#!/bin/sh</font>
> <br>
> <br><font size=2 face="sans-serif">JBOSS_HOME=/opt/jboss</font>
> <br><font size=2 face="sans-serif">export JBOSS_HOME</font>
> <br>
> <br><font size=2 face="sans-serif">Be sure to make it executable (chmod +x
>setvars.sh), and change to the actual location of your JBOSS_HOME.</font>
> <br>
> <br><font size=2 face="sans-serif">Add this near the top of run.sh:</font>
> <br><font size=2 face="Courier">. ./setvars.sh</font>
> <br>
> <br><font size=2 face="sans-serif">Edit the last line of run.sh (where the java vm
>is launched) to include a '-Djboss.home=$JBOSS_HOME' (put it somewhere around
>the tomcat.home var)</font>
> <br>
> <br><font size=2 face="sans-serif">Create a new file called shutdown.sh, executable
>with these contents:</font>
> <br><font size=2 face="Courier">#!/bin/sh</font>
> <br>
> <br><font size=2 face="Courier">. ./setvars.sh</font>
> <br>
> <br><font size=2 face="Courier">getpid() {</font>
> <br><font size=2 face="Courier"> pid=`cat $JBOSS_HOME/tmp/jboss.pid`</font>
> <br><font size=2 face="Courier"> echo $pid</font>
> <br><font size=2 face="Courier"> return 0</font>
> <br><font size=2 face="Courier">}</font>
> <br>
> <br><font size=2 face="Courier">thispid=`getpid`</font>
> <br><font size=2 face="Courier">kill $thispid</font>
> <br>
> <br>
> <br><font size=2 face="sans-serif">This seems to do the trick. There's some
>obvious room for improvement here and there.... (such as cleaning up the .pid file,
>etc.) I have no idea if this will work under Windows or not (I don't have a C
>compiler for windows)--anybody care to comment?</font>
> <br>
> <br><font size=2 face="sans-serif">It should now be trivial to set up start and stop
>scripts for your system that just call run.sh and shutdown.sh....</font>
> <br>
> <br><font size=2 face="sans-serif">-Jason</font>
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]