Advertisement
Guest User

reset

a guest
Jan 16th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.49 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ###
  4. # vCenter Server Appliance 6.0 Inventory Service Reset
  5. ##
  6.  
  7. echo '**********************************************************'
  8. echo 'Copyright 2016 VMware, Inc. All rights reserved'
  9. echo '**********************************************************​'
  10.  
  11. g_abort () {
  12. # Graceful Abort.
  13. echo -ne "ABORTING! "
  14. echo $1
  15. echo -ne "Aborting is strongly encouraged. Do you want to continue regardless? (y/N) "
  16. while true; do
  17. read -p "" YN
  18. case $YN in
  19. [Yy]*) break;;
  20. [Nn]*) exit 1;;
  21. *) exit;;
  22. esac
  23. done
  24. }
  25.  
  26. f_abort () {
  27. # Forceful Abort.
  28. echo -ne "FORCEFULLY ABORTING! "
  29. echo $1
  30. exit 1
  31. }
  32.  
  33. msg_header () {
  34. echo ""
  35. echo "###"
  36. echo "# $1"
  37. echo "##"
  38. echo ""
  39. }
  40.  
  41. msg_header "Resetting Inventory Service Database"
  42.  
  43. echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
  44. echo "┃ ╱╲ ┃"
  45. echo "┃ ╱ ╲ You should only ever use this if you cannot use: ┃"
  46. echo "┃ ╱ ╲ http://kb.vmware.com/kb/2113435 ┃"
  47. echo "┃ ╱ ╲ Always take a snapshot before running this script! ┃"
  48. echo "┃ ╱ ╲ You will lose Storage Profiles if you execute this script! ┃"
  49. echo "┃ ╱ WARNING! ╲ ┃"
  50. echo "┃ ──────────── ┃"
  51. echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
  52.  
  53. echo -ne "Are you sure you want to continue ? (y/N) "
  54. while true; do
  55. read -p "" YN
  56. case $YN in
  57. [Yy]*) break;;
  58. [Nn]*) exit;;
  59. *) exit;;
  60. esac
  61. done
  62.  
  63. ###
  64. # Setting up environment variables
  65. ##
  66.  
  67. for x in /usr/lib/vmware-invsvc/lib/*.jar; do
  68. CP="${CP}:$x";
  69. done;
  70. PATH_ROOT=/usr/lib/vmware-invsvc
  71.  
  72. TOOL_CLASSPATH=""
  73. TOOL_DIR=/usr/lib/vmware-vpx/inventoryservice-registration
  74.  
  75. for JAR in "${TOOL_DIR}"/*.jar; do
  76. if [ -f "${JAR}" ]; then
  77. TOOL_CLASSPATH="${TOOL_CLASSPATH}:${JAR}"
  78. fi
  79. done
  80.  
  81. TOOL_CLASSPATH="${TOOL_CLASSPATH}:${TOOL_DIR}"
  82.  
  83. ###
  84. # Getting data for Inventory Service config files
  85. ##
  86.  
  87. isinst=`grep -oP '\Q<instanceUuid>\E.*\Q</instanceUuid>\E' /usr/lib/vmware-vpx/endpoints/qs-endpoint.xml | sed -r 's_.*>(.*)<.*_\1_g'`
  88. ispw=`grep 'dataservice.xdb.password' /usr/lib/vmware-invsvc/lib/server/config/dataservice.properties | sed -r 's_dataservice.xdb.password=__g' | sed -r 's_[^a-zA-Z0-9]__g' `
  89. iscmurl=`grep dataservice.cm.url /usr/lib/vmware-invsvc/lib/server/config/dataservice.properties | sed -r 's_dataservice.cm.url=__g'`
  90.  
  91.  
  92. msg_header "Step 1: Stopping services: vSphere Web Client, Inventory Service, vCenter Server Service."
  93.  
  94. service vsphere-client stop || g_abort "Could not stop WebClient."
  95. sleep 5
  96. service vmware-invsvc stop
  97. sleep 5
  98. service vmware-vpxd stop || g_abort "Could not stop vCenter Server Service."
  99.  
  100.  
  101. msg_header "Step 2: Deleting old Inventory Service Database."
  102.  
  103. rm -rf /storage/invsvc/xdb || g_abort "Could not delete directory: /storage/invsvc/xdb"
  104.  
  105. msg_header "Step 3: Preparing the new dataservice.properties file."
  106.  
  107. echo "Inventory Service Instance UUID: ${isinst}"
  108. echo "Inventory Service Simplified Password: ${ispw}"
  109.  
  110. grep -v 'dataservice.xdb.password' /usr/lib/vmware-invsvc/lib/server/config/dataservice.properties >> /tmp/isdsprops
  111. echo "dataservice.xdb.password=${ispw}" >> /tmp/isdsprops
  112. echo "dataservice.instanceUuid=${isinst}" >> /tmp/isdsprops
  113.  
  114. cp /usr/lib/vmware-invsvc/lib/server/config/dataservice.properties /tmp/dataservice.properties.bak
  115. cp /tmp/isdsprops /usr/lib/vmware-invsvc/lib/server/config/dataservice.properties || g_abort "Could not write new dataservice.properties file."
  116.  
  117. msg_header "Step 4: Creating a new Inventory Service Database"
  118.  
  119. java -classpath ${CP} -Dds.dbdir="/storage/invsvc/data/xdb" \
  120. -Dvim.logdir="/var/log/vmware/invsvc" \
  121. -Dds.servicecfg="${PATH_ROOT}/lib/server/config/dataservice.properties" \
  122. -Dis_upgrade_uuid="${isinst}" \
  123. com.vmware.vim.dataservices.CreateDb \
  124. /storage/invsvc/xdb \
  125. /storage/invsvc/xdb/xdblog \
  126. default \
  127. default \
  128. "${ispw}" \
  129. 4096 || g_abort "Could not create empty Inventory Service database."
  130.  
  131. msg_header "Step 5: Getting the current vCenter Server Solution User Certificates"
  132.  
  133. mkdir -p /tmp/ssl || g_abort "Could not create temporary ssl folder."
  134. /usr/lib/vmware-vmafd/bin/vecs-cli entry getkey --store vpxd --alias vpxd --output /tmp/ssl/rui.key || f_abort "Could not fetch vCenter Server Solution User private key."
  135. /usr/lib/vmware-vmafd/bin/vecs-cli entry getcert --store vpxd --alias vpxd --output /tmp/ssl/rui.crt || f_abort "Could not fetch vCenter Server Solution User certificate."
  136.  
  137. echo "Done."
  138.  
  139. msg_header "Step 6: Starting Inventory Service"
  140.  
  141. service vmware-invsvc start || f_abort "Inventory Service failed to start. Check /var/log/vmware/invsvc/inv-svc.log"
  142. sleep 3
  143.  
  144. msg_header "Step 7: Starting vCenter Server Service"
  145.  
  146.  
  147. service vmware-vpxd start || f_abort "vCenter Server Service failed to start. Check /var/log/vmware/vpxd/vpxd.log"
  148.  
  149. msg_header "Step 8: Re-registering vCenter Server Service to Inventory Service."
  150.  
  151. mkdir -p /tmp/vcreglogs
  152. /usr/java/jre-vmware/bin/java -classpath "${TOOL_CLASSPATH}" -Dvim.logdir="/tmp/vcreglogs" com.vmware.vim.dataservices.vcregtool.RegisterVC \
  153. -action register \
  154. -cmurl "${iscmurl}" \
  155. -vcfeedurl 'http://localhost:8095' \
  156. -vccert /tmp/ssl/rui.crt \
  157. -vcprivkey /tmp/ssl/rui.key \
  158. -vcinstancecfg /etc/vmware-vpx/instance.cfg \
  159. -vcendpointsdir /usr/lib/vmware-vpx/endpoints \
  160. -vcextensionsdir /etc/vmware-vpx/extensions \
  161. -vcforceregister true || f_abort "Registration failed."
  162.  
  163. sleep 5
  164.  
  165. msg_header "Step 9: Restarting all services."
  166.  
  167. service-control --stop
  168. service-control --start
  169.  
  170. msg_header "Done. Wait for vSphere WebClient to start to confirm normal operation."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement