You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Chris S <ch...@googlemail.com> on 2011/08/03 13:57:05 UTC

[daemon] Problem with starting and stopping a service with prunsrv

Hello everybody,

just to to test apache-deamon i have written a simple program, i want to
start and stop it using the jvm mode. There a 3 different problems:

   1. I can't start the service using the windows xp service manager, i get
   an 1053 error, after that the status is "starting"
   2. When i start the service using the "//TS" argument i see my
   application will be started but it the state is still not started when i
   look into the service manager (even after pressing F5 for a refresh)
   3. Using the stop service parameter seems not to work when is start with
   "//TS" , my application seems only to stop when i hit Ctrl+C


 I am able to install my program as service using:
prunsrv //IS//TestService --DisplayName="Test Service" --StartMode=jvm
--StartClass=eu.gemtec.service.Service --StartMethod=start --StopMode=jvm
--StopClass=eu.gemtec.service.Service --StopMethod=stop
--Classpath=servicedummy.jar

I start it using:
prunsrv //TS//TestService

I am using the commons-daemon-1.0.6-bin.zip<http://mirror.arcor-online.net/www.apache.org//commons/daemon/binaries/commons-daemon-1.0.6-bin.zip>
and
Win XP for this test, here is my program source:

public class Service {

 private static final Object lock = new Object();

 public static void start(String[] args) throws InterruptedException {
  System.out.println("Start :"+Arrays.toString(args)+"thread:
"+currentThread());
  synchronized(lock) {
   lock.wait();
  }
 }

public static void stop(String[] args) throws InterruptedException {
  System.out.println("Stop :"+Arrays.toString(args)+"thread:
"+currentThread());
  synchronized(lock){
   lock.notifyAll();
  }
 }
}



Thanks in advance
Christian

Re: [exec] Draining process output/error

Posted by Siegfried Goeschl <si...@it20one.at>.
Hi Diane,

I think the best is to have a look at the JUnit test of commons-exec - 
there are a few examples how to consume stdout/stderr either pumping 
into stdout/stderr or collecting into a byte[]

Regarding your requirements

+) is it possible that your code can get stuck - if yes checkout Watchdog
+) please note that there are issues killing grand-children processes of 
your child process (think recursive killing)

Cheers,

Siegfried Goeschl

On 03.08.11 22:25, Diane Baumgartner wrote:
> Hi all,
>   
> I'm trying to run a shell script from a Java program.  I finally got a trivial example working wtih ProcessBuilder, and learned that I had to be sure to capture the child process's output so that my program would work correctly.  I have also seen the warning in the Sun documentation which states, "It is possible that the examples will deadlock if the subprocess generates enough output to overflow the system.  A more robust solution requires draining the process stdout and stder in separate threads."  That got me looking for information on draining these streams, and also led me to find Apache commons exec. 
>   
> My ultimate goal is to have the following.
> a. Java program calls shell script when user pushes a button.
> b. Shell script executes a sql script.  This script produces several output files, some of which can be large.
> c. Shell script then calls a java program which uses Apache Commons Net to FTP the files to an FTP server.
>   
> I have already successfully tested parts b and c, so now I'm trying to add part a (Java calls shell script).  My problem is that I'm having a hard time finding examples of how to drain the stdout/stderr for large amounts of data.  I have looked at the documentation, but don't have much experience with dealing with either streams or threads.  Can you please point me in the right direction?
>   
> Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [exec] Draining process output/error

Posted by Diane Baumgartner <po...@yahoo.com>.
Hi all,
 
I'm trying to run a shell script from a Java program.  I finally got a trivial example working wtih ProcessBuilder, and learned that I had to be sure to capture the child process's output so that my program would work correctly.  I have also seen the warning in the Sun documentation which states, "It is possible that the examples will deadlock if the subprocess generates enough output to overflow the system.  A more robust solution requires draining the process stdout and stder in separate threads."  That got me looking for information on draining these streams, and also led me to find Apache commons exec.  
 
My ultimate goal is to have the following.
a. Java program calls shell script when user pushes a button.
b. Shell script executes a sql script.  This script produces several output files, some of which can be large.
c. Shell script then calls a java program which uses Apache Commons Net to FTP the files to an FTP server.
 
I have already successfully tested parts b and c, so now I'm trying to add part a (Java calls shell script).  My problem is that I'm having a hard time finding examples of how to drain the stdout/stderr for large amounts of data.  I have looked at the documentation, but don't have much experience with dealing with either streams or threads.  Can you please point me in the right direction?
 
Thanks.