Skip to content

Instantly share code, notes, and snippets.

@haraldreingruber
Forked from sandcastle/install-teamcity.md
Last active September 24, 2015 21:38
Install TeamCity 9.1.3 on Ubuntu with Nginx

Install

Follow the steps below to install Team City 9.1.3 on Ubuntu with Nginx as the proxy for port 80.

Install Team City:

# will install on port 8111
sudo wget -c https://gist.github.com/haraldreingruber/c0dedecd07af9ed3ed9d/raw/teamcity-install.sh -O /tmp/teamcity-install.sh
sudo sh /tmp/teamcity-install.sh
sudo rm -rf /tmp/teamcity-install.sh

Install Postgres 9.3:

See postgres-9-3.md below

Update the database settings:

sudo nano /srv/.BuildServer/config/database.properties

Install Nginx:

#will proxy port 80 to team city on 8111
sudo wget -c https://gist.github.com/haraldreingruber/c0dedecd07af9ed3ed9d/raw/nginx.sh -O /tmp/nginx.sh
sudo sh /tmp/nginx.sh
sudo rm -rf /tmp/nginx.sh

Update nginx config:

sudo nano /etc/nginx/sites-available/teamcity

Remove the default ngnix server:

sudo rm -rf /etc/nginx/sites-enabled/default
sudo rm -rf /etc/nginx/sites-available/default

Start it up:

sudo /etc/init.d/nginx start
sudo /etc/init.d/teamcity start

Commands:

#start team city
sudo /etc/init.d/teamcity start

#stop team city
sudo /etc/init.d/teamcity stop

#star nginx
sudo /etc/init.d/nginx start

#stop nginx
sudo /etc/init.d/nginx stop

#reload nginx
sudo /etc/init.d/nginx reload

#test team city on port 8111
curl http://localhost:8111

#test team city on port 80
curl http://localhost:80
# We need to support websockets from TC 9.x onwards
# https://confluence.jetbrains.com/display/TCD9/How+To...#HowTo...-SetUpTeamCitybehindaProxyServer
map $http_upgrade $connection_upgrade {
default upgrade;
'' '';
}
server {
listen 80;
server_name localhost <DNS-ENTRY-HERE>;
proxy_read_timeout 1200;
proxy_connect_timeout 240;
client_max_body_size 0;
location / {
proxy_pass http://localhost:8111/tc;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $server_name:$server_port;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
#!/bin/sh
# install nginx
sudo apt-get install -y nginx
# update the config
sudo wget https://gist.github.com/haraldreingruber/c0dedecd07af9ed3ed9d/raw/nginx.conf -O /etc/nginx/sites-available/teamcity
sudo mkdir -p /var/www/teamcity
# create syn link
sudo ln -s /etc/nginx/sites-available/teamcity /etc/nginx/sites-enabled/teamcity
# reload
sudo /etc/init.d/nginx reload

Install

The following steps should be followed to install and configure postgres.

Install postgres 9.3:

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

Configure remote access:

# open the file and append the lines below
sudo nano /etc/postgresql/9.3/main/pg_hba.conf

# remote access (where x.x.x.x is your IP)
host all all x.x.x.x/32 md5

# servers (repeat this line per server)
host all all x.x.x.x/32 md5

Configure listening:

# open the file and change the lines below
sudo nano /etc/postgresql/9.3/main/postgresql.conf

listen_addresses = '*'

Access the psql command line:

# switch user to the postgres user
sudo su - postgres

# load the command line
psql

# create the team city user
create role teamcity with login password '<password>';
create database teamcity owner teamcity;

Restart postgres:

sudo /etc/init.d/postgresql restart
connectionUrl=jdbc:postgresql://<host>/teamcity
connectionProperties.user=<user>
connectionProperties.password=<password>
#!/bin/sh
# /etc/init.d/teamcity - startup script for teamcity
export TEAMCITY_DATA_PATH="/srv/.BuildServer"
case $1 in
start)
echo "Starting Team City"
start-stop-daemon --start -c teamcity --exec /srv/TeamCity/bin/teamcity-server.sh start
;;
stop)
echo "Stopping Team City"
start-stop-daemon --start -c teamcity --exec /srv/TeamCity/bin/teamcity-server.sh stop
;;
restart)
echo "Restarting Team City"
start-stop-daemon --start -c teamcity --exec /srv/TeamCity/bin/teamcity-server.sh stop
start-stop-daemon --start -c teamcity --exec /srv/TeamCity/bin/teamcity-server.sh start
;;
*)
echo "Usage: /etc/init.d/teamcity {start|stop|restart}"
exit 1
;;
esac
exit 0
#!/bin/bash
cd /
# install server dependencies
sudo apt-get update
sudo apt-get install -y openjdk-8-jre-headless
sudo apt-get install -y curl
# install build agent dependencies
#sudo apt-get install -y mercurial
sudo apt-get install -y git
# install team city
sudo wget -c https://download.jetbrains.com/teamcity/TeamCity-9.1.3.tar.gz -O /tmp/TeamCity-9.1.3.tar.gz
sudo tar -xvf /tmp/TeamCity-9.1.3.tar.gz -C /srv
sudo rm -rf /tmp/TeamCity-9.1.3.tar.gz
sudo mkdir /srv/.BuildServer
# create user
sudo useradd -m teamcity
sudo chown -R teamcity /srv/TeamCity
sudo chown -R teamcity /srv/.BuildServer
# create init.d script
sudo wget https://gist.github.com/haraldreingruber/c0dedecd07af9ed3ed9d/raw/teamcity-init.sh -O /etc/init.d/teamcity
sudo chmod 775 /etc/init.d/teamcity
sudo update-rc.d teamcity defaults
# download postgres
sudo mkdir -p /srv/.BuildServer/lib/jdbc
sudo mkdir -p /srv/.BuildServer/config
sudo wget http://jdbc.postgresql.org/download/postgresql-9.3-1101.jdbc41.jar -O /srv/.BuildServer/lib/jdbc/postgresql-9.3-1101.jdbc41.jar
sudo wget https://gist.github.com/haraldreingruber/c0dedecd07af9ed3ed9d/raw/postgres.database.properties -O /srv/.BuildServer/config/database.properties
# ensure owership
sudo chown -R teamcity /srv/TeamCity
sudo chown -R teamcity /srv/.BuildServer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment