Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Win32 - Dependant services

by periapt (Hermit)
on Oct 21, 2004 at 12:17 UTC ( [id://401134]=note: print w/replies, xml ) Need Help??


in reply to Win32 - Dependant services


I have had the same issue for several years. I don't know of a Perl solution but there is a system level solution that is simple to implement via perl. You can shell out to windows and use the net stop/net send commands to bring down and bring up the server. The main drawback is that, while you can stop all dependant services with one command, you have to start all the services by hand. I have it set up this way.
my @services = qw(MSSQLServerOLAPService SQLServerAgent MSSQLSERVER + ) foreach (@services){ my $rtncd = system("net stop $_") >> 8; # some error checking & other code if wanted } foreach (reverse @services){ my $rtncd = system("net start $_") >> 8; # some error checking & other code if wanted }

The order of the service shutdown and startup is based on the order of ops I have observed on my system. I've occasionally thought of exploring Win32::API to see if I could access the restart option that way but I haven't found the time yet and this solution has worked solidly for many years.

Hope this helps.

PJ
use strict; use warnings; use diagnostics;

Replies are listed 'Best First'.
Re^2: Win32 - Dependant services
by Smaug (Pilgrim) on Oct 21, 2004 at 14:34 UTC
    Hi PJ,
    Here is a possible solution using your command shell idea and the output from 'net stop'
    use strict; my @order; my @results = `net stop mssqlserver /N`; foreach(@results){ if(/^ /){ push(@order,$_) } } foreach(reverse(@order)){ print("Stopping $_\n"); system("net stop \"$_\""); } #...... reverse to start again....

    This is an initial hack. Any ideas for improvement are welcome!!
    Bye!

      Actually, this looks pretty good. I may try it myself. I haven't had the opportunity to take down my server lately so I haven't tested it but I like it.

      PJ
      use strict; use warnings; use diagnostics;
Re^2: Win32 - Dependant services
by Smaug (Pilgrim) on Oct 21, 2004 at 13:30 UTC
    Hi PJ,
    That's great....but....I don't always know what the dependant services are. Some servers have HP Insight Manager installed, so that needs to be stopped, and others don't.
    We have got an idea from this and I'll post the code if we get it working.
    Thanks again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://401134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found