Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way, in java, to check on the status of a windows service? [closed]

I am looking for a library that will allow me to look up the status of a windows service to verify that the service is started and running. I looked into the Sigar library, but it is GPL and therefor I cannot use it. A Commercial or BSD(ish) license is required as this will be bundled into commercial software.

like image 742
Tim Avatar asked Sep 24 '08 13:09

Tim


People also ask

How do I know if my Windows Service is working?

Windows has always used the Services panel as a way to manage the services that are running on your computer. You can easily get there at any point by simply hitting WIN + R on your keyboard to open the Run dialog, and typing in services. msc.

How do I track a Windows service?

Go to Server > Server Monitor > Servers > click on the desired monitor. Go to Services and Processes tab. Click on Discover Services and Processes . This will discover the processes & services running in your Windows server.

How can I tell if a Windows service is running command line?

Top Windows command-line commands Anytime you want to know what services are installed on a computer and find out which ones are active, you can use sc query state= all to find a complete list. If the computer in question is remote, you should use sc \\computername query state= all.


2 Answers

If nothing else helps, try to think of a slightly different approach (if you can, of course), e.g.:

  • There is a plenty of free/non-free software which does monitoring, including Windows service monitoring (e.g. nagios, Zabbix, etc.). These monitors typically have open API where your Java app could integrate into in a number of different ways.
  • If you have the control over depending service application, expose another, different way for your Java application to check (e.g. run a dummy listener on a port, create a file, etc.). Windows services aren't a cross-platform thing therefore is not something you would expect to be supported anytime soon.
like image 172
mindas Avatar answered Oct 03 '22 07:10

mindas


I don't think there is any pure-Java way to do this because some operating systems don't have the notion of "services" like Windows does. In our projects, we wrote a wrapper around calls to the "sc" command from the command line. To get the status of a service, you can do:

sc \\some-computer query "my service name"

You'll have to manually parse the output but it's pretty straightforward.

like image 38
Outlaw Programmer Avatar answered Oct 03 '22 08:10

Outlaw Programmer