commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Siegfried Goeschl (JIRA)" <j...@apache.org>
Subject [jira] [Issue Comment Deleted] (EXEC-65) Watchdog can't destroy 'sudo' and 'sleep'
Date Wed, 06 Jan 2016 19:36:39 GMT

     [ https://issues.apache.org/jira/browse/EXEC-65?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Siegfried Goeschl updated EXEC-65:
----------------------------------
    Comment: was deleted

(was: The problem under Ubuntu 

* the process is indeed killed by the watchdog 
* the StreamPumper is still reading and hence the join() will hang forever 
* some other bug report indicates that the problem is caused by no process output but adding
an echo statement does not help either)

> Watchdog can't destroy 'sudo' and 'sleep'
> -----------------------------------------
>
>                 Key: EXEC-65
>                 URL: https://issues.apache.org/jira/browse/EXEC-65
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: RedHat Enterprise Linux 64bit, JDK 1.6.0_25 64bit.
> {code}
> $ uname -a
> Linux demo-vrs1-happdb1.lts.stgt.vrs.cust.disy.net 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17
EDT 2006 i686 i686 i386 GNU/Linux
> {code}
> {code}
> $ java -version
> java version "1.6.0_25"
> Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
> Java HotSpot(TM) Server VM (build 20.0-b11, mixed mode)
> {code}
>            Reporter: Rusi Filipov
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>         Attachments: EXEC_65.patch
>
>
> I want to run a command from a shell script with make sure the process will be destroyed
after a timeout, especially if it asks for user input or contains sleep commands.
> {code:title=Java}
> DefaultExecutor executor = new DefaultExecutor();
> executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
> ExecuteWatchdog watchDog = new ExecuteWatchdog(3000);
> executor.setWatchdog(watchDog);
> CommandLine command = new CommandLine("./client.sh");
> int exitValue = executor.execute(command);
> System.out.println(exitValue);
> {code}
> I run this code on the server like this:
> {code}
> java -cp .:commons-exec-1.1.jar App
> {code}
> *Problem 1.* I want to run {{sudo}} in order to execute a script as a different user:
> {code:title=client.sh}
> #!/bin/bash
> sudo -u occ02 /apps/occ02/catalina_base/bin/restart-occ.sh
> {code}
> In case of a misconfiguration of {{/etc/sudoers}} this prompts me for a password.
> {code}
> Password:
> {code}
> And terminates only after about 5 minutes, not 3 seconds:
> {code}
> Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with
an error: 143 (Exit value: 143)
>         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
>         at App.destroy2(App.java:51)
>         at App.main(App.java:21)
> {code}
> Only if I use the {{sudo -S ...}} the process is killed after about 4 seconds:
> {code}
> Password:
> Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with
an error: 1 (Exit value: 1)
>         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
>         at App.destroy2(App.java:51)
>         at App.main(App.java:21)
> {code}
> *Problem 2.* I want to prevent a too long {{sleep}}:
> {code:title=client.sh}
> #!/bin/bash
> sleep 900
> {code}
> The Process just hangs! After 15 minutes the process terminates with this error:
> {code}
> Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with
an error: 143 (Exit value: 143)
>         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
>         at App.destroy2(App.java:51)
>         at App.main(App.java:21)
> {code}
> If I run the {{sleep}} command directly from within Java without the shell-script, the
process is destroyed on time:
> {code}
> DefaultExecutor executor = new DefaultExecutor();
> executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
> ExecuteWatchdog watchDog = new ExecuteWatchdog(3000);
> executor.setWatchdog(watchDog);
> CommandLine command = new CommandLine("sleep");
> command.addArgument("900");
> int exitValue = executor.execute(command);
> System.out.println(exitValue);
> {code}
> {code}
> Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with
an error: 143 (Exit value: 143)
>         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
>         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
>         at App.destroy4(App.java:67)
>         at App.main(App.java:23)
> {code}
> The problems were not visible when I tested on my development machine with Windows 7
64bit and JDK 1.6.0_25, 64bit. But now these issues are a serious barrier for using commons-exec
in production.
> Btw, with the {{ProcessBuilder}} from the JDK the process is destroyed in both cases:
> {code}
> ProcessBuilder builder = new ProcessBuilder("./client.sh");
> Process process = builder.start();
> Thread.sleep(3000);
> process.destroy();
> {code}
> Best regards,
> Rusi



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message