Skip to content

Instantly share code, notes, and snippets.

@alcoheca
Forked from stellio-team/install-teamcity.md
Last active September 9, 2019 13:29
Show Gist options
  • Save alcoheca/b6b366e0adbf27b1038edf5b2165da55 to your computer and use it in GitHub Desktop.
Save alcoheca/b6b366e0adbf27b1038edf5b2165da55 to your computer and use it in GitHub Desktop.
Install TeamCity 10.0.2 on Ubuntu with Nginx

Install

Follow the steps below to install Team City 10.0.2 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/stellio-team/2746a286f718710944967a9177175b5e/raw/b7457ca26bab3b01db642cfb179a17d88934c130/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
apt-get update
apt-get install -y openjdk-7-jre-headless
apt-get install -y curl
# install build agent dependencies
apt-get install -y mercurial
apt-get install -y git
# install team city
wget -c https://download.jetbrains.com/teamcity/TeamCity-10.0.2.tar.gz -O /tmp/TeamCity-10.0.2.tar.gz
tar -xvf /tmp/TeamCity-10.0.2.tar.gz -C /srv
rm -rf /tmp/TeamCity-10.0.2.tar.gz
mkdir /srv/.BuildServer
# create user
useradd -m teamcity
chown -R teamcity /srv/TeamCity
chown -R teamcity /srv/.BuildServer
# create init.d script
wget https://gist.githubusercontent.com/sandcastle/9282638/raw/teamcity-init.sh -O /etc/init.d/teamcity
chmod 775 /etc/init.d/teamcity
update-rc.d teamcity defaults
# download postgres
mkdir -p /srv/.BuildServer/lib/jdbc
mkdir -p /srv/.BuildServer/config
wget http://jdbc.postgresql.org/download/postgresql-9.3-1101.jdbc41.jar -O /srv/.BuildServer/lib/jdbc/postgresql-9.3-1101.jdbc41.jar
wget https://gist.githubusercontent.com/sandcastle/9282638/raw/postgres.database.properties -O /srv/.BuildServer/config/database.properties
# ensure owership
chown -R teamcity /srv/TeamCity
chown -R teamcity /srv/.BuildServer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment