What is the best way to deploy an executable process to a web server?

The original question:

The title of this question may be somewhat awkwardly worded, but here's the situation:

I have a .NET web project deployed to my server. It is still in beta, so there are many releases and re-releases.

I also wrote the C # executable in the same VS solution (call it “admin.exe”), which runs in the background on the server, periodically performing integrity checks on business rules and making appropriate inserts to the warning table in the database.

Question: What is the best way to deploy this application so that it updates whenever I make a new version? It should work all the time between releases, so ideally I need some kind of setup in which the shutdown-deploy-startup process includes as few steps as possible.

Thanks!

Editing - Starting Bounty

The answers given so far have been useful and interesting, but have not provided me with a clear, concise, and elegant solution. Please do not assume that I have extensive knowledge of deployment projects because I do not. Bounty goes to a person who can provide a solution that does the following:

  • Publish the latest website;
  • Turn off all instances of admin.exe that are running on the server;
  • Update admin.exe;
  • Run admin.exe;
  • All of the above should be done preferably in one step or as few steps as possible, as this will be repeated throughout the life of the product; and
  • All of the above should be done preferably without the need to install any third-party software.

Thank you for your help!

Minor change - clarification

I think that many of the proposed solutions overestimated the complexity of the problem, so let me clarify: everything that needs to be deployed should be deployed on only one computer, which is also happy that Visual Studio is available with all the source code. I only need to (1) publish the website in a web folder and (2) close, reinstall and restart admin.exe on the same server. Isn't there an easy way to do this in one step? Can this be done using the VS deployment project?

+7
c # deployment
source share
11 answers

The “right” way is probably to set up deployment scripts and installers, but the ability to simply click a publication in Visual Studio and skip remote desktop is much more convenient during development.

I have an admin web application that acts as an interface for a command line application - a little different than what you are doing, but the same solution should work.

Just add a link to the console project in the admin web application. Even if you do not call any methods in the console project, the link will cause the console application to be rebuilt and loaded when the admin website is published.

A simple start / stop page added to the web application takes care of steps 2 and 4 - Mine calls Process.Start () / Process.Kill (), although you obviously have the option of a cleaner shutdown depending on the admin.exe setting .

Below is the code from my Start / Stop page - I configured them as web service methods (to facilitate some monitoring materials that you probably won't need), but they should work just as well as from a simple button click method. Please note that the service account will need permission to start / stop the process. In the dev block, the easiest option is to configure iis to run as an administrator user, and not for the default service account.

private void KillProcess(string name) { var binpath = Server.MapPath("~/bin"); var pp2 = Process.GetProcesses(); var pp = from p in pp2 where p.ProcessName.Contains(name) && !p.ProcessName.Contains("vshost") select p; foreach (var p in pp) { p.Kill(); } } [WebMethod] public void StartQueueRunner() { var binpath = Server.MapPath("~/bin"); System.Diagnostics.Process.Start(Path.Combine(binpath, "TwoNeeds.QueueRunner.exe")); } [WebMethod] public void StartQueueRunner() { var binpath = Server.MapPath("~/bin"); System.Diagnostics.Process.Start(Path.Combine(binpath, "TwoNeeds.QueueRunner.exe")); } 
+3
source share

It looks like you need to take a look at a custom MSBuild script for deployment.

MSBuild does much more than just create solutions. You can also use it to copy files and update them. A good resource for tasks for this is the MSBuild community task here .

You can then enable background process deployment along with website deployment deployment.

An alternative approach could be to use Windows Powershell with something like PSExec to remotely execute copy and update commands.

Both of these approaches can be very well automated with continuous integration servers such as Hudson . I have a build process that automatically tracks the source code repository, builds the program, deploys on the intermediate server, runs the acceptance tests, and then deploys in the preview window. I have another (manual) task that with one click expands this version of the preview in order to live, minimizing downtime and (usually) reducing errors from erroneous commands.

+3
source share

There is probably a much cleaner way, but maybe install it as a Windows service and then install / uninstall command script using installutil.exe. Then just refresh the folder where the service is sitting and restart the script for each update?

Great maintenance tutorial here

Hope this helps

+2
source share

I would recommend writing a script that you could run on your PC that will perform the deployment over the network (so that you do not have to connect to the target machine each time). I did this with msbuild, but you really can just go to the batch file.

I assume that your administration process starts the Windows service (in any case, it makes sense to run it as a service), so you should deploy it (this is part of the msbuild script), you can delete the bit with the username and password if you do not need it ):

 <ItemGroup> <ReleaseFiles Include="localPath\bin\*.dll"/> <ReleaseFiles Include="localPath\bin\*.exe"/> <ReleaseFiles Include="localPath\bin\*.pdb"/> <ReleaseFiles Include="localPath\bin\*.config"/> </ItemGroup> <Target Name="Release"> <Message Text="Installing Admin on $(DeploymentMachine) as user $(User)"/> <Exec ContinueOnError="true" Command="sc.exe \\$(DeploymentMachine) stop &quot;Admin&quot;" /> <Exec ContinueOnError="true" Command="sc.exe \\$(DeploymentMachine) delete &quot;Admin&quot;" /> <Delete ContinueOnError="true" Files="\\$(DeploymentMachine)\C$\path-to-admin\*.*"/> <MakeDir Directories="\\$(DeploymentMachine)\C$\path-to-admin"/> <Copy SourceFiles="@(ReleaseFiles)" DestinationFiles="@(ReleaseFiles->'\\$(DeploymentMachine)\C$\path-to-admin\%(RecursiveDir)%(Filename)%(Extension)')" /> <Exec Command="sc.exe \\$(DeploymentMachine) create &quot;Admin&quot; binpath= &quot;C:\path-to-admin\admin.exe&quot; start= auto obj= $(User) password= $(Password)" /> <Exec ContinueOnError="true" Command="sc.exe \\$(DeploymentMachine) start &quot;Admin&quot;" /> </Target> 

Deploying IIS websites is usually a bit more painful, but if everything is set up on the target machine, it might just copy files over the network (again using \ DeploymentMachine \ share or \ DeploymentMachine \ C $ \ path).

Unfortunately, deployment is never pleasant and elegant :(

Please let me know if you need to clarify anything.

+2
source share

Here is an unpleasant thought. If you admin.exe does not do anything too heavy a kernel, why not throw in IIS? To write a C # web service, you probably won't have to change much.

For it to be called repeatedly, you can use any of a variety of methods, such as the Windows Scheduler, to run wget once a minute. Keep parallel copies from working with file locking if it ever takes MORE than one minute to complete.

This will make your deployment as easy as copying a file (FTP). I don’t even think you need to restart IIS by clicking the C # DLL. If you do this, you can script to exceed SSH.

+1
source share

For me, your problem sounds the same as the SharePoint deployment problem solves through its timer service running in each WFE, stsadm enqueuing admin task, this service uninstalls and starts them, etc.

What i would do is

  • write a service running in each WFE
  • write a small custom tool called “stsadm” so you can queue tasks, indicate when they need to run, etc.

Another approach: how about using a regular Windows task scheduler? Look here , you can easily remotely run tasks for ex.

0
source share

I would write a command line application that does all this.

Here is an example:

 Site.api.publish(); admin.api.shutdown(); while(shell.status("admin.exe") == true) {}; //still running file.replace("admin.exe", "path-to-compile\admin.exe"); shell.run("admin.exe"); 

You probably understand. If you want this done automatically, just use the "Task Schedule" to call it every day, or often you want it.

0
source share

Save to the server / web the latest version of the project that is online. for example: in the version.txt file the value is "2.1.0" or query the database if you have access too.

Your application running on clients will periodically read the contents of the version.txt file and then compare with the built-in version number.

  • If a patch or minor release, for example, 2.1.123, is found, turn out the second application (updater.exe), which will be quiet
    • upgrade,
    • it downloads the updated (preferred archived) project from the server / network.
    • Stop all running instances.
    • Unzip the contents.
    • Back up existing files (rename)
    • copy / install a new version of the project,
    • Launch the application (upon successful restart of the application, it will delete its own backup file).
  • if a major release is detected, for example: 3.0.0
    • notifies the user of a major update
    • if the user accepts, the installer downloads
    • launches a full installer update

Does it help?

0
source share

The VS deployment project for a web application is not easy to learn and somewhat unreliable. What I suggest:

  • Change your Admin.exe to the .NET Windows service. See why you need it.
  • Use sc.exe, InstallUtil.exe, or the installer utilities, such as installer.codeeffects.com, to quickly install the service on each deployment. By the way, if I remember correctly, on installer.codeeffects.com you can download an example of VS code, how to build a .NET Windows service if you are new to services.

Deployment can be done as follows (assuming that your automation needs are minimal, and you are perfectly deploying almost manually):

Run any of the above tools to install the service first. The sc.exe and InstalUtil.exe tools support the command line. Therefore, if your web application, VS and service are running on the same computer (your development computer, I assume?), You can right-click the web project in VS, select "Properties" and set the commands "before or after assembly" in the "Events" tab. This way, your VS can automatically rebuild and reinstall your service before publishing your web application. This is the main reason exe is not suitable in your case, the Windows service will serve you better.

Then deploy your web application (assuming it was built as described above). There is nothing here, just use the Publish command from your VS or move all the files of your web application except the .cs, / Properties / and / obj / folders files. Or, if you are working from the project folder, simply right-click on the main page and select "View in Browser" - this will run the runtime through VS without launching the debugger.

Sorry for such a long post. Did I understand your question and clarification correctly? :)

0
source share

How about admin.exe clicking after deployment. Then, in your admin.exe before checking the integrity of the business rules, check if there is an update. If so, update and then continue your checks.

0
source share

To make things simple and make sure that I can drop everything, I would create a PowerShell Script that does the following:

  • Stop application pool.
  • Copy the current web application to the “history folder” so that you can roll back to this version if required
  • Deploy a new web application
  • Stop current admin.exe from service
  • Remove admin.exe by executing Uninstall.bat (this is quite common for Windows services)
  • Copy the current admin.exe application to the history folder (see 2)
  • Copy the new admin.exe file to the correct location and run install.bat
  • Start new service
  • Launch Application Pool

You can automate all this in Powershell Script (the only thing I'm not sure about is the application pool, but I'm sure you can do it).

More information about PowerShell can be found here: http://arstechnica.com/business/news/2005/10/msh.ars/2

0
source share

All Articles