How to automatically restart service when it stops

Posted on 2012-08-20
Last Modified: 2012-08-21

   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?

Question by:szczecin
    LVL 19

    Expert Comment

    by:Miguel Angel Perez Muñoz
    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.
    LVL 19

    Expert Comment

    in service properties there is a tab Recovery where you can set action when service failure
    LVL 19

    Accepted Solution

    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.

    Author Closing Comment

    This is good answer. I have created java application for this already, but it's really nice.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    When I went to try to install Office 2007 and Office 2010 ADMX Group Policy administrative templates on my new Windows Server 2008 R2, I couldn't find any straightforward guidance on how to do it.  I muddled my way through it, but I thought I'd shar…
    Introduction As businesses grow they expand within their original location and often spill over into nearby buildings when space becomes constrained or open up a branch office in another, distant area. If these new offices are outside of the …
    This tutorial will walk an individual through the process of upgrading their existing Backup Exec 2012 to 2014. Either install the CD\DVD into the drive and let it auto-start, or browse to the drive and double-click the Browser file: Select the ap…
    This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now