Deployment runthrough » History » Version 16

Chris Cannam, 2014-09-30 10:15 AM

1 1 Chris Cannam
h1. Deployment runthrough
2 1 Chris Cannam
3 13 Chris Cannam
This is an example deployment, on a 64-bit Linux host. There are various different ways to do this and the details will vary from one platform to another. This is a deployment of a very early version of the code.
4 1 Chris Cannam
5 16 Chris Cannam
See [[Deployment troubleshooting]] for notes about Java and Tomcat versions and on things that might go wrong.
6 16 Chris Cannam
7 1 Chris Cannam
h2. 1. Obtain the current code from Mercurial repository
8 1 Chris Cannam
9 1 Chris Cannam
<pre>
10 1 Chris Cannam
$ hg clone https://code.soundsoftware.ac.uk/hg/human-echolocation-java-webapp
11 1 Chris Cannam
http authorization required for https://code.soundsoftware.ac.uk/hg/human-echolocation-java-webapp
12 1 Chris Cannam
realm: Mercurial repository for Human Echolocation WebApp
13 1 Chris Cannam
user: chrisca
14 1 Chris Cannam
password: 
15 1 Chris Cannam
destination directory: human-echolocation-java-webapp
16 1 Chris Cannam
requesting all changes
17 1 Chris Cannam
adding changesets
18 1 Chris Cannam
adding manifests
19 1 Chris Cannam
adding file changes
20 1 Chris Cannam
added 41 changesets with 93 changes to 40 files
21 1 Chris Cannam
updating to branch default
22 1 Chris Cannam
23 files updated, 0 files merged, 0 files removed, 0 files unresolved
23 1 Chris Cannam
$
24 1 Chris Cannam
</pre>
25 1 Chris Cannam
26 1 Chris Cannam
h2. 2. Install the MATLAB Compiler Runtime
27 1 Chris Cannam
28 1 Chris Cannam
Navigate to http://www.mathworks.co.uk/products/compiler/mcr/ and find the download URL, then use as follows.
29 1 Chris Cannam
30 1 Chris Cannam
<pre>
31 1 Chris Cannam
$ mkdir mcr
32 1 Chris Cannam
$ cd mcr
33 1 Chris Cannam
$ wget 'http://www.mathworks.co.uk/supportfiles/downloads/R2013b/deployment_files/R2013b/installers/glnxa64/MCR_R2013b_glnxa64_installer.zip'
34 1 Chris Cannam
--2014-02-24 10:00:10--  http://www.mathworks.co.uk/supportfiles/downloads/R2013b/deployment_files/R2013b/installers/glnxa64/MCR_R2013b_glnxa64_installer.zip
35 1 Chris Cannam
Resolving www.mathworks.co.uk (www.mathworks.co.uk)... 23.214.117.160
36 1 Chris Cannam
Connecting to www.mathworks.co.uk (www.mathworks.co.uk)|23.214.117.160|:80... connected.
37 1 Chris Cannam
HTTP request sent, awaiting response... 200 OK
38 1 Chris Cannam
Length: 488473010 (466M) [application/zip]
39 1 Chris Cannam
Saving to: ‘MCR_R2013b_glnxa64_installer.zip’
40 1 Chris Cannam
41 1 Chris Cannam
100%[======================================>] 488,473,010 7.81MB/s   in 60s    
42 1 Chris Cannam
43 1 Chris Cannam
2014-02-24 10:01:11 (7.71 MB/s) - ‘MCR_R2013b_glnxa64_installer.zip’ saved [488473010/488473010]
44 1 Chris Cannam
$ unzip MCR_R2013b_glnxa64_installer.zip 
45 1 Chris Cannam
Archive:  MCR_R2013b_glnxa64_installer.zip
46 1 Chris Cannam
  inflating: archives/mpc_resources_common_1348598029.enc  
47 1 Chris Cannam
  inflating: archives/cgir_mi_core_glnxa64_1375749553.xml  
48 1 Chris Cannam
[etc]
49 1 Chris Cannam
$ ./install
50 1 Chris Cannam
</pre>
51 1 Chris Cannam
52 1 Chris Cannam
The installer window then pops up (X server connection required for graphical interaction here).
53 1 Chris Cannam
54 1 Chris Cannam
The default installation folder is @/usr/local/MATLAB/MATLAB_Compiler_Runtime@. I'm going to accept that.
55 2 Chris Cannam
56 2 Chris Cannam
The installer runs, and then prints out the following:
57 2 Chris Cannam
58 2 Chris Cannam
<pre>
59 2 Chris Cannam
On the target computer, append the following to your LD_LIBRARY_PATH environment variable:
60 2 Chris Cannam
61 2 Chris Cannam
/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/bin/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/sys/java/jre/glnxa64/jre/lib/amd64
62 2 Chris Cannam
63 2 Chris Cannam
Next, set the XAPPLRESDIR environment variable to the following value:
64 2 Chris Cannam
65 2 Chris Cannam
/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/X11/app-defaults  
66 2 Chris Cannam
</pre>
67 3 Chris Cannam
68 3 Chris Cannam
h2. 3. Bring dependent JAR files into the webapp folder
69 3 Chris Cannam
70 3 Chris Cannam
Make sure we're back in the webapp folder (the one we cloned from Mercurial earlier)
71 3 Chris Cannam
72 3 Chris Cannam
<pre>
73 3 Chris Cannam
$ cd ../human-echolocation-java-webapp
74 3 Chris Cannam
</pre>
75 3 Chris Cannam
76 3 Chris Cannam
Copy in the Servlet API library from our application server (in this case Tomcat):
77 3 Chris Cannam
78 3 Chris Cannam
<pre>
79 3 Chris Cannam
$ cp /usr/share/java/tomcat7/servlet-api.jar .
80 3 Chris Cannam
</pre>
81 3 Chris Cannam
82 14 Chris Cannam
(Note that sometimes that file appears to live at @/usr/share/java/servlet-api-3.0.jar@ or similar -- it should be the same file anyway)
83 14 Chris Cannam
84 3 Chris Cannam
And the MATLAB MCR JavaBuilder library:
85 3 Chris Cannam
86 3 Chris Cannam
<pre>
87 3 Chris Cannam
$ cp /usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/toolbox/javabuilder/jar/javabuilder.jar ./WebContent/WEB-INF/lib/
88 3 Chris Cannam
</pre>
89 4 Chris Cannam
90 4 Chris Cannam
h2. 4. Build the WAR file bundle
91 4 Chris Cannam
92 4 Chris Cannam
Simple enough:
93 4 Chris Cannam
94 4 Chris Cannam
<pre>
95 4 Chris Cannam
$ ant
96 4 Chris Cannam
Buildfile: /work/human-echolocation-java-webapp/build.xml
97 4 Chris Cannam
98 4 Chris Cannam
build:
99 4 Chris Cannam
    [javac] Compiling 2 source files to /work/human-echolocation-java-webapp/WebContent/WEB-INF/classes
100 4 Chris Cannam
101 4 Chris Cannam
build-war:
102 4 Chris Cannam
      [war] Building war: /work/human-echolocation-java-webapp/echoapp.war
103 4 Chris Cannam
104 4 Chris Cannam
BUILD SUCCESSFUL
105 4 Chris Cannam
Total time: 1 second
106 4 Chris Cannam
$
107 4 Chris Cannam
</pre>
108 5 Chris Cannam
109 5 Chris Cannam
h2. 5. Deploy the bundle and start the app server
110 5 Chris Cannam
111 5 Chris Cannam
<pre>
112 5 Chris Cannam
$ sudo cp echoapp.war /var/lib/tomcat7/webapps/
113 12 Chris Cannam
$ sudo /usr/share/tomcat7/bin/startup.sh
114 1 Chris Cannam
</pre>
115 10 Chris Cannam
116 11 Chris Cannam
_Note: on many Linux distros you can start Tomcat as a system service, e.g. using "systemctl start tomcat7". I tried this initially but later on found that logs weren't being written where I expected and config changes weren't taking effect, so I started running it directly from the script in the Tomcat directory instead_
117 5 Chris Cannam
118 5 Chris Cannam
Then navigate to the Tomcat manager URL http://localhost:8080/manager/html in a browser. (This URL may vary. The default admin username and password are admin/admin; of course these must be changed and the manager port firewalled in any real deployment.)
119 6 Chris Cannam
120 6 Chris Cannam
Because the WAR file was present when Tomcat was started, it should be listed as running in the manager interface. If it isn't, we can hit the Start button on the line listing echoapp (and if we have redeployed it since last time, we should hit Reload).
121 6 Chris Cannam
122 13 Chris Cannam
h2. 6. Test the app 
123 6 Chris Cannam
124 6 Chris Cannam
Now the app has been deployed, we can run it by going to the http://localhost:8080/echoapp URL linked in the Tomcat manager page. This should display the basic Human Echolocation Webapp page. If I enter a value into the Distance field and hit Generate... nothing happens.
125 6 Chris Cannam
126 11 Chris Cannam
I can debug this by trying to retrieve the result from the HumanEchoServlet directly, through the URL http://localhost:8080/echoapp/HumanEcho. This shows a stack trace, of which the pertinent lines are:
127 6 Chris Cannam
128 6 Chris Cannam
<pre>
129 6 Chris Cannam
java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.toolbox.javabuilder.internal.MWMCR
130 6 Chris Cannam
	uk.ac.soton.isvr.IsvrMCRFactory.newInstance(IsvrMCRFactory.java:47)
131 6 Chris Cannam
	uk.ac.soton.isvr.IsvrMCRFactory.newInstance(IsvrMCRFactory.java:58)
132 6 Chris Cannam
	uk.ac.soton.isvr.HumanEcho.<init>(HumanEcho.java:62)
133 6 Chris Cannam
</pre>
134 8 Chris Cannam
135 11 Chris Cannam
OK, so this is where the library path from the MCR comes into play. We can set environment variables for Tomcat in a @setenv.sh@ script in the directory where the other Tomcat shell scripts are found. In my case that is @/usr/share/tomcat7/bin@, so I create a file in there called @setenv.sh@ with the following content
136 8 Chris Cannam
137 8 Chris Cannam
<pre>
138 8 Chris Cannam
export LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/bin/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/sys/java/jre/glnxa64/jre/lib/amd64
139 8 Chris Cannam
</pre>
140 8 Chris Cannam
141 1 Chris Cannam
and run
142 8 Chris Cannam
143 1 Chris Cannam
<pre>
144 11 Chris Cannam
$ sudo chmod +x setenv.sh
145 12 Chris Cannam
$ sudo ./shutdown.sh
146 12 Chris Cannam
$ sudo ./startup.sh
147 8 Chris Cannam
</pre>
148 8 Chris Cannam
149 11 Chris Cannam
On reloading the app and re-requesting the servlet, the error message has disappeared and instead we see
150 8 Chris Cannam
151 8 Chris Cannam
<pre>
152 11 Chris Cannam
java.lang.NumberFormatException: null
153 11 Chris Cannam
	java.lang.Integer.parseInt(Integer.java:454)
154 11 Chris Cannam
	java.lang.Integer.parseInt(Integer.java:527)
155 11 Chris Cannam
	HumanEchoServlet.doGet(Unknown Source)
156 11 Chris Cannam
	javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
157 8 Chris Cannam
</pre>
158 9 Chris Cannam
159 11 Chris Cannam
OK, this is just (!) a bug in our servlet -- it isn't handling the absent dist and azim parameters correctly. If I add some random values by retrieving http://localhost:8080/echoapp/HumanEcho?dist=8&azim=4 instead, then I get served a WAV file. Hurrah!