5

I'm looking into Apache Daemon to help me with a Java app, and I just wanted to get some ideas/hints about what is possible.

I want to create a simplified application that shows some kind of failsafe ability. The application will go through 4 steps in a sequence (imagine that it prints out to a simple text file in each step just a letter, like step 1 is "A", step 2 is "B" , etc), and I would like to be able to forcibly shutdown the JVM, then have it automatically restart the java application and resume the printing out (imagine it like a child pulling the plug on the TV and it turns on again by itself).

Is this possible to do via Apache Daemon? If so, how would I automate that? Do I need to attach some third-program at the operating-system level (like a simple C program that itself monitors the flow ?).

At this stage I'm just looking for pointers, as I realize it is not really clear what I will do. I prefer Windows, but I do have a Mac also and would be open to using Mac if that is better(I know Linux has some unique tools/abilities ). Any tips/ideas appreciated.

So far, I have tried using this tutorial here for help, which has been useful but not as thorough as I need.

Caffeinated
  • 11,982
  • 40
  • 122
  • 216
  • 1
    If this is a background job, run as a Windows Service, then restart-on-failure is built into Windows, you just need to define it in the Service setup. As for "resume" logic, you'd have to code that in Java and constantly update an external resource (synchronously) to ensure state is saved, since a forced shutdown caused by killing the process using Task Manager will not run any shutdown hooks. – Andreas Oct 26 '15 at 02:23
  • @Andreas - Ok understood. I'm planning to use logging files to hold the state. thanks ! – Caffeinated Oct 28 '15 at 21:54
  • @Andreas - In regards to " constantly update an external resource (synchronously) to ensure state is saved" , do you think a simple text log file would be sufficient? Or do I need to use something like MySQL ? – Caffeinated Nov 22 '15 at 04:00

1 Answers1

6

On windows, last time I check it was not managed by procrun (commmons-daemon) but by the windows service management.

You probably need to configure the service recovery after the daemon installation

  • sc failure %SERVICE_NAME% reset= 60 actions= restart/30000
  • sc failureflag %SERVICE_NAME% 1

where %SERVICE_NAME% is ... your service name

the resume logic should be in your application

Edit : add more context

See https://commons.apache.org/proper/commons-daemon/procrun.html for the service installation on windows

when issuing the commands (manually or with a cmd script)

ex :

set SERVICE_NAME=myService
prunsrv //IS//%SERVICE_NAME% --DisplayName="Test Service" \
    --Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm \
    --StartClass=org.apache.SomeStartClass --StartParams=arg1;arg2;arg3 \
    --StopClass=org.apache.SomeStopClass --StopParams=arg1#arg2

add the recovery settings after the service installation

ex

sc failure %SERVICE_NAME% reset= 60 actions= restart/30000 
sc failureflag %SERVICE_NAME% 1
benbenw
  • 723
  • 7
  • 20