Re: Batch script for maintaing remote services
- From: test <harpreet.noni@xxxxxxxxx>
- Date: Thu, 19 Feb 2009 08:19:04 -0800 (PST)
On Feb 19, 8:20 pm, "Pegasus \(MVP\)" <I....@xxxxxxxxxx> wrote:
*** See below.
"test" <harpreet.n...@xxxxxxxxx> wrote in message
news:26363214-a7e3-4000-932a-e8219a2c7aec@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Greetings,
I want to maintain (stop/start) services on remote machine in orderly
fashion. The requirement is that the next service should only be
started/stopped when previous service has stopped/started completely.
I am using Windows xp. I am able to come up with something like below:
REM ** To stop services on remote machine **
start /wait sc \\server_name stop service_name1
start /wait sc \\server_name stop service_name2
REM ** To start services on remote machine **
start /wait sc \\server_name start service_name1
start /wait sc \\server_name start service_name2
Is it true that above command means that service_name2 will only
stop/start when the first service i.e service_name1 gets
stopped/started completely?
*** Probably, but if this is what you want then you should
*** drop the "start" command altogether:
*** sc \\Server_Name stop service_name1
Also, I have one more issue. Sometimes when the service is getting
stopped, it goes into a "intermediate" state as STOPPING. In this
case, I want to kill this service before sc command go on stopping
next services.
*** In such cases you need a loop, e.g. like so:
***
*** sc \\Server_Name stop service_name1
*** :Loop1
*** ping localhost -n 10 > nul
*** sc \\Server_Name query service_name1 | find /i "stopped || goto Loop1
***
*** You should also add a loop counter in order to deal
*** with cases where the service can't be stopped.
Can someone please help me here. I have searched enough and not able
to come to any conclusion.
TIA- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Thanks. But the requirement says that I have to stop certain services
(stop next service only when previous service has completely stopped)
and then start them in reverse order (again, the next service should
be started only when previous services has started completely).
So based on your inputs I was able to modify the code as below
REM ** stopping first service
sc \\server_name stop service_name1
REM ** looping to make sure service got completely stopped **
:Loop1
ping localhost -n 10 > nul
sc \\server_name query service_name | find /i "stopped" || goto Loop1
Does the loop breaks when it finds "stopped" status for a particular
service? if yes, this takes care of the requirement where I need to
make sure that I will only proceed further when previous service in
STOPPED status. But how will I kill this service if it gets stuck in
STOPPING status? I mean in my case some services do get stuck in
STOPPING status and we have to manually killl it right away. How can I
check if the service got stuck in STOPPING status and how should I
kill it?
Also, the above loop make sure that we proceed only when previous
service has completely stopped. Correct me, but I thought even the
following two commands also does the same job. I mean the following sc
command (using wait) parameter, makes sure that next service is only
started/stopped, when the current service has been completely started/
stopped. Is it not the case? I mean what does wait parameter mean
here?
start /wait sc \\server_name stop service_name1
start /wait sc \\server_name stop service_name2
TIA
.
- Follow-Ups:
- Re: Batch script for maintaing remote services
- From: Pegasus \(MVP\)
- Re: Batch script for maintaing remote services
- References:
- Batch script for maintaing remote services
- From: test
- Re: Batch script for maintaing remote services
- From: Pegasus \(MVP\)
- Batch script for maintaing remote services
- Prev by Date: Re: EFS for XP
- Next by Date: Re: removing " double click "
- Previous by thread: Re: Batch script for maintaing remote services
- Next by thread: Re: Batch script for maintaing remote services
- Index(es):
Relevant Pages
|