Deployment runthrough » History » Version 14

Chris Cannam, 2014-07-24 02:53 PM

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 1 Chris Cannam
h2. 1. Obtain the current code from Mercurial repository
6 1 Chris Cannam
7 1 Chris Cannam
<pre>
8 1 Chris Cannam
$ hg clone https://code.soundsoftware.ac.uk/hg/human-echolocation-java-webapp
9 1 Chris Cannam
http authorization required for https://code.soundsoftware.ac.uk/hg/human-echolocation-java-webapp
10 1 Chris Cannam
realm: Mercurial repository for Human Echolocation WebApp
11 1 Chris Cannam
user: chrisca
12 1 Chris Cannam
password: 
13 1 Chris Cannam
destination directory: human-echolocation-java-webapp
14 1 Chris Cannam
requesting all changes
15 1 Chris Cannam
adding changesets
16 1 Chris Cannam
adding manifests
17 1 Chris Cannam
adding file changes
18 1 Chris Cannam
added 41 changesets with 93 changes to 40 files
19 1 Chris Cannam
updating to branch default
20 1 Chris Cannam
23 files updated, 0 files merged, 0 files removed, 0 files unresolved
21 1 Chris Cannam
$
22 1 Chris Cannam
</pre>
23 1 Chris Cannam
24 1 Chris Cannam
h2. 2. Install the MATLAB Compiler Runtime
25 1 Chris Cannam
26 1 Chris Cannam
Navigate to http://www.mathworks.co.uk/products/compiler/mcr/ and find the download URL, then use as follows.
27 1 Chris Cannam
28 1 Chris Cannam
<pre>
29 1 Chris Cannam
$ mkdir mcr
30 1 Chris Cannam
$ cd mcr
31 1 Chris Cannam
$ wget 'http://www.mathworks.co.uk/supportfiles/downloads/R2013b/deployment_files/R2013b/installers/glnxa64/MCR_R2013b_glnxa64_installer.zip'
32 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
33 1 Chris Cannam
Resolving www.mathworks.co.uk (www.mathworks.co.uk)... 23.214.117.160
34 1 Chris Cannam
Connecting to www.mathworks.co.uk (www.mathworks.co.uk)|23.214.117.160|:80... connected.
35 1 Chris Cannam
HTTP request sent, awaiting response... 200 OK
36 1 Chris Cannam
Length: 488473010 (466M) [application/zip]
37 1 Chris Cannam
Saving to: ‘MCR_R2013b_glnxa64_installer.zip’
38 1 Chris Cannam
39 1 Chris Cannam
100%[======================================>] 488,473,010 7.81MB/s   in 60s    
40 1 Chris Cannam
41 1 Chris Cannam
2014-02-24 10:01:11 (7.71 MB/s) - ‘MCR_R2013b_glnxa64_installer.zip’ saved [488473010/488473010]
42 1 Chris Cannam
$ unzip MCR_R2013b_glnxa64_installer.zip 
43 1 Chris Cannam
Archive:  MCR_R2013b_glnxa64_installer.zip
44 1 Chris Cannam
  inflating: archives/mpc_resources_common_1348598029.enc  
45 1 Chris Cannam
  inflating: archives/cgir_mi_core_glnxa64_1375749553.xml  
46 1 Chris Cannam
[etc]
47 1 Chris Cannam
$ ./install
48 1 Chris Cannam
</pre>
49 1 Chris Cannam
50 1 Chris Cannam
The installer window then pops up (X server connection required for graphical interaction here).
51 1 Chris Cannam
52 1 Chris Cannam
The default installation folder is @/usr/local/MATLAB/MATLAB_Compiler_Runtime@. I'm going to accept that.
53 2 Chris Cannam
54 2 Chris Cannam
The installer runs, and then prints out the following:
55 2 Chris Cannam
56 2 Chris Cannam
<pre>
57 2 Chris Cannam
On the target computer, append the following to your LD_LIBRARY_PATH environment variable:
58 2 Chris Cannam
59 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
60 2 Chris Cannam
61 2 Chris Cannam
Next, set the XAPPLRESDIR environment variable to the following value:
62 2 Chris Cannam
63 2 Chris Cannam
/usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/X11/app-defaults  
64 2 Chris Cannam
</pre>
65 3 Chris Cannam
66 3 Chris Cannam
h2. 3. Bring dependent JAR files into the webapp folder
67 3 Chris Cannam
68 3 Chris Cannam
Make sure we're back in the webapp folder (the one we cloned from Mercurial earlier)
69 3 Chris Cannam
70 3 Chris Cannam
<pre>
71 3 Chris Cannam
$ cd ../human-echolocation-java-webapp
72 3 Chris Cannam
</pre>
73 3 Chris Cannam
74 3 Chris Cannam
Copy in the Servlet API library from our application server (in this case Tomcat):
75 3 Chris Cannam
76 3 Chris Cannam
<pre>
77 3 Chris Cannam
$ cp /usr/share/java/tomcat7/servlet-api.jar .
78 3 Chris Cannam
</pre>
79 3 Chris Cannam
80 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)
81 14 Chris Cannam
82 3 Chris Cannam
And the MATLAB MCR JavaBuilder library:
83 3 Chris Cannam
84 3 Chris Cannam
<pre>
85 3 Chris Cannam
$ cp /usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/toolbox/javabuilder/jar/javabuilder.jar ./WebContent/WEB-INF/lib/
86 3 Chris Cannam
</pre>
87 4 Chris Cannam
88 4 Chris Cannam
h2. 4. Build the WAR file bundle
89 4 Chris Cannam
90 4 Chris Cannam
Simple enough:
91 4 Chris Cannam
92 4 Chris Cannam
<pre>
93 4 Chris Cannam
$ ant
94 4 Chris Cannam
Buildfile: /work/human-echolocation-java-webapp/build.xml
95 4 Chris Cannam
96 4 Chris Cannam
build:
97 4 Chris Cannam
    [javac] Compiling 2 source files to /work/human-echolocation-java-webapp/WebContent/WEB-INF/classes
98 4 Chris Cannam
99 4 Chris Cannam
build-war:
100 4 Chris Cannam
      [war] Building war: /work/human-echolocation-java-webapp/echoapp.war
101 4 Chris Cannam
102 4 Chris Cannam
BUILD SUCCESSFUL
103 4 Chris Cannam
Total time: 1 second
104 4 Chris Cannam
$
105 4 Chris Cannam
</pre>
106 5 Chris Cannam
107 5 Chris Cannam
h2. 5. Deploy the bundle and start the app server
108 5 Chris Cannam
109 5 Chris Cannam
<pre>
110 5 Chris Cannam
$ sudo cp echoapp.war /var/lib/tomcat7/webapps/
111 12 Chris Cannam
$ sudo /usr/share/tomcat7/bin/startup.sh
112 1 Chris Cannam
</pre>
113 10 Chris Cannam
114 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_
115 5 Chris Cannam
116 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.)
117 6 Chris Cannam
118 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).
119 6 Chris Cannam
120 13 Chris Cannam
h2. 6. Test the app 
121 6 Chris Cannam
122 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.
123 6 Chris Cannam
124 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:
125 6 Chris Cannam
126 6 Chris Cannam
<pre>
127 6 Chris Cannam
java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.toolbox.javabuilder.internal.MWMCR
128 6 Chris Cannam
	uk.ac.soton.isvr.IsvrMCRFactory.newInstance(IsvrMCRFactory.java:47)
129 6 Chris Cannam
	uk.ac.soton.isvr.IsvrMCRFactory.newInstance(IsvrMCRFactory.java:58)
130 6 Chris Cannam
	uk.ac.soton.isvr.HumanEcho.<init>(HumanEcho.java:62)
131 6 Chris Cannam
</pre>
132 8 Chris Cannam
133 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
134 8 Chris Cannam
135 8 Chris Cannam
<pre>
136 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
137 8 Chris Cannam
</pre>
138 8 Chris Cannam
139 1 Chris Cannam
and run
140 8 Chris Cannam
141 1 Chris Cannam
<pre>
142 11 Chris Cannam
$ sudo chmod +x setenv.sh
143 12 Chris Cannam
$ sudo ./shutdown.sh
144 12 Chris Cannam
$ sudo ./startup.sh
145 8 Chris Cannam
</pre>
146 8 Chris Cannam
147 11 Chris Cannam
On reloading the app and re-requesting the servlet, the error message has disappeared and instead we see
148 8 Chris Cannam
149 8 Chris Cannam
<pre>
150 11 Chris Cannam
java.lang.NumberFormatException: null
151 11 Chris Cannam
	java.lang.Integer.parseInt(Integer.java:454)
152 11 Chris Cannam
	java.lang.Integer.parseInt(Integer.java:527)
153 11 Chris Cannam
	HumanEchoServlet.doGet(Unknown Source)
154 11 Chris Cannam
	javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
155 8 Chris Cannam
</pre>
156 9 Chris Cannam
157 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!