Forum Discussion

dlegate_23320's avatar
dlegate_23320
Icon for Nimbostratus rankNimbostratus
Mar 09, 2012

iRule to Migrate to new server based on URL (directory) text?

Can iRules direct requests to a specific server/s based on text in the URL?

 

 

Scenario:

 

 

We have an old production server (physical) that is NOT load balanced.

 

 

We have new virtual servers to replace that server.

 

 

Instead of doing one massive cut-over for all the applications on this server, we wondered if we put the phyiscal server behind the F5 (with the new virtual replacements).

 

 

At first, we make sure ALL requests only go to server1.com (original physical server).

 

 

Then, when each application is "ready" on the new servers, one-by-one we add their directory name to an iRule and based on that, the request goes to the new server/s instead of the old.

 

 

For example, let's say we have an application at:

 

 

https://server.com/app1/

 

 

still being delivered from server1.com. But we've moved all its code to server2.com and server3.com, and they are ready to start handling those requests.

 

 

We add an iRule that sees "app1" in the URL and makes sure those requests are ONLY handled by server2.com and server3.com and NEVER by server1.com.

 

 

Is that possible with an iRule?

 

 

Thanks!

 

 

Dan

 

3 Replies

  • Hi Dan,

     

     

    If all of the content for each application is under a single directory, this should be really simple to implement using a switch statement in an iRule. Here's an example. As you want to move new apps to a separate pool, just add the path to the switch statement and point it to a new pool

     

     

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::path]] {
          "/app1*" {
             pool app1_pool
          }
          "/app2*" {
             pool app2_pool
          }
          default {
             pool default_pool
          }
       }
    }

     

     

    Or if all of the new servers have the code for all of the URIs, you could combine the switch cases to point to a single new pool:

     

     

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::path]] {
          "/app1*" -
          "/app2*" -
          "/app3*" {
             pool app2_pool
          }
          default {
             pool default_pool
          }
       }
    }

     

     

    Aaron
  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    Just an aside. Although doing the globs above is quick and easy (and performs well too), you will run the risk of breaking your site a little if you get the irule wrong when editing it on the fly (changing logic is always interesting ;) and if you have a lot of sites it will quickly get to be quite long...

     

     

    To reduce risk of breaking migrated apps wth the change to add new ones I'd use a datagroup and a lookup via the [class ...] commands.

     

     

    You could always use the ProxyPass iRule from the codeshare too... New sites are then just a datagroup edit away. (In fact id recommend reading the ProxyPass iRule anyway. It will show you a lot of stuff thats possible with an iRule).

     

     

    H
  • Thanks to you both!

     

     

    Aaron, when you say "under a single directory" does that include sub-directories? All apps are self-contained within their own directories, however they do have sub-directories.

     

     

    I will look into both of the options you mentioned.

     

     

    Dan