1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | # This script deploys a archiver appliance build onto a appliance into four separate JVM's as per the documentation.
|
---|
4 | # The artifacts from the build are four war files that are independent of each other.
|
---|
5 | # One can choose to deploy all of these on one JVM; however, as the archiver appliance is a fairly memory intensive application; this can adversely impact GC on the single JVM.
|
---|
6 | # Also, one does not want a large user retrieval to affect the engine or ETL.
|
---|
7 | # Therefore, there are some advantages to deploying each war file on a separate JVM.
|
---|
8 |
|
---|
9 | # This script uses TOMCAT_HOME to determine the source of the Tomcat distribution.
|
---|
10 | # It then makes four subfolders in the specified folder, one each for the mgmt, engine, etl and retrieval webapps.
|
---|
11 | # It copies over the necessary content from the source into each of these subfolders and adjusts the configuration as necessary.
|
---|
12 | # It then deploys the war files into the appropriate tomcats.
|
---|
13 | # The war files are assumed to be in the parent folder; however you can use an option to override this.
|
---|
14 |
|
---|
15 | # This is the just the deployment step; you can then have individual /etc/init.d scripts (or use commons daemon) to start the four webapps.
|
---|
16 | # So your deployment script should be something like 1) Stop webapps 2) Deploy webapps using this script 3) Start webapps.
|
---|
17 |
|
---|
18 | # The appliance port configuration is determined from appliances.xml as specified in the ARCHAPPL_APPLIANCES environment variable.
|
---|
19 | # The identity for this appliance is determined from the ARCHAPPL_MYIDENTITY environment variable and ise used to lookup the parameters for this appliance in appliances.xml.
|
---|
20 | # The tomcat start/stop ports are set by incrementing the port specified in the source for each of the webapps.
|
---|
21 |
|
---|
22 | # To generate start and stop script use something like this
|
---|
23 | # export CATALINA_HOME=$TOMCAT_HOME
|
---|
24 | # DEPLOY_DIR=/opt/local/ArchiverAppliance/tomcats
|
---|
25 | # The stop sequences....
|
---|
26 | # export CATALINA_BASE=${DEPLOY_DIR}/mgmt; ${CATALINA_HOME}/bin/catalina.sh stop
|
---|
27 | # export CATALINA_BASE=${DEPLOY_DIR}/engine; ${CATALINA_HOME}/bin/catalina.sh stop
|
---|
28 | # export CATALINA_BASE=${DEPLOY_DIR}/etl; ${CATALINA_HOME}/bin/catalina.sh stop
|
---|
29 | # export CATALINA_BASE=${DEPLOY_DIR}/retrieval; ${CATALINA_HOME}/bin/catalina.sh stop
|
---|
30 | # The start sequences
|
---|
31 | # export CATALINA_BASE=${DEPLOY_DIR}/mgmt; ${CATALINA_HOME}/bin/catalina.sh start
|
---|
32 | # export CATALINA_BASE=${DEPLOY_DIR}/engine; ${CATALINA_HOME}/bin/catalina.sh start
|
---|
33 | # export CATALINA_BASE=${DEPLOY_DIR}/etl; ${CATALINA_HOME}/bin/catalina.sh start
|
---|
34 | # export CATALINA_BASE=${DEPLOY_DIR}/retrieval; ${CATALINA_HOME}/bin/catalina.sh start
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | import sys
|
---|
39 | import os
|
---|
40 | import xml.dom.minidom
|
---|
41 | #import urlparse
|
---|
42 | from urllib.parse import urlparse
|
---|
43 | import shutil
|
---|
44 |
|
---|
45 | def deployMultipleTomcats(destFolder):
|
---|
46 | tomcatHome = os.getenv("TOMCAT_HOME")
|
---|
47 | if tomcatHome == None:
|
---|
48 | print("We determine the source Tomcat distribution using the environment variable TOMCAT_HOME which does not seem to be set.")
|
---|
49 | sys.exit(1)
|
---|
50 | thisAppliance = os.getenv("ARCHAPPL_MYIDENTITY")
|
---|
51 | if thisAppliance == None:
|
---|
52 | print("We determine the identity of this appliance using the environment variable ARCHAPPL_MYIDENTITY which does not seem to be set.")
|
---|
53 | sys.exit(1)
|
---|
54 | appliancesXML = os.getenv("ARCHAPPL_APPLIANCES")
|
---|
55 | if appliancesXML == None:
|
---|
56 | print("We determine the location of the appliances.xml file using the environment variable ARCHAPPL_APPLIANCES which does not seem to be set.")
|
---|
57 | sys.exit(1)
|
---|
58 |
|
---|
59 | print("Using\n\ttomcat installation at", tomcatHome, "\n\tto generate deployments for appliance", thisAppliance, "\n\tusing configuration info from", appliancesXML, "\n\tinto folder", destFolder)
|
---|
60 |
|
---|
61 | # Parse the tomcat/conf/server.xml file and determine the stop start port
|
---|
62 | # We start incrementing and use this port+1 for each of the new webapps
|
---|
63 | tomcatServerConfSrc = tomcatHome + '/conf/server.xml'
|
---|
64 | serverdom = xml.dom.minidom.parse(tomcatServerConfSrc);
|
---|
65 | serverStopStartPort = serverdom.getElementsByTagName('Server').item(0).getAttribute('port')
|
---|
66 | if int(serverStopStartPort) == 8005:
|
---|
67 | print("The start/stop port is the standard Tomcat start/stop port. Changing it to something else random - 16000")
|
---|
68 | serverStopStartPort='16000'
|
---|
69 | newServerStopStartPort = int(serverStopStartPort)+1
|
---|
70 | print('The stop/start ports for the new instance will being at ', newServerStopStartPort)
|
---|
71 |
|
---|
72 | # Parse the appliances.xml and determine the ports for the HTTP listeners
|
---|
73 | appliancesXMLDOM = xml.dom.minidom.parse(appliancesXML)
|
---|
74 | appliances = appliancesXMLDOM.getElementsByTagName('appliance')
|
---|
75 | for appliance in appliances:
|
---|
76 | identity = appliance.getElementsByTagName('identity').item(0).firstChild.data
|
---|
77 | if identity != thisAppliance:
|
---|
78 | # print "Skipping config for", appliance, " looking for ", thisAppliance
|
---|
79 | continue
|
---|
80 | httplistenerports = {}
|
---|
81 | mgmtUrl = appliance.getElementsByTagName('mgmt_url').item(0).firstChild.data
|
---|
82 | engineUrl = appliance.getElementsByTagName('engine_url').item(0).firstChild.data
|
---|
83 | etlUrl = appliance.getElementsByTagName('etl_url').item(0).firstChild.data
|
---|
84 | retrievalUrl = appliance.getElementsByTagName('retrieval_url').item(0).firstChild.data
|
---|
85 |
|
---|
86 | httplistenerports['mgmt'] = urlparse(mgmtUrl).port
|
---|
87 | httplistenerports['engine'] = urlparse(engineUrl).port
|
---|
88 | httplistenerports['etl'] = urlparse(etlUrl).port
|
---|
89 | httplistenerports['retrieval'] = urlparse(retrievalUrl).port
|
---|
90 |
|
---|
91 | for app in ['mgmt', 'engine', 'etl', 'retrieval']:
|
---|
92 | # Delete any existing subfolders if any and make new ones.
|
---|
93 | subFolder = destFolder + '/' + app
|
---|
94 | if os.access(subFolder, os.W_OK):
|
---|
95 | print("Removing ", subFolder)
|
---|
96 | shutil.rmtree(subFolder)
|
---|
97 | print("Generating tomcat folder for ", app, " in location", subFolder)
|
---|
98 | os.makedirs(subFolder)
|
---|
99 | # See http://kief.com/running-multiple-tomcat-instances-on-one-server.html for the steps we are using here.
|
---|
100 | shutil.copytree(tomcatHome + '/conf', subFolder + '/conf')
|
---|
101 | shutil.copytree(tomcatHome + '/webapps', subFolder + '/webapps')
|
---|
102 | os.makedirs(subFolder + '/logs')
|
---|
103 | os.makedirs(subFolder + '/temp')
|
---|
104 | os.makedirs(subFolder + '/work')
|
---|
105 |
|
---|
106 | # print 'StopStart for', app, ' is', newServerStopStartPort, "and the HTTP listener port as determined from appliances.xml is", httplistenerports[app]
|
---|
107 | newServerDom = xml.dom.minidom.parse(subFolder + '/conf/server.xml')
|
---|
108 | newServerDom.getElementsByTagName('Server').item(0).setAttribute('port', str(newServerStopStartPort))
|
---|
109 | # Find the 'Connector' whose 'protocol' is 'HTTP/1.1'
|
---|
110 | haveSetConnector = False
|
---|
111 | for httplistenerNode in newServerDom.getElementsByTagName('Connector'):
|
---|
112 | if httplistenerNode.hasAttribute('protocol') and httplistenerNode.getAttribute('protocol') == 'HTTP/1.1':
|
---|
113 | httplistenerNode.setAttribute('port', str(httplistenerports[app]))
|
---|
114 | haveSetConnector = True
|
---|
115 | else:
|
---|
116 | print("Commenting connector with protocol ", httplistenerNode.getAttribute('protocol'), ". If you do need this connector, you should un-comment this.")
|
---|
117 | comment = httplistenerNode.ownerDocument.createComment(httplistenerNode.toxml())
|
---|
118 | httplistenerNode.parentNode.replaceChild(comment, httplistenerNode)
|
---|
119 | if haveSetConnector == False:
|
---|
120 | raise AssertionError("We have not set the HTTP listener port for " + app);
|
---|
121 |
|
---|
122 |
|
---|
123 | with open(subFolder + '/conf/server.xml', 'w') as file:
|
---|
124 | newServerDom.writexml(file)
|
---|
125 | newServerStopStartPort = newServerStopStartPort+1
|
---|
126 |
|
---|
127 | if __name__ == "__main__":
|
---|
128 | if len(sys.argv) < 2:
|
---|
129 | print("Usage: ", sys.argv[0], "<DeploymentFolder>")
|
---|
130 | sys.exit(1)
|
---|
131 | deployMultipleTomcats(sys.argv[1])
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|