Skip to content

Instantly share code, notes, and snippets.

@sandcastle
Last active December 7, 2023 18:02
  • Star 61 You must be signed in to star a gist
  • Fork 48 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sandcastle/9282638 to your computer and use it in GitHub Desktop.
Install TeamCity 9.0.3 on Ubuntu with Nginx

Install

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

Install Team City:

# will install on port 8111
sudo wget -c https://gist.githubusercontent.com/sandcastle/9282638/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.githubusercontent.com/sandcastle/9282638/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.githubusercontent.com/sandcastle/9282638/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-7-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.0.3.tar.gz -O /tmp/TeamCity-9.0.3.tar.gz
sudo tar -xvf /tmp/TeamCity-9.0.3.tar.gz -C /srv
sudo rm -rf /tmp/TeamCity-9.0.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.githubusercontent.com/sandcastle/9282638/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.githubusercontent.com/sandcastle/9282638/raw/postgres.database.properties -O /srv/.BuildServer/config/database.properties
# ensure owership
sudo chown -R teamcity /srv/TeamCity
sudo chown -R teamcity /srv/.BuildServer
@calclavia
Copy link

@chrisjenx
Copy link

Not sure much has changed, but would be nice to be updated to TC 9.1 and how we go about enabling TLS in Nginx

Copy link

ghost commented Feb 23, 2016

Tested and working with 9.1.6. Simply replace the download URLs in teamcity-setup.sh.

@rehmanzile
Copy link

This is very helpful! Thanks..

@matthieudolci
Copy link

matthieudolci commented Apr 28, 2016

here is a nginx conf with ssl

`map $http_upgrade $connection_upgrade {
default upgrade;
'' '';
}

server {
listen 80;
server_name teamcity.blah.com;
rewrite ^ https://$host$request_uri? permanent;

}

server {

listen       443;
server_name  teamcity.blah.com;

    ssl on;
    ssl_certificate /etc/nginx/ssl/wildcard_cert.crt;
    ssl_certificate_key /etc/nginx/ssl/wildcard_cert.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:MEDIUM;
    ssl_prefer_server_ciphers on;

    client_max_body_size 0;
    client_header_buffer_size 50M;

    proxy_read_timeout     1200;
    proxy_connect_timeout  240;

    access_log /var/log/nginx/teamcity-access.log;
    error_log /var/log/nginx/teamcity-error.log;

location / {

    proxy_pass                              http://localhost:8111/;
    proxy_set_header X-Forwarded-Host       $http_host;
    proxy_set_header X-Forwarded-Proto      $scheme;
    #proxy_set_header X-Real-IP             $remote_addr;
    proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
    proxy_http_version                      1.1;
    proxy_set_header Upgrade                $http_upgrade;
    proxy_set_header Connection             "upgrade";
}

}`

@insuusvenerati
Copy link

Why not use the runAll script in teamcity init? Otherwise the build agent will not start.

@nezaboravi
Copy link

Why removing default in sites-enabled? What is the reson?
wondering because if you are using laravel forge to start droplet in Digital Ocean for example, it uses default as your default site there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment