Welcome, guest | Sign In | My Account | Store | Cart

Install multiple virtual hosts.

Tcl, 120 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 
# Install Virtual Hosts.
#
####################################################################
# Patrick Finnegan 01/09/2004.  V1. 
####################################################################

####################################################################
# List installed virtual hosts.
####################################################################
proc showList { a } {

    puts "\nList installed virtual hosts"
    puts "\**********************\n"

    foreach e $a {
	regexp {(.*)(\(cells.*)} $e 1 2 3
	puts [ format "%-5s %-50s"  " "  $2 ]
	lappend returnList                 $2
    }

    puts \n

    return $returnList   
}
####################################################################
# Create Virtual Host.
####################################################################
proc installVHost { virtualhostName hostAliases cellId } {

   global AdminConfig 

   foreach i $hostAliases {

       set hostname  [ list hostname [ lindex  [split $i : ] 0 ] ]
       set port      [ list port     [ lindex  [split $i : ] 1 ] ]

       set hostAlias [ list $hostname $port ]

       lappend hostAliasList $hostAlias  

   }
 
   set aliases  [ list aliases $hostAliasList ]
   set name     [ list name $virtualhostName ]

   set attrList [ list $name $aliases ] 

   if { [ catch {$AdminConfig create VirtualHost $cellId $attrList} r ] == 0 } {
        puts "************************************"
        puts "$virtualhostName virtual host created successfully."
        puts "************************************\n"
   } else {
           puts "\nfailed to create $virtualhostName virtual host\n"
           puts "************************************\n"
	   return -code error $r
   }

}
####################################################################
# Main Control.
####################################################################

puts "\n argc = $argc \n"

if {$argc < 2} {
        return -code error "error - no arguments supplied.  Supply virtual host name"
        puts "no arguments"
}

# the first argument is the logical name
# the remaining arguments are the host aliases.

set virtualhostName [ lindex $argv 0 ]
set hostAliases     [ lrange $argv 1 end ] 

set cellId [ lindex [ $AdminConfig list Cell ] 0 ]
set nodeId [ lindex [ $AdminConfig list Node ] 0 ]

#######################################################################
# List virtual hosts check if target virtual host already exists.
# If so delete it and recreate.
#######################################################################

set vHosts [ $AdminConfig list VirtualHost ]

catch { showList $vHosts } r

catch {lsearch $r $virtualhostName } r 

if { $r == -1 } {
    set continue true 
} else { 
        set vHostId [ $AdminConfig getid /VirtualHost:$virtualhostName/ ]
        catch { $AdminConfig remove $vHostId } r
	puts $r
}
####################################################################
# Install virtual host  
####################################################################

if { [ catch { installVHost $virtualhostName $hostAliases $cellId } r ] == 0 } {
    puts "************************************"
    puts "$virtualhostName installed successfully"
    puts "************************************\n"
    puts "\n###### Admin Config Save ######\n"
    $AdminConfig save
} else {
        puts "\n$virtualhostName failed to install\n"
        puts $r 
        puts "************************************\n"
}

####################################################################
# List virtual hosts to verify install 
####################################################################

set vHosts [ $AdminConfig list VirtualHost ]

catch { showList $vHosts } r

Windows calling script looks like:


pushd D:\IBM\WebSphere\DeploymentManager\bin

set vhName=vh1 set vh1="www.yoursite.com:80" set vh2="www.yoursite.com:9082" set vh3="yourhost:80" set vh4="yourhost:9082"

echo ################################################### echo # Install %vhName% on %COMPUTERNAME% echo ###################################################

command.com /c

call wsadmin -username wsadminlogon^ -password wsadminlogon^ -f d:\scripts\websphere\JACL\installVirtualHost.tcl %vhName%^ %vh1%^ %vh2%^ %vh3%^ %vh4%

popd

Created by Patrick Finnegan on Tue, 18 Oct 2005 (MIT)
Tcl recipes (162)
Patrick Finnegan's recipes (56)

Required Modules

  • (none specified)

Other Information and Tasks