check service status on ubuntu server by windows-service on windows server - c#

i have a huge problem with my Windows-Service (C#). We had a system change on a few servers (from windows 2012R2 to Ubuntu) and for all these servers i wrote a monitoring tool as windows service running on a windows server. In this service i checked a few things on the server which worked fine. One of the things i had to check was if some special windows services (e.g. iis) are in state = running.
So - is there ANY possibility to check an Ubuntu-Service programmatically from my monitoring service? Can i set commands on the Ubuntu shell? Or start a bat File?
ServiceController sc = new ServiceController("servicename", "ubuntu-IP"))
Using a ServiceController doesn't work i guess because of Windows != Ubuntu?!
It should be an "easy" way to do it - so if it would be too ornate i just don't do it.
Any information would be appreciated.

EDIT: totally rewrote, I misunderstood the question.
Linux does not use services the way Windows does, first of all there is no infrastructure to remotely check and manage the services like in a windows domain.
You have two options there:
1-Connect through SSH with an account with admin privileges and issue "service (servicename) status", this wil yield if the service is running or not. To connect through SSH the servers must have an SSH server configured and use some C# library for the SSH connection (per example this: https://sshnet.codeplex.com/)
2-Create a C# service and use Mono on your servers, in this way that service can execute commands locally like "ps" or use Process.GetProcesses(), then you can comunicate this process with your Windows process the way you best like, per example TCP or UDP.

Related

How to monitor an external process (simplest approach)

I have a csharp app running in my customer's server. The app is a Windows Service.
I want to be able to tell if app is running, if it is stopped and lastly I want to be able to restart it. Everthing must be done from a web client app.
Because access from external networks to this machine is restricted by my customer, I was thinking about implementing an "Agent Client", which will be just another Windows Service running locally and that could execute the "restart" and "stop" commands. It would be pulling an external "Agent Server" to find out if commands need to be executed.
What do you think about this? Any better ideas?
Thanks a lot!

Remote Communication Service for WinForms

Im looking at creating a service on a remote server that a win forms app can communicate with. (Where the forms app is running locally on user machines).
The service can either run in IIS (7.5) or as a windows service, but essentially I need to be able to call the service from the forms app and then have a stream of progress sent back to the forms app from the service, much like you would output to a Console window.
I've looked into using WCF which seems ideal except I couldn't find out whether I can relay progress updates back to the forms app. Also SignalR running as a self hosted windows service seems to be an option but might be overkill?
We'll be running the forms app on win7 and the remote server will be running server 2008.
Are you able to advise best routes to go down for this and if possible some examples or tutorial links?
Many thanks :-)
If you are looking for the application to relay back to the server for progress, seems you are looking for something like this:
WCF Duplex
It basicly enable you to call bi-directional function using open socket.
Hope it helps.
Thanks,
Amir

How to let my application to be running even when Logged off the machine?

I have developed a TCP Server. I want my TCP server to be running even when I log off my machine. So clients can connect to it even when my computer is logged off. I was thinking if I must create a Windows Service to implement this approach, but I am not sure how to do so.
Please tell me how can I let my application to keep working even when my machine is logged off.
You can create a service by following these instructions:
http://support.microsoft.com/kb/251192
And then installing it to your PC should be as simple as using
installutil MyService.msc
(installutil will be part of your .NET installation, eg in C:\Windows\Microsoft.NET\Framework\v3.5)
You can the configure it to Startup Automatically by running services.msc from the command prompt.
You could launch it as a task from Windows Task Scheduler and set it to run even if you aren't logged in. This would work even if the application isn't a service.
If you want to be able to shut down your machine and still let the client connect then you need to deploy your application on a server.
Create a windows service and run it as LocalService http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.80).aspx

WCF Service reference not working on other PC

I have a Windows Store - Metro app that connects with a Net TCP WCF Service running on same PC (hosted in a console application) but on Desktop mode of Windows 8. I have added a reference of WCF Service inside metro app and everything works fine.
I package my store/metro app and WCF Service and try out on another PC which don't have Visual Studio installed so I don't recompile the code, I just install the metro app package and run the executable of WCF Service. WCF Service starts fine but when I launch my metro app it give me error (see the image below)
It seems that for some reason metro app when installed on other PC is unable to find the service reference. I have tried many things after googling but nothing works. Any ideas/hint/suggestion would be greatly appreciated.
Windows Store Apps generally cannot use the loopback address, except for 1) communication within the SAME process, or 2) for development purposes. From How to enable loopback and troubleshoot network isolation:
Network communications using an IP loopback address cannot be used for interprocess communication (between two different apps) in a Windows Store app since this is restricted by network isolation. Network communication using an IP loopback address is allowed within an app within the same process for communication purposes.
A developer may want to use loopback for testing or debugging purposes, even though that capability will not be available for customers. For example, an app may want to download data from a web service from a Windows Store app. For development purposes, the developer wants to test the app on a single computer that is configured with the web service locally on 127.0.0.1.
Loopback is permitted only for development purposes. Usage by a Windows Store app installed outside of Visual Studio is not permitted.
In a production scenario, you will likely have to install the WCF service on a separate machine. Note that you will have to enable the "private network" capability in your application manifest (on the client app) to enable local network access.

Querying a Windows Service status in C# on a Web Application

We are using the ServiceController object to query if our Service is running or not. Our web application that is performing the query is using Impersonation for security/login.
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("myService");
return sc.Status
Using an Administrator account, the query is successful. Using a limited account (non-administrator), the query is failing with a message of "Service myService was not found on computer '.'"... BUT it is only failing in Windows Server 2003 and not in Windows XP.
I've Googled it and checked in MSDN. I didn't find anything related to the usage of ServiceController in Windows Server 2003.
Any ideas?
EDIT: If there is a way to query the service status without using the ServiceController that doesn't involve "security" privileges, that might work for us. We just need to get the status of the service.
UPDATE:
I created a simple console application that will print the status of the service. I used the "runas" command to run the application using both the Administrator and Non-Administrator account. It both worked in Windows Server 2003... Which means that this is an issue of the privilege not being properly passed to the ServiceController call in the web application? IIS security stuff perhaps?
Thanks!
I thought that web app-s are supposed to be run in a sandbox. Allowing access to the service running on local computer isn't really what you should do, because of security issues.
Maybe you could tell us what you want to do and there is another solution?

Categories

Resources