- Joined
- Feb 16, 2003
- Messages
- 9,527
So I'm not much of a programmer, but my company has ignored a problem with allowing our customers to restart our applications services easily. So I decided to take it upon myself to write a batch file to allow our customers to double click and it will restart our application services in the proper order. However, there's one thing I have not been able to find any information on.
Sometimes our implementers and customers will disable some of the services that they do not need in the windows services manager. I would ideally like to have the batch file check to see if a service is disabled to avoid wasting time trying to start it.
I also have another service which can take some time to stop depending on the workload it has at the time of the command to stop. So I have a fail safe system to check to see if it's still on, re-issue a stop, wait 30 seconds, re-check rinse and repeat until the service is found to be stopped.
Sometimes our implementers and customers will disable some of the services that they do not need in the windows services manager. I would ideally like to have the batch file check to see if a service is disabled to avoid wasting time trying to start it.
I also have another service which can take some time to stop depending on the workload it has at the time of the command to stop. So I have a fail safe system to check to see if it's still on, re-issue a stop, wait 30 seconds, re-check rinse and repeat until the service is found to be stopped.
Code:
@ECHO off
ECHO PatientWorks Auto Service Restart
ECHO PW Versions 3.4 - 4.X
ECHO on
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Creating Event Log
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
eventcreate /l application /t warning /so PW-RESTART /id 1 /d "A system administrator has manually restarted the PatientWorks services by using the PW-RESTART Batch File."
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Stopping Services
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
NET STOP "PATIENTWORKS SERVER MONITOR"
TIMEOUT 5
NET STOP "PATIENTWORKS DATA SERVICES" /y
TIMEOUT 10
TASKLIST | FIND /I "PWIMPORTSERVER.EXE" >NUL
IF NOT %errorlevel%==0 GOTO STEP2
:STEP2
NET STOP "PATIENTWORKS DATAFILE LISTENER"
TIMEOUT 5
TASKLIST | FIND /I "PWHL7AppServer.EXE" >NUL
IF NOT %errorlevel%==0 GOTO STEP3
:STEP3
NET STOP "PATIENTWORKS HL7 lISTENER"
TIMEOUT 5
TASKLIST | FIND /I "PWJOBServer.EXE" >NUL
IF NOT %errorlevel%==0 GOTO STEP4
:STEP4
NET STOP "PATIENTWORKS JOB SERVER"
TIMEOUT 5
TASKLIST | FIND /I "PWREDIRECTOR.EXE" >NUL
IF NOT %errorlevel%==0 GOTO STEP5
:STEP5
NET STOP "PATIENTWORKS REDIRECTOR"
TIMEOUT 5
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Timeout while DataServices may stop
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TASKLIST | FIND /I "PWDATASERVER.EXE" >NUL
IF NOT %errorlevel%==0 GOTO STARTING
IF NOT %errorlevel%==1 GOTO RETRY
:RETRY
TASKLIST | FIND /I "PWDATASERVER.EXE" >NUL
IF NOT %errorlevel%==1 TIMEOUT 30
TASKLIST | FIND /I "PWDATASERVER.EXE" >NUL
IF NOT %errorlevel%==1 GOTO RETRY2
:RETRY2
NET STOP "PATIENTWORKS DATA SERVICES" /y
TIMEOUT 5
TASKLIST | FIND /I "PWDATASERVER.EXE" >NUL
IF NOT %errorlevel%==0 GOTO STARTING
IF NOT %errorlevel%==1 GOTO RETRY
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Starting Services
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:STARTING
NET START "PATIENTWORKS DATA SERVICES"
TIMEOUT 10
NET START "PATIENTWORKS DATAFILE LISTENER"
TIMEOUT 5
NET START "PATIENTWORKS HL7 lISTENER"
TIMEOUT 5
NET START "PATIENTWORKS JOB SERVER"
TIMEOUT 5
NET START "PATIENTWORKS REDIRECTOR"
TIMEOUT 5
NET START "PATIENTWORKS SERVER MONITOR"