Saturday, February 4, 2017

How to set up multiple Gitora installations on the same server

When you use Gitora on multiple databases (DEV, CI, TEST) you need to have multiple Gitora installations, one for each database.

There are a few things you need to change in Gitora if you want to have have multiple Gitora client (Tomcat) installations on the same machine.

First is the HTTP port. You can choose the port you want to run Gitora on during the Gitora installation, so that is no problem.



But notice the "Note: Port no 8005 and 8009 must not be used by a service or application".
So we need to change some ports afterwards to make it work.

Here is how to do that.
In this example we will set up 2 Gitora installations, DEV and TEST.

Install Gitora DEV 

DEV will run on port 8080 and will use all default ports, so we do not have to change anything after the Gitora installation wizard.

Tomcat server.xml

Ports 8005 and 8009 are defined in the server.xml file, with me the file is located at:
C:\Program Files (x86)\Gerger\GitoraServer-DEV\apache-tomcat-7.0.69\conf\server.xml

Also, the port 8080 is in here and one more, port 8443 (redirectPort)
..
<Server port="8005" shutdown="SHUTDOWN">
..
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
..
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
..

As we run the DEV instance with default, no need to change anything here now.

Gitblit default.properties

Another interesting port is the Git deamon port in the Gitblit default.properties file. With me the file is located at:
C:\Program Files (x86)\Gerger\GitoraServer-DEV\gitblit-config\defaults.properties
# port for serving the Git Daemon service.  <= 0 disables this service.
# On Unix/Linux systems, ports < 1024 require root permissions.
# Recommended value: 9418
#
# SINCE 1.3.0
# RESTART REQUIRED
git.daemonPort = 9418

# The port for serving the SSH service.  <= 0 disables this service.
# On Unix/Linux systems, ports < 1024 require root permissions.
# Recommended value: 29418
#
# SINCE 1.5.0
# RESTART REQUIRED
git.sshPort = 29418

Install Gitora TEST 

TEST will run on http port 8081 (you can specify it during install) and we will manually change the rest of the ports in the config files.
First stop Gitora DEV, otherwise the installer cannot continue when it detects ports 8005 an 8009 are in use.

change Tomcat server.xml

Open server.xml (see file location mentioned above) and change the ports, for example.
port 8005 to 8006
port 8009 to 8010
port 8443 to 8444



change Gitblit default.properties

Open Gitblit default.properties (see file location mentioned above)  and change the Git deamon port and SSH port.
daemonPort from 9418 to 9419
sshPort from 29418 to 29419

At this point you are able to run the 2 Gitora instances at the same time on the same machine without any port conflicts and all standard functions should work.

Remote pull from DEV to TEST

With the setup we did so far you are already able to remote pull from the DEV to the TEST repository.
This works by default, because the Git deamon port on DEV has not been changed.
The pull will look at the default port 9418 (for http connections).

Remote pull from TEST to DEV

But pulling from TEST to DEV will not work, because we changed the default Git deamon port on TEST from 9418 to 9419.

In order to pull from TEST to DEV we must change the Git deamon port in the remote repository definition in Gitora DEV to 9419 (the deamon port we configured in Gitora TEST setup).

Here is how to do that:

1. Create a remote repository in the Gitora DEV installation that looks at the TESTREPO, something like this:



(Note that the Port here is 8081, that is the http port of the Gitora TEST instance)

2. Open a command window in the Git repository directory you created in the DEV Gitora installation. 
For example i created a Git repository named 'DEVREPO' in my Gitora DEV installation.
The path (in my windows installation) would be:
C:\Program Files (x86)\Gerger\GitoraServer-DEV\repositories\gitora\DEVREPO

Now we need to use the Git 'remote' command to change the Git port.

Use 'remote -v' to lists all remote repositories that have been created in the repository.

C:\Program Files (x86)\Gerger\GitoraServer-DEV\repositories\gitora\DEVREPO>
"C:\Program Files (x86)\Gerger\GitoraServer-DEV\Git\bin\git.exe" remote -v

When you do this right after creating the remote repository in Gitora UI, you will not see any remote repository yet. This is because it is not yet created in Git, only configured in Gitora.

The easiest way to create it is just to open the remote pull window in the Gitora UI and fill in the remote repository details you want to pull from. That will create the Git remote definition.

Log into Gitora DEV, open the repository you want to pull to, and open the "Pull from remote" window (via menu "Remote commands - Pull").
Then select the remote Gitora, the Repository and Branch, but do not pull (it will not work anyway). Just cancel the screen after you selected the remote branch.

Now if you do 'remote -v' then you will see it listed, something like this:
TESTREPO_TESTREPO git://10.127.9.114/gitora/TESTREPO (fetch)
TESTREPO_TESTREPO git://10.127.9.114/gitora/TESTREPO (push)

3. To change the port we can use 'remote add'.
First, remove the current repository definition:

C:\Program Files (x86)\Gerger\GitoraServer-DEV\repositories\gitora\DEVREPO>
"C:\Program Files (x86)\Gerger\GitoraServer-DEV\Git\bin\git.exe" remote remove TESTREPO_TESTREPO

Then add the new definition, inluding the port (use the exact repository definition you got from 'remote -v', just add port 9419) like this:

C:\Program Files (x86)\Gerger\GitoraServer-DEV\repositories\gitora\DEVREPO>
"C:\Program Files (x86)\Gerger\GitoraServer-DEV\Git\bin\git.exe" remote add TESTREPO_TESTREPO git://10.127.9.114:9419/gitora/TESTREPO

If you list the remote now, you should see the port number added
TESTREPO_TESTREPO git://10.127.9.114:9419/gitora/TESTREPO (fetch)
TESTREPO_TESTREPO git://10.127.9.114:9419/gitora/TESTREPO (push)

And now you should be able to pull from remote repo TESTREPO in Gitora TEST to the DEVREPO in Gitora DEV.

Have Fun!