How to monitor an external process (simplest approach) - c#

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!

Related

running an application on vps

I have just finished a project , for short an Instagram robot for following and other tasks which is written in c# and selenium, for make it more practical and prevent from cracking and stealing my code I would like to run it on a virtual server because it needs a single system to work continuously for running.
As I don't have any experience in working with VPS, I need some hints, first is my approach correct? can I execute my application in a virtual server like a personal computer?
Moreover can I use a VPS as a host? like some parts of my application run on the VPS and some parts run on the other host?I mean could they be connected together? something like a panel(run on host) which users are able to do different settings on their robots(run on vps).
thanks for any tips , article or advise in advance!
all you should do is connect to a VPS using the windows Remote Desktop application.
then it's basically like a personal computer, you can run your robot and close the Remote Desktop application and it keeps running.

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

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.

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

Run Batch-Files in Windows Service while logged off

I wrote a windows service in C# .NET 3.5.
It starts up automatically and runs as Local System User (no log in required).
If i run a Shutdown-Batch-File (shutdown -s -t 30) with my service by calling Process.Start(), nothing happens until i log in to windows. So it waits for logging in and then starts the batch.
Is it possible to run this batch in logged off state?
Greetings
There is a property for each service application called Allow Interact With Desktop that should be set True for your service to be able to run Shutdown-Batch-File.
Take a look at these links:
Interact With Desktop when Installing Windows Service
Allow service to interact with desktop in C#
Have you checked to make sure this is not a permission issue? Ie does it work if the service is running as an administrator?
You might also want to try the alternative methods of shutting down mentioned in this question how-to-shutdown-the-computer-from-c#.

When do we use windows service?

Are there situations that we should use a windows service ?
I am building a client-server project (c#) and the server supposed to work alone without any user so someone advised me to use a windows service to run the server, is this right ? or there are a better solutions ?
Windows services are normally used when an application needs to continuously run. For example if they need to:
Wait for incoming requests. (Like through remoting or wcf)
Monitor a queue, file system etc.
If a program just needs to run periodically, like once a day. It is normally easier to create a scheduled task.
In your situation I would use a service for the following reasons:
You don't need to have a session running. This is good for security, and also reduces overhead on the server.
You get some of the managment commands built in for free
Start
Stop
Pause
Continue
You can handle server events such as shutdown.
Windows service can start running as soon as the machine is powered up, which makes ideal for running as a server, http server for example. No one is required to login.
You should create a Windows Service to run code in the background, without user interaction.
For example, a Windows Service will run even if no-one is logged on.
Any server that accepts connections (such as a mail, web, or FTP server) should usually be a Windows Service.
Well, a Windows Service provides a full framework for your application to work and to remain active while you want it to, so I think its ok.
Windows services are the right thing to use for something that should run all of the time, whether or not a user is logged in.
If you need something to run without an active user logged in, you need to use a windows service.
When you need the application to start running even when no one has physically logged into the machine, which is common with server machines, a service is a good candidate in this case. Especially because the service can be configured to auto start, which means the service will start when the machine is rebooted withut human intervention.
If however you are wanting to host web services (WCF) while a service is an option, you might consider hosting in IIS, this relieves you of writing the actual hosting code etc.

Categories

Resources