# Basic installation with Jetty and H2 Database

**Install Required Software**

```bash
#install a lot of stuff
sudo apt update
sudo apt install tesseract-ocr tesseract-ocr-deu tesseract-ocr-eng libtesseract-dev ffmpeg mediainfo mediainfo-gui openjdk-11-jdk
 
#install Jetty Web Server
sudo apt install jetty11
 
#check versions
ffmpeg -version
tesseract -v
mediainfo --version
dpkg -l | grep jetty11
dpkg -l | grep jdk
```

You can also install jetty manually (not by `apt`) with ease and full control:

```bash
cd /opt
wget https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/11.0.15/jetty-home-11.0.15.tar.gz
tar -xvzf jetty-home-11.0.15.tar.gz
mkdir -p /opt/jetty-home-11.0.15/jetty-base/
cd /opt/jetty-home-11.0.15/jetty-base/
java -jar ../start.jar --add-modules=deploy,http
cp /opt/teedy/docs-web/target/docs-web-1.*.war /opt/jetty-home-11.0.15/jetty-base/webapps/dms.war #copy the compiled deployment war to target dir
chown jetty:adm /opt/jetty-home-11.0.15/jetty-base/webapps/dms.war
chown jetty:adm /opt/jetty-home-11.0.15/jetty-base/webapps/dms.xml
```

**Create dms.xml configuration files**

This allows to change the default docs home dir and other things. Have a look at [https://github.com/sismics/docs/blob/master/docs.xml](https://github.com/sismics/docs/blob/master/docs.xml)

```bash
vim /opt/jetty-home-11.0.15/jetty-base/webapps/dms.xml
```

```xml
<?xml version="1.0"?>

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/dms</Set>
  <Set name="war"><SystemProperty name="jetty.data" default="."/>/webapps/dms.war</Set>
  <Call class="java.lang.System" name="setProperty">
    <Arg>docs.home</Arg>
    <Arg>/var/docs</Arg>
  </Call>
</Configure>
```

Adjust the following lines according to your configured XML argument `docs.home` (if changed)

```bash
mkdir -p /var/docs/
chmod -T 770 /var/docs/
chown -R jetty:jetty /var/docs/
```

Take the pre-built `dms.war` file or [compile on your own](https://wiki.stadtfabrikanten.org/books/inventar-und-handbucher/page/build-web-application-server-from-source "Build web application server from Source") and put it to /opt/jetty-home-11.0.15/jetty-base/webapps/dms.war

**Tuning**

Raise the heap space Xmx to prevent "java heap space error" - this often occures when OCR'ing a lot of files or uploading multiple files at once. This causes to restart jetty9 completely

```bash
sudo vim /lib/systemd/system/jetty11.service
```

```ini
Environment="JAVA_OPTS=-Xms1024m -Xmx3584m -Djava.awt.headless=true"
```

See also [Environment Configuration](https://wiki.stadtfabrikanten.org/books/inventar-und-handbucher/page/environment-configuration "Environment Configuration") for reference

**JDK/JRE - Permissions Policy Adjustments (optional)**

<p class="callout danger">that might be dangerous / unsecure</p>

```ini
sudo vim /usr/lib/jvm/java-11-openjdk-amd64/lib/security/default.policy
```

Add to top of file:

```ini
grant {
    permission java.security.AllPermission "", "";
};
```

**Fix jetty read-only filesystem (since Jetty 9.4.15)**

Sympton → "Caused by: [java.io](http://java.io).FileNotFoundException: /var/docs/db/docs.trace.db (file system is readonly - but it is not!)"

The newest jetty package was changed to contain restricted settings in `/lib/systemd/system/jetty9.service`. You need to add another ReadWritePath for the `/var/docs` directory

```ini
sudo vim /lib/systemd/system/jetty11.service
```

```ini
ProtectSystem=strict
ReadWritePaths=/var/lib/jetty11
ReadWritePaths=/var/docs/
```

**Restart Jetty Service**

```ini
sudo systemctl restart jetty11.service
```

**Check the logs**

```ini
sudo less /var/log/jetty11/
sudo journalctl -f -u jetty11
```

**Access to Teedy Web Interface**


[https://YOURHOST:8080](https://YOURHOST:8080)