Skip to content

Instantly share code, notes, and snippets.

@simoneb
Forked from sandcastle/install-teamcity.md
Last active July 18, 2022 15:18
Show Gist options
  • Save simoneb/cedac22c58ad0a9e37cddd84abe975a3 to your computer and use it in GitHub Desktop.
Save simoneb/cedac22c58ad0a9e37cddd84abe975a3 to your computer and use it in GitHub Desktop.
Install TeamCity on Ubuntu with Nginx

Install

Follow the steps below to install Team City 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/simoneb/cedac22c58ad0a9e37cddd84abe975a3/raw/teamcity-install.sh -O /tmp/teamcity-install.sh
sudo sh /tmp/teamcity-install.sh
sudo rm -rf /tmp/teamcity-install.sh

Install Postgres:

See postgres.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/simoneb/cedac22c58ad0a9e37cddd84abe975a3/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/simoneb/cedac22c58ad0a9e37cddd84abe975a3/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
connectionUrl=jdbc:postgresql://<host>/teamcity
connectionProperties.user=<user>
connectionProperties.password=<password>

Install

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

Install postgres:

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/X.x/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/X.x/main/postgresql.conf

listen_addresses = '*'

Configure TeamCity recommended options:

https://confluence.jetbrains.com/display/TCD9/How+To...#HowTo...-ConfigureNewlyInstalledPostgreSQLServer

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
#!/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/runAll.sh start
;;
stop)
echo "Stopping Team City"
start-stop-daemon --start -c teamcity --exec /srv/TeamCity/bin/runAll.sh stop
;;
restart)
echo "Restarting Team City"
start-stop-daemon --start -c teamcity --exec /srv/TeamCity/bin/runAll.sh stop
start-stop-daemon --start -c teamcity --exec /srv/TeamCity/bin/runAll.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 git
# install team city
sudo wget -c https://download.jetbrains.com/teamcity/TeamCity-9.1.7.tar.gz -O /tmp/TeamCity.tar.gz
sudo tar -xvf /tmp/TeamCity.tar.gz -C /srv
sudo rm -rf /tmp/TeamCity.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/simoneb/cedac22c58ad0a9e37cddd84abe975a3/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 https://jdbc.postgresql.org/download/postgresql-9.4.1208.jre7.jar -O /srv/.BuildServer/lib/jdbc/postgresql-9.4.1208.jre7.jar
sudo wget https://gist.githubusercontent.com/simoneb/cedac22c58ad0a9e37cddd84abe975a3/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