How to deploy an ASP.NET Application with zero downtime

后端 未结 11 1384
日久生厌
日久生厌 2020-11-28 00:38

To deploy a new version of our website we do the following:

  1. Zip up the new code, and upload it to the server.
  2. On the live server, delete all the live
11条回答
  •  一个人的身影
    2020-11-28 01:14

    This is how I do it:

    Absolute minimum system requirements:
    1 server with

    • 1 load balancer/reverse proxy (e.g. nginx) running on port 80
    • 2 ASP.NET-Core/mono reverse-proxy/fastcgi chroot-jails or docker-containers listening on 2 different TCP ports
      (or even just two reverse-proxy applications on 2 different TCP ports without any sandbox)

    Workflow:

    start transaction myupdate

    try
        Web-Service: Tell all applications on all web-servers to go into primary read-only mode 
        Application switch to primary read-only mode, and responds 
        Web sockets begin notifying all clients 
        Wait for all applications to respond
    
        wait (custom short interval)
    
        Web-Service: Tell all applications on all web-servers to go into secondary read-only mode 
        Application switch to secondary read-only mode (data-entry fuse)
        Updatedb - secondary read-only mode (switches database to read-only)
    
        Web-Service: Create backup of database 
        Web-Service: Restore backup to new database
        Web-Service: Update new database with new schema 
    
        Deploy new application to apt-repository 
        (for windows, you will have to write your own custom deployment web-service)
        ssh into every machine in array_of_new_webapps
        run apt-get update
        then either 
        apt-get dist-upgrade
        OR
        apt-get install 
        OR 
        apt-get install --only-upgrade 
        depending on what you need
        -- This deploys the new application to all new chroots (or servers/VMs)
    
        Test: Test new application under test.domain.xxx
        -- everything that fails should throw an exception here
        commit myupdate;
    
        Web-Service: Tell all applications to send web-socket request to reload the pages to all clients at time x (+/- random number)
        @client: notify of reload and that this causes loss of unsafed data, with option to abort 
    
        @ time x:  Switch load balancer from array_of_old_webapps to array_of_new_webapps 
        Decomission/Recycle array_of_old_webapps, etc.
    
    catch
            rollback myupdate 
            switch to read-write mode
            Web-Service: Tell all applications to send web-socket request to unblock read-only mode
    end try 
    

提交回复
热议问题