Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

334 lines
9.5 KiB

  1. REM =================================================================================
  2. REM
  3. REM IIS_SWITCH <Cluster_Name> [<group_name>]
  4. REM
  5. REM
  6. REM Replace IIS resources (Web and FTP) with generic scripts.
  7. REM Note: If you chose to replace all groups, then the resource types that are
  8. REM not supported by Windows Server 2003 will also be deleted by the script
  9. REM
  10. REM Copyright (c) 2001 Microsoft Corporation
  11. REM
  12. REM =================================================================================
  13. Option Explicit
  14. REM ---------------------------------------------------------------------------------
  15. REM DeleteResourceTypes (objCluster)
  16. REM
  17. REM Delete the resource types that are not valid in Windows Server 2003
  18. REM ---------------------------------------------------------------------------------
  19. sub DeleteResourceTypes(objCluster)
  20. Dim colTypes
  21. Dim objType
  22. Dim colRes
  23. on error resume next
  24. set colTypes = objCluster.ResourceTypes
  25. REM Delete IIS resource type
  26. set objType = colTypes.Item("IIS Server Instance")
  27. set colRes = objType.Resources
  28. if colRes.Count = 0 then
  29. objType.Delete
  30. end if
  31. REM Delete SMTP resource type
  32. set objType = colTypes.Item("SMTP Server Instance")
  33. set colRes = objType.Resources
  34. if colRes.Count = 0 then
  35. objType.Delete
  36. end if
  37. REM Delete NNTP resource type
  38. set objType = colTypes.Item("NNTP Server Instance")
  39. set colRes = objType.Resources
  40. if colRes.Count = 0 then
  41. objType.Delete
  42. end if
  43. end sub
  44. REM ---------------------------------------------------------------------------------
  45. REM SwitchResource (objOld, objNew)
  46. REM
  47. REM Switch old object out of the tree and put in the new object
  48. REM Rebuild all the dependencies
  49. REM ---------------------------------------------------------------------------------
  50. sub SwitchResource(objOld, objNew)
  51. Dim colOldDeps
  52. Dim colNewDeps
  53. Dim objDep
  54. REM Switch out the dependent resources
  55. REM
  56. set colOldDeps = objOld.Dependents
  57. set colNewDeps = objNew.Dependents
  58. for each objDep in colOldDeps
  59. colOldDeps.RemoveItem objDep.Name
  60. colNewDeps.AddItem objDep
  61. next
  62. REM Switch out the dependencies
  63. REM
  64. set colOldDeps = objOld.Dependencies
  65. set colNewDeps = objNew.Dependencies
  66. for each objDep in colOldDeps
  67. colOldDeps.RemoveItem objDep.Name
  68. colNewDeps.AddItem objDep
  69. next
  70. end Sub
  71. REM ---------------------------------------------------------------------------------
  72. REM CreateGenScript(objGroup, strName, web)
  73. REM
  74. REM Routine to create a generic script resource in a specific group
  75. REM ---------------------------------------------------------------------------------
  76. Function CreateGenScript(objGroup, strName, web)
  77. Dim colResources
  78. Dim objResource
  79. Dim colPrivateProps
  80. Dim strScript
  81. if web then
  82. strScript = "%windir%\system32\inetsrv\clusweb.vbs"
  83. else
  84. strScript = "%windir%\system32\inetsrv\clusftp.vbs"
  85. end if
  86. set colResources = objGroup.Resources
  87. set objResource = colResources.CreateItem(strName, "Generic Script", 0)
  88. set colPrivateProps = objResource.PrivateProperties
  89. colPrivateProps.CreateItem "ScriptFilepath", strScript
  90. colPrivateProps.SaveChanges
  91. set CreateGenScript = objResource
  92. end Function
  93. REM ---------------------------------------------------------------------------------
  94. REM UpgradeIIS(objCluster, objGroup)
  95. REM
  96. REM Routine to upgrade all Web and FTP resources to Windows Server 2003 resource
  97. REM ---------------------------------------------------------------------------------
  98. Sub UpgradeIIS(objCluster, objGroup)
  99. DIM colResources
  100. DIM objResource
  101. DIM objNewResource
  102. DIM colPrivateProps
  103. DIM objProp
  104. DIM resName
  105. DIM boolWeb
  106. DIM oldState
  107. on error resume next
  108. Err.Clear
  109. REM Take the cluster group offline if it is online
  110. REM it is not online or offline, return an error
  111. REM
  112. oldState = objGroup.state
  113. if objGroup.state = 0 then
  114. objGroup.offline 5000
  115. end if
  116. if objGroup.state = 3 then
  117. objGroup.offline 5000
  118. end if
  119. do while objGroup.state = 4
  120. sleep (5)
  121. loop
  122. if objGroup.state <> 1 then
  123. wscript.echo "ERROR: The group '" + objGroup.Name + "' is not in a state to perform this operation"
  124. wscript.quit(1)
  125. end if
  126. REM Find all IIS resources (Web and FTP) in the group
  127. REM
  128. set colResources = objGroup.Resources
  129. for each objResource in colResources
  130. REM Look for IIS resources
  131. REM
  132. if objResource.TypeName = "IIS Server Instance" then
  133. resName = objResource.Name
  134. REM Figure out whether it is an FTP resource or a Web resource
  135. REM
  136. set colPrivateProps = objResource.PrivateProperties
  137. set objProp = colPrivateProps.Item("ServiceName")
  138. boolWeb = (objProp.Value = "W3SVC")
  139. REM Rename the old resource
  140. REM
  141. objResource.Name = resName + " (W2K)"
  142. REM Switch out the old resource and plumb in the new one
  143. REM
  144. set objNewResource = CreateGenScript(objGroup, resName, boolWeb)
  145. SwitchResource objResource, objNewResource
  146. REM Now delete the old resource and print out a message (assuming nothing broke)
  147. REM
  148. if Err.Number = 0 then
  149. objResource.Delete
  150. if boolWeb then
  151. wscript.echo "INFO: Upgraded IIS Web resource '" + resName + "'"
  152. else
  153. wscript.echo "INFO: Upgraded IIS FTP resource '" + resName + "'"
  154. end if
  155. else
  156. REM Catch any errors that may have happened
  157. REM
  158. wscript.echo "ERROR: Failed to convert resource '" + resName + "': " + Err.Description
  159. Err.Clear
  160. end if
  161. end if
  162. next
  163. REM Ok, move the group to the Whistler node and put it back in the
  164. REM online state if it was there before
  165. REM
  166. if oldstate = 0 then
  167. objGroup.Move 10000
  168. objGroup.Online 0
  169. end if
  170. end Sub
  171. REM ---------------------------------------------------------------------------------
  172. REM UpgradeGroup(objCluster, objGroup)
  173. REM
  174. REM Routine to upgrade a single group
  175. REM ---------------------------------------------------------------------------------
  176. Sub UpgradeGroup(objCluster, objGroup)
  177. DIM colResources
  178. DIM objResource
  179. DIM boolFound
  180. DIM objProp
  181. REM Figure out whether this group needs any work done to it
  182. REM
  183. boolFound = False
  184. set colResources = objGroup.Resources
  185. for each objResource in colResources
  186. if objResource.TypeName = "IIS Server Instance" then
  187. boolFound = True
  188. end if
  189. next
  190. REM If we found an IIS resource, make sure it is not the cluster group
  191. REM and then go upgrade it
  192. REM
  193. if boolFound then
  194. set objResource = objCluster.QuorumResource
  195. set objProp = objResource.Group
  196. if objProp.Name = objGroup.Name then
  197. wscript.echo "WARN: Skipping group '" + objProp.Name + "'"
  198. wscript.echo " An IIS resource exists in the cluster group, this is not a supported configuration"
  199. else
  200. UpgradeIIS objCluster, objGroup
  201. end if
  202. end if
  203. end Sub
  204. REM ---------------------------------------------------------------------------------
  205. REM main
  206. REM
  207. REM Main entry point for switch utility
  208. REM Usage:
  209. REM switch <cluster_name> [<group_name>]
  210. REM ---------------------------------------------------------------------------------
  211. sub main
  212. Dim args
  213. Dim objCluster
  214. Dim objGroup
  215. Dim colGroups
  216. Dim colTypes
  217. Dim objType
  218. on error resume next
  219. wscript.echo "Server Cluster (MSCS) upgrade script for IIS resources V1.0"
  220. REM Check for the arguments
  221. REM
  222. set args = Wscript.Arguments
  223. if args.count < 1 then
  224. wscript.echo "Usage: iis_switch <cluster_name> [<group_name>]"
  225. wscript.quit(1)
  226. end if
  227. REM Open a handle to the cluster
  228. REM
  229. Set objCluster = CreateObject("MSCluster.Cluster")
  230. objCluster.Open (args(0))
  231. if Err.Number <> 0 then
  232. wscript.echo "ERROR: Unable to connect to cluster '" + args(0) + "': " + Err.Description
  233. wscript.quit(1)
  234. end if
  235. REM Check that this script is being run on a node that has the generic script resource
  236. REM i.e. a Windows Server 2003 cluster node
  237. REM
  238. set colTypes = objCluster.ResourceTypes
  239. set objType = colTypes.Item("Generic Script")
  240. if Err.Number <> 0 then
  241. wscript.echo "ERROR: You must execute this script against a Windows Server 2003 node"
  242. wscript.quit(1)
  243. end if
  244. REM Either upgrade all groups or just the specified group
  245. REM
  246. if args.count = 1 then
  247. set colGroups = objCluster.ResourceGroups
  248. for each objGroup in colGroups
  249. UpgradeGroup objCluster, objGroup
  250. next
  251. else
  252. set colGroups = objCluster.ResourceGroups
  253. set objGroup = colGroups.Item(args(1))
  254. UpgradeGroup objCluster, objGroup
  255. end if
  256. REM delete the resource types that are no longer supported
  257. DeleteResourceTypes objCluster
  258. end sub
  259. main()