views:

430

answers:

11

The original question:

The title of this question might be a bit clumsily phrased, but here's the situation:

I have a .NET web project deployed on my server. It's still in beta, so there's a lot of releasing and re-releasing happening.

I have also written a C# executable in the same VS solution (call it "admin.exe") that runs in the background on the server, periodically performing certain business rule integrity checks and making appropriate insertions to a warning table in the DB.

Question is: what's the best way to deploy this app so that it gets updated whenever I make a new release? It should be running all the time in between releases, so ideally I'd like some sort of setup whereby the shutdown-deploy-startup process involves the minimum possible number of steps.

Thanks!

Edit - Bounty started

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

  1. Publish the latest version of the web site;
  2. Shut down any instances of admin.exe that are running on the server;
  3. Update admin.exe;
  4. Launch admin.exe;
  5. All of the above should be done preferably in one step, or as few steps as possible, seeing as it will be done repeatedly throughout the life of the product; and
  6. All of the above should be done preferably without requiring installation of any 3rd party software.

Thank you for your help!

Minor edit - clarification

I think a lot of the solutions offered thus far have overestimated the complexity of the problem, so let me clarify: everything that is to be deployed, only has to be deployed on one computer, which also happily has Visual Studio available with all source code. I only need to (1) publish the web site to the web folder, and (2) shut down, reinstall and restart admin.exe on the same server. Isn't there a simple way of doing this in one step? Can it be done with a VS Deployment project?

+2  A: 

There is probably a much cleaner way but maybe install it as a windows service then script the install / uninstall commands using installutil.exe. Then just update the folder where the service sits and re-run the script for each update?

Great service tutorial here

Hope this helps

Jammin
Thanks for your answer - please see my edits for further clarification
Shaul
+3  A: 

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

MSBuild does much more than just build solutions. You can also use it to copy files and update them, too. A good resource for tasks to do this is the MSBuild Community Tasks here.

You can then include the deployment of your background process alongside the deployment of the Web site deployment.

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

Both these kinds of approach can be automated very well with continuous integration servers such as Hudson. I have a build process that automatically monitors my source code repository, builds the program, deploys to a staging server, runs acceptance tests, then deploys to a preview box. I have another (manual) job that with one click deploys this preview version to live, minimising downtime and (usually) reducing errors from mistiped commands.

Jeremy McGee
Thanks for your answer - please see my edits for further clarification
Shaul
A: 

To me, your problem sounds a lot like the deployment problem SharePoint solves through their Timer service running in each WFE, stsadm enqueuing admin tasks, that service dequeuing and running them etc.

What I would do is to

  • write a service running in each WFE
  • write a small custom "stsadm" tool so you can enqueue tasks, specify when they need to run, etc.

Another approach: what about using the plain vanilla Windows Task Scheduler? Look here, you can easily enqueue tasks remotely for ex.

Ariel
Thanks for your answer - please see my edits for further clarification
Shaul
A: 

I would write a command-line application that would do all of that.

Here is a rough 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 get the point. If you want it to do it automatically just use the Task Schedular to call it every day, or however often you want it.

Arlen Beiler
Thanks for your answer - please see my edits for further clarification
Shaul
A: 

Store on the server/web the most recent version of the project that is online. eg: in a version.txt the value "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, then compared against the inbuilt(self) version number.

  • If a patch or minor release is detected eg 2.1.123, spins out a second app(updater.exe) that will quietly
    • do the upgrade,
    • it shall download the updated(preferred zipped) project from server/web.
    • Stop any running instances.
    • Unzipping the content.
    • Backup existing files(rename)
    • copy/install the new version of the project,
    • Start the application (when the app is restarted successfully it will delete its own backup file).
  • if a major release is detected eg: 3.0.0
    • notifies the user there is a major upgrade
    • if user accepts, download the installer
    • runs a full installer update

Does this help?

Pentium10
Thanks for your answer - please see my edits for further clarification
Shaul
+1  A: 

Hi,

I would recommend writing a script that you could run on your PC, that would do the deployment over the network (so that you don't have to log in to the target machine every time). I have done it using msbuild, but you can really just go for a batch file.

I assume your admin process is running a windows service (anyway, it makes sense to run it as a service), so you would deploy it like this (this is part of the msbuild script - you can delete the bits with username and password if you don't 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 web sites is usually a bit more pain, but if you have everything set up on the target machine then possibly it would work to just copy the files over the network (again using the \DeploymentMachine\share or \DeploymentMachine\C$\path addressing).

Unfortunately deployment is never nice nor elegant :(

Please let me know if you need clarification on anything

Grzenio
A: 

VS Deployment project for a web app is not that easy to master and somewhat not reliable. What I'd suggest:

  1. Modify your Admin.exe into a .NET Windows service. Seebelow why would you need to do it.
  2. Use sc.exe, InstallUtil.exe or installer-building services like installer.codeeffects.com to reinstall your service fast on every deployment. Btw, if I remember correctly, at installer.codeeffects.com you can download a VS example code of how to build a .NET Windows service if you're new to services.

Deployment could be done like this (assuming that your needs in automation is minimal and you're fine deploying almost manually):

Run either of the above mentioned tools to reinstall your service first. The sc.exe and InstalUtil.exe tools support command line. Therefore, if your web app, VS and the service is running on the same machine (your development computer, I assume?), you can right-click the web project in VS, select Properties and set pre- or post-build commands in the Build Events tab there. This way your VS can automatically rebuild and reinstall your service before you publish your web app. This is the main reason why the exe program is not good in your case, a Windows service would serve you better.

Then deploy your web app (assuming it's been build as discussed above). No biggies here, just use the Publish command from your VS or move all files of your web app except for the .cs files, /Properties/ and /obj/ folders. Or, if running from the project's folder, just right click the main page and select "View in Browser" - this will start the run time through VS without starting the debugger.

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

Jane
+1  A: 

The "correct" way is probably to set up deployment scripts and installers, but being able to just click publish in Visual Studio and skip going in with remote desktop is a lot more convenient during development.

I have an admin web app that acts as a front end to a command line app - slightly different from what you are doing, but the same solution should work.

Simply add a reference to the console project in the admin web app. Even though you don't call any methods in the console project, the reference will cause the console app to be rebuilt and uploaded when you publish the admin website.

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

Below is the code from my start/stop page - I have them set up as web service methods (to facilitate some monitoring stuff you probably won't need), but they should work just as well called from a simple button click method. Note that the service account will need permission to run/stop the process - on a dev box the simplest option is to set up iis to run as an admin user rather than 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"));
    }
Tom Clarkson
+1 This is sounding very promising. Please clarify what you mean by a "start/stop" page in the web app - I'm not (yet) fluent in ASP.NET...
Shaul
+ bounty: I haven't had time to get around to implementing this solution, but the bounty clock is running out in a few hours, and so far this solution is looking the most promising. You really nailed it with your statement "... being able to just click publish in Visual Studio... is a lot more convenient during development. I may contact you again for help ironing out the actual solution.Thank you!
Shaul
+1  A: 

Here's a nasty thought. If you're admin.exe isn't doing anything too hard core, why not throw into IIS? To write a C# Web Service, you probably won't need to change much.

To ensure it gets called repeatedly, you could use any variety of methods, like Windows Scheduler to run wget once a minute. Keep concurrent copies from running with a file lock, should it ever take MORE than one minute to complete.

This would make your deployment as simple as a file copy (FTP). I don't even think you need to reboot IIS when pushing a C# DLL. If you do, you can script that up over SSH.

Pestilence
A: 

What about making admin.exe a click once deployment. Then in your admin.exe, before you check the integrity of business rules, check if an update is available. If it is, update and then continue on with your checks.

taylonr
A: 

In order to make things simple and make sure I would be able to roll back everything, I would create a PowerShell Script that performed the following actions:

  1. Stop the Application Pool.
  2. Copy the current web app to the "history folder" so you can rollback to that version if required
  3. Deploy the new web app
  4. Stop the current admin.exe from services
  5. Uninstall the admin.exe, by executing the Uninstall.bat (this is quite common for Windows Services)
  6. Copy the current admin.exe app to the history folder (see 2)
  7. Copy the new admin.exe to the correct location and run install.bat
  8. Start the new service
  9. Start the application Pool

You can automate all of that in a Powershell script (the only thing I'm not sure is about the app pool, but I'm pretty sure that you can do this).

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

Wagner Silveira