What's the best way to deploy an executable process on a web server?

后端 未结 11 1295
一生所求
一生所求 2021-02-02 03:35

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.

相关标签:
11条回答
  • 2021-02-02 03:41

    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?

    0 讨论(0)
  • 2021-02-02 03:44

    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

    0 讨论(0)
  • 2021-02-02 03:46

    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

    0 讨论(0)
  • 2021-02-02 03:51

    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.

    0 讨论(0)
  • 2021-02-02 03:53

    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.

    0 讨论(0)
  • 2021-02-02 03:55

    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"));
        }
    
    0 讨论(0)
提交回复
热议问题