Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restarting a Windows service from a Linux box

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.

like image 858
markdrayton Avatar asked Jul 28 '09 17:07

markdrayton


People also ask

How do I restart a service from the command line?

You can use net stop [service name] to stop it and net start [service name] to start it up again basically restarting the service. To combine them just do this - net stop [service name] && net start [service name] .

How do I start a Windows service from run?

Start and run the serviceIn Windows, open the Services desktop app. Press Windows+R to open the Run box, enter services. msc, and then press Enter or select OK.


3 Answers

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"

like image 129
gimel Avatar answered Oct 28 '22 10:10

gimel


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.
like image 41
Josh Kelley Avatar answered Oct 28 '22 08:10

Josh Kelley


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.

like image 28
angelblade Avatar answered Oct 28 '22 08:10

angelblade