Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Win32 - Dependant services

by periapt (Hermit)
on Oct 21, 2004 at 12:17 UTC ( #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;


Comment on Re: Win32 - Dependant services
Download Code
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.
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;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-12-22 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls