12

I am on Windows and trying to run multiple (currently two) instances of TeamCity on the same server. I chose not to install the Windows services and instead run the server via runAll.bat start command. When I ran the installer I chose different ports, names and paths for each one. The first server starts successfully, but the second one does not - I see the tomcat window showing up, but it's gone after a while, though the build agent window stays. Here's some output:

c:\Tools\TeamCity\bin>runAll.bat start
starting TeamCity server and agent...
Using CATALINA_BASE:   "c:\Tools\TeamCity\bin\.."
Using CATALINA_HOME:   "c:\Tools\TeamCity\bin\.."
Using CATALINA_TMPDIR: "c:\Tools\TeamCity\bin\..\temp"
Using JRE_HOME:        "c:\Tools\TeamCity\bin\..\jre"
Using CLASSPATH:       "c:\Tools\TeamCity\bin\..\bin\bootstrap.jar"
Starting TeamCity Build Agent Launcher...
Agent home directory is C:\Tools\TeamCity\buildAgent
Current JRE version is 1.6

c:\Tools\TeamCity\bin>cd c:\Tools\TeamCity2\bin

c:\Tools\TeamCity2\bin>runAll.bat start
starting TeamCity server and agent...
Using CATALINA_BASE:   "c:\Tools\TeamCity2\bin\.."
Using CATALINA_HOME:   "c:\Tools\TeamCity2\bin\.."
Using CATALINA_TMPDIR: "c:\Tools\TeamCity2\bin\..\temp"
Using JRE_HOME:        "c:\Tools\TeamCity2\bin\..\jre"
Using CLASSPATH:       "c:\Tools\TeamCity2\bin\..\bin\bootstrap.jar"
Starting TeamCity Build Agent Launcher...
Agent home directory is C:\Tools\TeamCity2\buildAgent
Current JRE version is 1.6
Pawel Krakowiak
  • 9,300
  • 2
  • 33
  • 54
  • 2
    Pre-emptive strike against further flags on this post. This is actually not against the licensing for the free professional version of TeamCity, so stop flagging this for this reason. – Lasse V. Karlsen Jun 13 '11 at 19:42

2 Answers2

10

You need to edit conf\server.xml for the second Tomcat/TeamCity instance so that it uses different ports or binds to different network interfaces, changing the following ports should be enough:

  • Server port="8005"
  • Connector port="8080"

Two servers cannot share the same database, so you must configure them to use different locations via TEAMCITY_DATA_PATH environment variable.

If you also want to run multiple agents on the same machine, refer to my answer here.

Community
  • 1
  • 1
CrazyCoder
  • 350,772
  • 137
  • 894
  • 800
  • The second server runs this time, but it reports that the database is in use already, so TeamCity can't get past the startup phase. I thought they'd use another database (sorry, I have no idea about Java). `HSQL database opened (in-process) by another application. SQL error when doing: Connecting to HSQL SQL exception: The database is already in use by another process: lockFile: org.hsqldb.persist.LockFile@6431050a[file =C:\Users\Administrator\.BuildServer\system\buildserver.lck` Why doesn't it look in _.BuildServer 2_? – Pawel Krakowiak Jun 08 '11 at 07:43
  • 2
    Actually, it is not quite clear why do you need 2 instances of TeamCity server running. One server can only work with one database/configuration. So if you really need 2 servers, specify alternative location for the settings via TEAMCITY_DATA_PATH environment variable. – KIR Jun 08 '11 at 08:01
  • I want two TeamCity servers running on the same machine and they should use separate databases. What I am trying to achieve is to see if this allows me to have more than 20 configurations in the Professional version. According to their FAQ it should work, unless I did not understand it: http://www.jetbrains.com/teamcity/buy/licensing_faq.html#q2 – Pawel Krakowiak Jun 08 '11 at 12:10
  • 4
    Can I suggest just paying the money and stop annoying yourself - it's an awesome product and your going against the spirit of "and if it's __really__ saving your but and you love it, you buy it" which their pricing is based on. – Ruben Bartelink Jun 08 '11 at 15:02
  • 5
    Technically, you're right Ruben. :-) 1680 EUR is way too much for a business my size, though (1 guy + occasional subcontractors when I need them). The Enterprise Server is "for larger teams and organizations", which I'm not. I am not looking to run dozens of concurrent build configurations, instead I'd like to be able to keep some archived projects around in case a customer comes after 10 months and requests some new features. Thought that having multiple instances of TC would help with keeping archived projects with their build history... – Pawel Krakowiak Jun 13 '11 at 11:33
7

It is possible to make more than one TeamCity server run on the same Windows box as Windows services.

The following procedure assumes you want to install 3 instances of TeamCity named TeamCity1, TeamCity2, and TeamCity3 on ports 8080, 8081, and 8082 respectively. If you change any of these details, make sure you remain consistant with the change throughout the procedure. Each instance MUST run under a different Windows user account for this procedure to work. This was done with TeamCity 7.1, I am not sure if it works with other versions.

Here is the procedure:

  1. Install TeamCity, choose "C:\TeamCity1" as the destination folder.

  2. Uncheck the Build Agent (both Windows Service and Core) - these will be installed later.

  3. Uncheck the Windows Service for Server, but leave the Core checked.

  4. Use "C:\TeamCity1\TeamCityData\" as the configuration directory.

  5. Choose a unique port for this instance. I chose 8080, 8081, and 8082.

  6. Repeat steps 1-5 as many times as desired, changing the to TeamCity2, TeamCity3, etc. and changing the port each time.

  7. Go to Computer Management in Administrative Tools and create 1 unique Windows user account for each service (i.e. TeamCity1, TeamCity2, and TeamCity3). Make sure the passwords do not expire. For now, make sure each user has enough permission to log onto Windows.

  8. Open an elevated command prompt by going to All programs > Accessories > Command Prompt, right clicking, and choose "Run as Administrator".

  9. Run the commands at the end of this procedure for each instance of TeamCity, replacing the number 1 with the appropriate TeamCity instance.

  10. You need to add "Logon as a service" right for each account. The easy way to do this is to open Services from Administrative Tools, right click each service, go to the Log On tab, retype the password in both boxes, and click Apply.

  11. Logoff the machine and login as "TeamCity1".

  12. Go to Control Panel > User Accounts > User Accounts > Change my environment variables.

  13. Add a new User variable by clicking New... Name it TEAMCITY_DATA_PATH with a value of C:\TeamCity1\TeamCityData.

  14. Repeat steps 11-13 for each instance of TeamCity.

  15. Logoff and log back in with the Administrator account.

  16. Go back into the environment variables dialog and delete the System variable (not User variable) named TEAMCITY_DATA_PATH.

  17. If desired, change the permissions for each TeamCity user account so they do not have permission to log in.

  18. Open C:\TeamCity1\conf\server.xml and C:\TeamCity1\conf\server-standard.xml and change the server port=8105 to another port of your choosing. Ensure you use the SAME PORT in both files. Repeat for each instance of TeamCity.

  19. Start each service and connect with your browser to configure the data directory for each one. I had to stop all of the teamcity service instances except the current one or I got a "client not authenticated" error during the build process, but once completed they seem to work okay.

  20. Configure database access as appropriate.

  21. Use these instructions to install multiple build agents on the same machine. I don't believe it is possible to share an agent between TeamCity instances as communication is 2-way and there doesn't seem to be a way to configure more than one port, so it is probably best to install the agents to C:\TeamCity1\buildAgent1\ named TeamCity1BuildAgent1, C:\TeamCity1\buildAgent2\ named TeamCity1BuildAgent2, C:\TeamCity2\buildAgent1\ named TeamCity2BuildAgent1, etc.

  22. If you want to use standard ports for each TeamCity instance (80 and/or 443), follow these instructions to use IIS as a proxy for Tomcat.

Run these commands at step #9 above

sc create TeamCity1 binPath= "\"C:\TeamCity1\bin\TeamCityService.exe\" jetservice \"/settings=C:\TeamCity1\conf\teamcity-server-service.xml\" \"/LogFile=C:\TeamCity1\logs\teamcity-winservice.log\"" DisplayName= "TeamCity Server 1" start= auto obj= ".\TeamCity1" password= "Password1"

sc description "TeamCity1" "JetBrains TeamCity server service 1"

NOTE: teamcity is misspelled as "teamicty" as the name of the config file in some builds. 
This is a TeamCity bug, make sure you correct the file name before 
executing these commands.
NightOwl888
  • 51,095
  • 20
  • 122
  • 194