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

Install a virtual host on WebSphere 5.1 base installation.

Called from a Windows bat file.

@echo off

set vhName=your_host set vh=www.yoursite.com

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

command.com /c

call wsadmin -username userid^ -password password^ -f C:\scripts\websphere\JACL\installVirtualHost.tcl %vhName% %vh%

Tcl, 107 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
# 
# Install Virtual Host.
#
####################################################################
# 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 ]
#	puts [ format "%-10s %-50s\n" " "  $3 ]
	lappend returnList                 $2
    }

    puts \n

    return $returnList   
}
####################################################################
# Create Virtual Host.
####################################################################
proc installVHost { virtualhostName virtualHost nodeId } {

   global AdminConfig 

   set port     [ list port     9081 ] 
   set host     [ list hostname $virtualHost ]

   set aliases  [ list aliases [ list [list $port $host ]]]

   set name     [ list name     $virtualhostName ]
  
   set attrList [ list          $name $aliases ]

   if { [ catch {$AdminConfig create VirtualHost $nodeId $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"
}

set virtualhostName [lindex $argv 0]
set virtualHost     [lindex $argv 1]
set nodeName        [ exec hostname ] 
set nodeId          [ $AdminConfig getid /Node:$nodeName/ ]

#######################################################################
# 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 $virtualHost $nodeId } 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

Automated repeatable install of virtual host.

1 comment

Patrick Finnegan (author) 17 years, 3 months ago  # | flag

Scope level. To set the virtual host at the cell level use cellName instead of nodeName.

set cellName [ exec hostname ] set cellId [ $AdminConfig getid /Cell:$cellName/ ]

Created by Patrick Finnegan on Tue, 31 Aug 2004 (MIT)
Tcl recipes (162)
Patrick Finnegan's recipes (56)

Required Modules

  • (none specified)

Other Information and Tasks