= How to install Bonita as a service on Windows
:description: In this tutorial we show how to install Tomcat with Bonita configured as a Windows service.

In this tutorial we show how to install Tomcat with Bonita configured as a Windows service.

== Software needed

For this tutorial you will need the following softwares:

* Tomcat Windows service installer
* Bonita Tomcat Bundle
* Postgresql Database (or another database supported by Bonita)

Please verify the supported version in xref:hardware-and-software-requirements.adoc[Installation/Basic Bonita Platform installation/hardware-and-software-requirements]

== Download and installation

* *_Download_* apache-tomcat-x.y.exe (32-bit/64-bit Windows Service Installer) from Tomcat website: https://tomcat.apache.org/

[WARNING]
====

Download the same apache-tomcat version (visible in xref:hardware-and-software-requirements.adoc[Installation/Basic Bonita Platform installation/hardware-and-software-requirements])
Choose the "32-bit/64-bit Windows Service Installer" installation.
====
* *_Install_* apache-tomcat-x.y.exe. From now on we'll call the installation path as %TOMCAT_INSTALL_FOLDER%
* *_Verify_* that Tomcat is well installed browsing the following URL: http://localhost:8080

image::images/bonita-as-windows-service/tomcatHome.png[Tomcat home page]

* *_Download_* the bundle BonitaSubscription-x.y.z.zip (or BonitaCommunity-x.y.z.zip for the community edition)
* *_Unzip_* the bundle in a folder that we'll call: %TOMCAT_BUNDLE%

== Get the license (In case of Subscription edition)

* *_Execute_* `%TOMCAT_BUNDLE%/tools/request_key_utils/generateRequestKey.bat`
* *_Use_* the generated key to get a license from the Customer Service Center. The license should not be a development license.
* *_Move_* the received license file into the folder `%TOMCAT_INSTALL_FOLDER%/setup/platform_conf/licenses`

== Database configuration

* Follow the documentation xref:database-configuration.adoc#postgres_setup[here] to correctly prepare the PostgreSQL database
* *_Configure_* the file `%TOMCAT_BUNDLE%/setup/database.properties` to point towards the suited database (engine and BDM)

image::images/bonita-as-windows-service/databaseProperties.png[database-properties file]

* *_Execute_* the command "%TOMCAT_BUNDLE%/setup/setup.bat init" in order to initialize the Bonita database with the default configuration.
* *_Verify_* that setup tool properly created the tables in the engine database.

image::images/bonita-as-windows-service/postgresTables.png[database tables]

* *_Execute_* the command "%TOMCAT_BUNDLE%/setup/setup.bat configure" in order to configure file in the %TOMCAT_BUNDLE%.
Those files will be copied to the tomcat installation.

[NOTE]
====
This is an example with Postgres, any database works
====

== Server configuration

* *_Copy_* the folder %TOMCAT_BUNDLE%/server/lib/bonita to %TOMCAT_INSTALL_FOLDER%/lib
* *_Copy_* the folder %TOMCAT_BUNDLE%/server/conf to %TOMCAT_INSTALL_FOLDER%/conf
* *_Copy_* the application %TOMCAT_BUNDLE%/server/webapps/bonita.war to %TOMCAT_INSTALL_FOLDER%/webapps


== Configure JVM properties

* The file `%TOMCAT_BUNDLE%/server/bin/setenv.bat` contains all JVM parameters to use in the new installation.
* The properties should be the following ones:
 ** -Dorg.bonitasoft.platform.setup.folder=%TOMCAT_INSTALL_FOLDER%\setup
 ** -Dorg.bonitasoft.engine.incident.folder=C:\Program Files\Apache Software Foundation\Tomcat x.y\logs
 ** -Dsysprop.bonita.db.vendor=postgres
 ** -Dsysprop.bonita.bdm.db.vendor=postgres
 ** -Dcom.arjuna.ats.arjuna.common.propertiesFile=C:\Program Files\Apache Software Foundation\Tomcat x.y\conf\jbossts-properties.xml
 ** -Dfile.encoding=UTF-8

[WARNING]
====
Replace the `%TOMCAT_INSTALL_FOLDER%` by the exact path where you move the setup folder, for example `C:\Program Files\Apache Software Foundation\setup`
====

where we replaced the `%CATALINA_HOME% with our new Tomcat directory`

In order to apply these configurations to the new installation, you have to use the program %TOMCAT_INSTALL_FOLDER%/bin/TomcatXw.exe (Where X is the Tomcat major version), and replicate them in the *Java Options* field.

[NOTE]
====
This is not a command line.

* One property per line.
* Attention, no space at the end of the line.
* do not use environment variable. All path must be resolved.
* do not set the -Xms and -Xmx option: use the field "Initial memory pool" and "Maximum memory pool".

====

Then for example

[source,properties]
----
-Dorg.bonitasoft.platform.setup.folder=C:\Program Files\Apache Software Foundation\Tomcat 8.5\setup
-Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.5
-Dcatalina.base=C:\Program Files\Apache Software Foundation\Tomcat 8.5
-Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 8.5\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=C:\Program Files\Apache Software Foundation\Tomcat 8.5\conf\logging.properties
-Dorg.bonitasoft.platform.setup.folder=C:\Program Files\Apache Software Foundation\Tomcat 8.5\setup
-Dorg.bonitasoft.h2.database.dir=C:\Program Files\Apache Software Foundation\Tomcat 8.5\h2_database
-Dorg.bonitasoft.engine.incident.folder=C:\Program Files\Apache Software Foundation\Tomcat 8.5\logs
-Dsysprop.bonita.db.vendor=postgres
-Dsysprop.bonita.bdm.db.vendor=h2
-Dcom.arjuna.ats.arjuna.common.propertiesFile=C:\Program Files\Apache Software Foundation\Tomcat 8.5\conf\jbossts-properties.xml
-Xshare:auto
-XX:+HeapDumpOnOutOfMemoryError
-Dfile.encoding=UTF-8
----

is correct

image::images/bonita-as-windows-service/tomcatw.png[tomcatw configuration]

* Setup `+%TOMCAT_INSTALL_FOLDER%/bin/Tomcat8w.exe -> Java+` \-> "Initial memory" with a proper value based on your hardware and project requirements.
* Do the same with "Maximum Memory pool" property.
As an example, if your Operating system has 8 GB of ram you could setup Initial Memory Pool = Maximum Memory Pool = 4096.
* Verify that in the Startup tab the "Mode" property is set to "Jvm".

image::images/bonita-as-windows-service/tomcatWStartup.png[tomcatw startup tab]

== System restart and test

* Restart the Tomcat service to take in account the new updates.
* Verify that the Bonita portal is available at the following address:
http://localhost:8080/bonita
* Connect with the technical user (default install/install) and do some tests:
 ** Add an organization.
 ** Assign profiles to users.
 ** Deploy a simple process and test its execution.
