AM_INSTALLATION_GUIDE.md 3.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Dependencies
Java 11, Maven, Tomcat 9

Tested on Ubuntu 18.04.4 LTS.

# Install dependencies

## Install Java 
```
sudo apt install openjdk-11-jdk
```

## Install Maven
```
sudo apt install Maven
```

### Setup Tomcat user
For security purposes, Tomcat should not be run under the root user. In this guide we create a new system user and group with home directory /opt/Tomcat that will run the Tomcat service.

```
sudo useradd -r -m -U -d /opt/Tomcat -s /bin/false Tomcat
```

### Install Tomcat 9
Download latest binary from the official Tomcat project page 

https://Tomcat.apache.org/download-90.cgi

For example with wget

```
wget https://downloads.apache.org/Tomcat/Tomcat-9/v9.0.31/bin/apache-Tomcat-9.0.31.tar.gz -P /tmp
```

At the time of writing this instruction, the latest Tomcat 9 is 9.0.31.

I replace the minor versions with * in further instructions, as this might be reliable to change.

Extract the downloaded archive

```
sudo tar xf /tmp/apache-Tomcat-9*.tar.gz -C /opt/Tomcat
```

Create symlink for ease of use

```
sudo ln -s /opt/Tomcat/apache-Tomcat-9.*.* /opt/Tomcat/latest
```

Change the owner of installation folder to Tomcat user and make scripts executable

```
sudo chown -RH Tomcat: /opt/Tomcat/latest
sudo sh -c 'chmod +x /opt/Tomcat/latest/bin/*.sh'
```

### Optional: create Tomcat service
Though you can start and stop Tomcat manually 

```
opt/Tomcat/latest/bin/startup.sh
/opt/Tomcat/latest/bin/shutdown.sh
```

For comfortable use Tomcat should be set up as a service.

Using your favorite text editor create a file

```
/etc/systemd/system/Tomcat.service
```

with content ... 

```
[Unit]
Description=Tomcat 9 servlet container
After=network.target

[Service]
Type=forking

User=Tomcat
Group=Tomcat

Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/opt/Tomcat/latest"
Environment="CATALINA_HOME=/opt/Tomcat/latest"
Environment="CATALINA_PID=/opt/Tomcat/latest/temp/Tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/Tomcat/latest/bin/startup.sh
ExecStop=/opt/Tomcat/latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

check your Java home -- in my installation the Java installation produced

/usr/lib/jvm/java-1.11.0-openjd-amd64
```

Symlink pointing to Java installation directory

```
/usr/lib/jvmjava-11-openjdk-amd64
```

One could paste that into the above file. I chose to rename the symlink.

```
sudo mv /usr/lib/jvm/java-1-11-0-openjd-amd64 /usr/lib/jvm/java/default-java
```

Reload systemd deamon

```
sudo systemctl daemon-reload
```

Now one can start/stop/restart the service and look its status

```
sudo systemctl start/stop/restart/status Tomcat
```

If status shows Tomcat running nicely one can now enable Tomcat to start on system boot time

```
sudo sustemctl enable Tomcat
```


# Package and install the application

After downloading the source code.
Move to the uppermost project folder containing pom.xml file.

Package the application

```
mvn clean -U package
```

In folder `/target` `andmemuundur.war` package is generated.

Copy `andmemuundur.war` to `/opt/Tomcat/latest/webapps`. Copy there also `/templates` folder from source code.

Start or restart Tomcat 9.