Windows Task Scheduler doesn't restart java app after failure - java

I have a java application that terminates with System.exit(1);. And I have created a task "C:\Program Files\Java\jre1.8.0_221\bin\java.exe" -Dfile.encoding=UTF-8 -jar C:\test\transfer-1.0.jar. In the settings tab of Task Scheduler I have checked
allow task to be run on demand,
if the task fails, restart every 1 minute,
attempt to restart up to 10 times,
if the running task does not end when requested, force it to stop,
stop the existing instance
But when I run the task it doesn't restart after 1 minute. The history logs say "Information: Action completed, and Task completed".
What I need to to so that the Task Scheduler restarts the java application?

Related

Robot - how to check if the execution of a jar is finished

I would like to run a jar file using a robot framework test suite, because this test-case is to be included among other test cases.
When the jar is run from the cmd, it produces the expected output, which can take 10 minutes, and then it ends.
My issue is that I'm not capable to detect when the execution of the jar is finished. I tried several keywords combination, in the last attempt I used the keyword Process Should Be Stopped, as shown below, and the result is that the process is always running.
One of my doubts is: which process is running, java? or the execution of the jar?
*** Settings ***
Library Process
Library OperatingSystem
Suite Setup log running on ${properties.hostname}
Suite Teardown Terminate All Processes kill=True
Variables C:/Users/theUser/Desktop/CheckOutRegression/Regression/RegressionScripts/config/properties.py
*** Test Cases ***
Check jar execution
${data}= Start Process java -jar da-1.0-SNAPSHOT.jar importFile1.json importFile2.zip cwd=${properties.pathToScripts} alias=myProc
${wait}= Wait Until Keyword Succeeds 10x 60s Process Should Be Stopped myProc
Log ${wait}
${result}= Get Process Result myProc
Log ${data.stdout}
Do you know how I can check that the execution of the jar file is finished?

Jenkins hangs between build and post-build

After updating Jenkins to version 2.156 (from version 1.6), some of our build jobs get stuck after completing and before moving to post-build action. Job itself is finished within 5 minutes (same as before), then it hangs for 5-10 minutes before moving on.
I managed to narrow it down to this:
"Executor #10 for master : executing 03_masa #4390" Id=34464 Group=main TIMED_WAITING
at java.lang.Thread.sleep(Native Method)
at hudson.util.ProcessTree$WindowsOSProcess.killSoftly(ProcessTree.java:560)
at hudson.util.ProcessTree$WindowsOSProcess.killRecursively(ProcessTree.java:520)
at hudson.util.ProcessTree$Windows.killAll(ProcessTree.java:666)
at hudson.Launcher$LocalLauncher.kill(Launcher.java:955)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:510)
at hudson.model.Run.execute(Run.java:1810)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Referenced code can be found here (present since version 2.141).
threadDump #1, threadDump #2
Can we do something about it?
2.141 introduced a 2min wait on process termination (it would seem that multiplies with as many processes as were created during your build)
https://github.com/jenkinsci/jenkins/commit/d8eac92ee9a1c19bf145763589f1c152607bf3ed
unsure why killSoftly does not work but you can configure the timeout
In your jenkins.xml you can add this to your /service/arguments element (before the -jar) like so:
-DSoftKillWaitSeconds=0
After doing so and restarting jenkins you should be able to find your SoftKillWaitSeconds setting under /systemInfo
and your build time should be back to normal

Run same jar file sequentially in a loop for different inputs

Am executing a jar file in remote server using jenkins job build step through publish over ssh.
Input build parameters for the job,say list - a,b,c,d,e
Execution command for publish over ssh -
cd /myjarfilepath
for input in $list
do
java -Xmx1024m -cp myApp.jar com.CommandLineRunner $input
done
job fails with error
ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 120,000 ms]
It runs successfully for one input. Say if it fails for input b then it gets terminated without executing the jar for c,d,e. I want execute the jar for all the inputs available.
Any suggestions will be appreciated!
Thanks.
Yes this is because of default timeout set to=120000. By updating transfers->Advanced->Exec Timeout(ms). I was able to build for all in loop successfully.

Authorization required to install jzos batch launcher?

We are trying to install the JZOS Batch Launcher. The function consists of three pieces: a load module that must be put into a z/OS PDSE, a sample start proc that can be tailored and put into an appropriate PROCLIB, and sample JCL that can be tailored and put into an appropriate SAMPLIB.
On submitting the job we are getting return code=0101. Below are the trace details which we are getting in the job:
Output from DD:STDENV config shell script:
waiting for child shell process to complete
waitChild()
child shell process exited with exit code 0
waitChild()
Child shell process exited without printing environment; //STDENV should not contain 'exit'
adoptEnvironment()
run()
cleanup()
JZOS batch launcher elapsed time=0 seconds, cpu time=0.040000 seconds
JZOS batch launcher failed, return code=101
cleanup()
~JzosVM()
~JzosVM()
After looking this up and reading more,we then tried to run the job with superuser access and the job ran fine. So we need to know what privileges we require without being a superuser which will enable us to run the job successfully.

System.exit working in "sbt run" but not in .jar

When shutting down my program I need to let my akka actors finish what they're doing before shutting down, so I have a shutdown hook:
sys.addShutdownHook(
{
log.info("\n shutting down startWorkScheduler\n")
assignWorkScheduler.cancel()
log.info("\ntelling manager to shutdown gracefully\n")
manager ! Manager.ShutdownGracefully
//spam shutdown messages until we exit
val resendShutDown = system.scheduler.schedule(5 seconds, 2 seconds){
manager ! Manager.ShutdownGracefully
}
system.awaitTermination()
}
and elsewhere I wait for a "all ok, you can shutdown" message:
case Terminated(httpDlrSqlRouter) => {
println("received terminated message from http router")
if(shuttingDown) {
println("httpDlrRouter done, shutting down......")
log.info("httpDlrRouter done, shutting down......")
context.system.shutdown()
java.lang.System.exit(0)
}else{
log.warning("httpDlrRouter terminated, don't know why!")
}
}
When I run the code using sbt run it works as expected: kill or CTRL+c finishes the work, prints "httpDlrRouter done, shutting down......" and exits.
When I build a .jar using sbt assembly and run it using java -jar filename.jar it does the same except actually exiting, it just hangs until i kill it with kill -9
do I need any alternatives to System.exit or some configuration to make it work?
Apparently changing
java.lang.System.exit(0)
to
Runtime.getRuntime().halt(0)
solved the problem

Categories

Resources