I want to create a windows service that will "restart" a node server or "run" npm run dev. I currently check that the server is not running by creating sockets to call to the server (localhost:8080), and increment a variable if there's no connection. Once that variable reaches a certain number, then we can assume that the server is no longer running, and that we would have to call npm run dev again.
I also don't want to use things like forever and pm2, though I do think that it should be used, just that it's not allowed..
Any help is greatly appreciated. I researched a lot on this topic, and realized that you can't call any GUI's (including shells) as part of a windows service. Let me know if there are any other alternatives.
Thanks in advance!
Currently, the process I have to 'restart' the server is through a batch script that just calls "CALL npm run dev". I have tried to run a console app in Windows Service. The console app itself work.
Related
I have a .NET 6 application compiled as a standalone executable that runs as a Windows service. What I want to add is a way to update and restart the service when it detects that a new version is available. The problem is that I can't find a way to actually restart a service with a single command in a way that can be triggered from C#.
The sc.exe can be used to create, modify, start and stop a service. But it does not have a restart command. My original plan was to modify the service and point it to the new binary, and then restart it using sc.exe, but then I noticed that it doesn't actually have a real restart command.
The Powershell cmdlet Restart-Service does what I want, but the C# Powershell integration seems to have some severe issues and bugs when the C# application is compiled as a standalone executable. It simply does not work at all for me.
I'm triggering the update from the running Windows service itself, so I can't just execute a stop command and then try to execute the start command, as my application won't be running anymore at that point.
One option might be to execute both sc.exe stop and sc.exe start in a way that isn't interrupted when the calling process is stopped, but I'm not sure which method would work reliably here. Another idea would be to slightly misuse the auto-restart on failure mechanism for Windows services. But I'm not sure I can trigger that without creating superfluous error messages in the Windows Event logs.
What options do I have to reliably restart a running Windows service from the running C# application itself?
I wanted to run .NET window service/c# script as background process in AWS and I'm very new for AWS, So if anybody can suggest that how can I schedule my window service over the AWS to execute it every day based on time set?
The simplest way is to test and develop you C# windows server locally, and then use RDP to connect to the EC2 instance and re-install it there.
There is nothing special about running an EC2 instance - its just another Windows server (in this case) that you can install whatever you want on it.
Thats the basic minimum you need to do; of course, once you learn more about AWS there is probably a lot more you could do, i.e. setup automated deployments so that when you update your service it gets deployed automatically, autoscaling it, load-balancing it, taking snapshots and backing it up etc -
But, just to get up and running, just install the windows service like you would on any other windows machine and you can build from there.
I'm making an application in C# with VS 2012 that checks a database every 15 seconds and perform some actions when it finds data. Right now I've created a Console Application so I can debug it easely but during relese this application needs to run in a IIS server.
How can I do that? I've read this question but it looks like some sort of workaround because to run it I need to perform these steps. Right now I'm reading the docs about Windows Service Application, Is this the right way?
EDIT Sorry but I've never used Windows server before, so as people pointed out IIS is only a web server, the thing I need to do is run my application in a Windows Server environment
IIS is a web-server and accordingly it should be used for hosting web applications.
Develop a windows service which does the job of checking the database in intervals and invoke a web service (which you can host in IIS)
If your application is performing some data query and manipulation on the server then I would recommend the approach to host it in a windows service.
Some advantages to this are:
The service will start and run independently of a user logging into the server.
You can configure the service to recover should it experience an exception (ideally not!).
The service will start automatically (if configured) when the server restarts.
You can configure which user group (or user) the service should run under so you have a more granual approach to security.
As it's running as a seperate process, you can monitor its memory and processor utilisation.
Debugging is slightly more cumbersome but not difficult, one approach I've used is to install the service locally, start it and then attach to it via the debugger. This question describes another approach I've also used.
I have a console application which basically sends emails once per day.
The Windows server administrator disallows this technique and doesn't want to allow extra software on the computer (launched by a scheduled task or a service).
I've been asked to evaluate the possibility of redeveloping a part of the application and integrate it into the IIS application pool but I don't think IIS can do this. Is it possible ? If so, how ?
The only approach I've looked at so far is to redevelop it as a web application and launch a web page everyday with a scheduled task, but I'd like to avoid that.
Let's analyze your options:
Use task scheduler in your server to launch console app
Use task schedule**r in your server to **web service hosted in IIS
Have an IIS application running 100% of time in an infinite loop that that checks time every minute and if it happens to be the correct time send the emails
Have a windows service.
Use task scheduler in a different server to invoke
Analyzing each one of them:
KO: Your administrator does not want console apps and process is not isolated.
KO: You have process isolated but still you are installing a console app.
OK: Not very good for performance but your fulfills your admin conditions.
KO: Your admin does not want windows services.
??: Probably your admin will not want to use an extra server
Proposed solution: As you can see only options 3 and 5 might pass the filter. Ask him
Correct solution I did similar things in the past and went for option 2. You have to convince your admin that solution 3 is a bad idea and probably 5 is already out of the question. When he had to choose the lesser of the evils option 2 is the best :-)
NOTE: You don't mention it but in case you have a SQL Server or similar you can store there an scheduled task too...
I had similar questions when I was moving from Apache servers (where it's dead easy to send a nightly email) to Windows (where you have options).
Clients have sometimes pushed me towards SQL Mail. It's not terrible. If your web app has a SQL backend, and it's okay to schedule things there, it's capable of sending emails when properly configured.
I don't think this is possible. With an IIS application you'd need something to trigger loading the application (call the web page). This itself would require a scheduled task.
You need to pound some sense into your administrator. Sorry.
I have done plenty of C# shell command calls, apps, batch files etc. The other day I was asked if it would be a problem if an executable that I currently run from my web site app, would move to another server on our intranet.
In other words the web site app and the executable that I am running through Process.Start(...) are located on the same box currently - all good there. Now there is a wish to separate the two on two different servers.
I done a few futile attempts to execute an app (located on server B) from server A (where the web site resides).
Is there a way that I have not run cross yet to do this ?
Thanks
PsExec is one way with minimal coding. Using System.Diagnostic.Process, you can call this command:
psexec \\ServerB (path)\myapp.exe arg0 arg1 ...
To control the processes of server A by running an application on server B, you would need an application running on server B that would get controlled remotely somehow.
As an example, let's say server A runs unix, so you could write a application that would connect to server A using ssh, authenticate and then control the processes and whatnot like you do in a shell. If server A does not allow ssh connection, you could write your own application that would be running on server A listening to some connection and commands that would come from an application in server B.
It's quite hard to understand what are your current settings and why would you even want to switch the application from server A to server B, so a little more information would wield you a better answer.
Austin's PSExec approach is probably the easiest approach to executing an EXE on a remote machine, but you may want to consider a potentially more robust solution:
You could modify your command-line app to run as a service and to respond to requests for work and/or data via a WCF (binaryXML/TCP or XML/HTTP) call.