TeamCity Server on Ubuntu

Last time, we set up a virtual machine template for an ubuntu server. Now that we have set up a clone of this machine, it is time to set up Teamcity on it.


Teamcity on linux is meant to be run from its integrated Tomcat server. We will use the default Teamcity installation procedure in combination with the lightweight lighttpd to act as a front end server listening on port 80 and forwarding requests to Teamcity’s Tomcat installation. This setup is both, easier than configuring Tomcat on Port 80 (remember it requires root permissions to allocate) and we could add authentication or https access more easily later (though I will not do that for now).

Installing Teamcity

To install Teamcity, follow the instructions from JetBrains, which can be found here (takes less than 10 minutes). I chose to install mine at /var/TeamCity: 

Follow the instructions to set up your external database (recommended approach). I am using a SQL Server 2008 Installation that is already present and regularly backed up in my “private cloud”.  Edit your server.conf to configure a port for the Tomcat Server :

ubuntu@localhost: sudo vi /var/TeamCity/conf/server.xml

Permissions are a chore, but we don’t want the Teamcity Server directory to be owned by our admin user, so we change the owner of our Teamcity install directory to the default www-data user.

ubuntu@localhost: sudo chown -R www-data /var/TeamCity

Next, we want Teamcity to start automatically when the server is booted, so we add a small init script. Be sure to adjust the TEAMCITY_DATA_PATH environment variable to a static directory of your choice, otherwise TCs default will make end up in www-data’s home directory, which is, frankly, a very inconvenient location.

ubuntu@localhost:/var/TeamCity$ cat /etc/init.d/teamcity 
# /etc/init.d/teamcity -  startup script for teamcity
export TEAMCITY_DATA_PATH="/var/TeamCity/.BuildServer"

case $1 in
 start-stop-daemon --start  -c www-data --exec /var/TeamCity/bin/ start

 start-stop-daemon --start -c www-data  --exec  /var/TeamCity/bin/ stop


exit 0

Now we need to register the startup script to run automatically:

ubuntu@localhost: sudo update-rc.d teamcity defaults

Next, we start the server manually (you can reboot too):

ubuntu@localhost: sudo /etc/init.d/teamcity start

Installing Lighttpd

Now we need to install lighttpd:

ubuntu@localhost: sudo apt-get install lighttpd

And configure it to forward requests from port 80 to the port we configured for Tomcat (8080 in my case).

ubuntu@localhost: sudo vi /etc/lighttpd/lighttpd.conf
server.modules = (
#       "mod_rewrite",

$HTTP["host"] =~ "" {
        proxy.server = (
                "" => (
                        "tomcat" => (
                                "host" => "",
                                "port" => 8080,
                                "fix-redirects" => 1

Final Words

That’s it. By now you should have a running teamcity server. If something goes wrong, be sure to check the logs which can be found at /var/TeamCity/logs. To make the server available via DNS, you need to make sure the servers hostname is registered with your local DNS. In my case, I simply added a static record to it.

  1. djs10
    April 21, 2012 at 17:44

    Great article, thanks. Didn’t bother with the lighthttpd bit, but your script for running TC from init.d worked brilliantly.

  2. Ken
    July 11, 2012 at 23:46

    Enjoyed the article. Could you possibly provide same information for CentOS / Red Hat? We want teamcity to start as the teamcity user on reboot.


    • July 12, 2012 at 15:07

      Sorry, no expert on CentOS. Think a quick google should help you here. Good chance the guys at can help you too.

    • abc123
      May 23, 2014 at 20:03

      I did this,
      # teamcity daemon
      # chkconfig: 345 20 80
      # description: teamcity daemon
      # processname: teamcity



      DESC=”teamcity service”

      export TEAMCITY_DATA_PATH=”/opt/TeamCity/.BuildServer”

      case “$1” in
      printf “%-50s” “Starting $NAME…”
      cd $DAEMON_PATH
      PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
      echo “Saving PID” $PID ” to ” $PIDFILE
      if [ -z $PID ]; then
      printf “%s\n” “Fail”
      runuser -l teamcityuser -c ‘exec /opt/TeamCity/bin/ start’
      echo $PID > $PIDFILE
      printf “%s\n” “Ok”
      printf “%-50s” “Checking $NAME…”
      if [ -f $PIDFILE ]; then
      PID=`cat $PIDFILE`
      if [ -z “`ps axf | grep ${PID} | grep -v grep`” ]; then
      printf “%s\n” “Process dead but pidfile exists”
      echo “Running”
      printf “%s\n” “Service not running”
      printf “%-50s” “Stopping $NAME”
      PID=`cat $PIDFILE`
      cd $DAEMON_PATH
      if [ -f $PIDFILE ]; then
      #kill -HUP $PID
      runuser -l teamcityuser -c ‘exec /opt/TeamCity/bin/ stop’
      printf “%s\n” “Ok”
      rm -f $PIDFILE
      printf “%s\n” “pidfile not found”

      $0 stop
      $0 start

      echo “Usage: $0 {status|start|stop|restart}”
      exit 1

  3. Todd Fischer
    August 15, 2012 at 20:06

    I also had to do a

    sudo chmod ugo+x /etc/init.d/teamcity

  1. March 9, 2012 at 07:29
  2. May 11, 2012 at 08:44

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: