views:

921

answers:

6

We have a crummy legacy Windows application (already discussed here) which replicates content to from a Windows host to many Linux hosts. We several instances of it running on several boxes. Each instance has its own .ini file containing a list destination servers. Fairly often we need to change the content of these files and restart the process, a process which is done by hand by our ops team. I'd like to replace this with a simple web-based utility (running on a Linux host) which allows users to generate the configuration files, send them to the hosts and restart the services. Generating the files is easy -- I'd probably use Perl and Template Toolkit -- and since the servers export their configuration directories copying the data is relatively easy as well.

What're my options for restarting the Windows services? Win32::Service? I haven't had a chance to look very far yet so if you say "x::y makes this easy, but watch out for z" you'd save me a lot of time. Is it even possible? Alternatively, perhaps you could suggest a better way to tackle this problem (replacing the software sadly is not one!) I'm not trying to be lazy, just avoid wasting time fiddling with modules that might not do what I want.

+1  A: 

You can restart a Windows service from the Windows command line using:

net stop service_name
net start service_name

You can find the Service Name by clicking on properties in the Services window.

That might enable you to script it.

Supertux
A: 

The most concrete way would be to build a web service that handles the updating of the ini's and restarting of the services, but given that this is an internal solution that is likely massive overkill.

Guvante
+2  A: 

Ubuntu includes a utility that can help with managing Windows systems, wmic - WMI Client. With proper permissions, WMI can easily stop and start Windows services.

(An example from the man page, not on service control.)

EXAMPLE

wmic -U [domain/]adminuser%password //host "select * from Win32_ComputerSystem"

gimel
A: 

I usually enable telnet, telnet to the box remotely, and use "net stop ServiceName" and "net start ServiceName".

Domchi
A: 

Winexe can do this; it's the Linux equivalent to Sysinternal's very useful PsExec tool.

The last time I used Winexe was a couple of years ago, so this may have changed, but at the time, there were a couple of caveats:

  • Terminal handling wasn't well implemented, so typing non-alphanumeric keys to a remote command may be weird. If you're scripting, this shouldn't be an issue.
  • Like PsExec, Winexe operates by installing a service on the Windows box then telling that service to run a command. Unlike PsExec, it didn't clean the service up afterward. The installed service is harmless and doesn't run when Winexe isn't doing anything, so this is pretty much harmless.
Josh Kelley
A: 

You can use Winexe

$ winexe -U HOME/Administrator%'Pass123' //host 'cmd /C net stop wuauserv && net start wuauserv && echo AutoUpdates service restarted'

The password is written between '' <-- Manual dont say about this, but it work.

angelblade