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

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.

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!!

      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.

      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://401134]
and the universe expands...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2018-02-18 18:47 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (256 votes). Check out past polls.