• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 902
  • Last Modified:

How to automatically restart service when it stops


   I am looking for solution to my problem. Due to some error in Java Virtual Machine / Application Server, JBoss AS service stops (java crashes) randomly. It occurs like once in a month, usually in the night. As it is very important service, it needs to be started immediately after stop. I tried "recovery" tab in service properties (first failure: "restart the service"), but it doesn't work for me. In the event viewer this crash is just simple event "JBoss service entered the stopped state", probably that's why recovery does not help.

Any hints what can be done?

1 Solution
Miguel Angel Perez MuñozCommented:
On this site you can find a code to check if an apply is running. Changing process name can adjust to your java software and re-run if process is not running.
in service properties there is a tab Recovery where you can set action when service failure
you could create a scheduled task that tries to start the service every 5 minutes or so. If the service is running it will give the message that the service is already started, otherwise it will start the service.

Create a Basic task, start it daily,
Program / Script: Net.exe
Arguments: start "your JBoss AS service"

Edit the task, select the Trigger tab, and under Advanced settings select "Repeat task every" 5 minutes.

IMHO this is a bullet proof method to restart the service.

You can also use the trigger "On an event"
Select the event log where the "JBoss service entered the stopped state" message appears, and the source.
If this works the restart will be faster, but if for some reason the source changes, or the crash isn't logged in event viewer there will be no restart.

Of course you can also add both methods as scheduled tasks.
szczecinAuthor Commented:
This is good answer. I have created java application for this already, but it's really nice.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now