Skip to content

Instantly share code, notes, and snippets.

@ashwoods
Forked from sandcastle/install-teamcity.md
Last active March 8, 2024 23:10
Show Gist options
  • Save ashwoods/c7759c903d3991818b53306d4c01ca6e to your computer and use it in GitHub Desktop.
Save ashwoods/c7759c903d3991818b53306d4c01ca6e to your computer and use it in GitHub Desktop.
Install TeamCity 10.0.2 on Debian/Ubuntu with Nginx

Install

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

Requirements:

  • curl
  • configure utf-8 locale of your choice (recommended)

Install Team City:

# will install on port 8111
curl -L https://gist.github.com/ashwoods/c7759c903d3991818b53306d4c01ca6e/raw/teamcity-install.sh | bash

Configure Postgres 9.4:

See postgres-9-4.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 curl -L https://gist.github.com/ashwoods/c7759c903d3991818b53306d4c01ca6e/raw/nginx.sh | bash

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 default_server;
server_name _;
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
# remove default
sudo rm -rf /etc/nginx/sites-enabled/default
sudo rm -rf /etc/nginx/sites-available/default
# update the config
sudo wget https://gist.github.com/ashwoods/c7759c903d3991818b53306d4c01ca6e/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.4:

sudo apt-get update

Configure remote access:

# open the file and append the lines below
sudo nano /etc/postgresql/9.4/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.4/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://localhost/teamcity
connectionProperties.user=teamcity
connectionProperties.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
set -e
set -u
PG_VERSION="9.4"
PG_PASS=`date +%s | sha256sum | base64 | head -c 32`
PG_USERCMD="CREATE USER teamcity WITH PASSWORD '$PG_PASS';"
PG_DBCMD="CREATE DATABASE teamcity owner teamcity;"
cd /
# install server dependencies
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y oracle-java8-installer
sudo apt-get install postgresql postgresql-contrib
# 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-10.0.2.tar.gz -O /tmp/TeamCity-10.0.2.tar.gz
sudo tar -xvf /tmp/TeamCity-10.0.2.tar.gz -C /srv
sudo rm -rf /tmp/TeamCity-10.0.2.tar.gz
sudo mkdir -p /srv/.BuildServer
# create user
id -u teamcity &>/dev/null || 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/ashwoods/c7759c903d3991818b53306d4c01ca6e/raw/teamcity-init.sh -O /etc/init.d/teamcity
sudo chmod 775 /etc/init.d/teamcity
sudo update-rc.d teamcity defaults
# install postgres
sudo apt-get -y install postgresql-9.4
sudo apt-get -y install postgresql-contrib-9.4
sudo echo $PG_PASS >> /home/teamcity/.pgpass
sudo -u postgres bash -c "psql -c \"$PG_USERCMD\""
sudo -u postgres bash -c "psql -c \"$PG_DBCMD\""
# download postgres driver
sudo mkdir -p /srv/.BuildServer/lib/jdbc
sudo mkdir -p /srv/.BuildServer/config
sudo wget https://jdbc.postgresql.org/download/postgresql-9.4.1212.jar -O /srv/.BuildServer/lib/jdbc/postgresql-9.4.1212.jar
sudo wget https://gist.github.com/ashwoods/c7759c903d3991818b53306d4c01ca6e/raw/postgres.database.properties -O /srv/.BuildServer/config/database.properties
sudo echo -n $PG_PASS >> /srv/.BuildServer/config/database.properties
# ensure owership
sudo chown -R teamcity /srv/TeamCity
sudo chown -R teamcity /srv/.BuildServer
@reatlat
Copy link

reatlat commented May 26, 2020

@ashwoods any reason why you use the old version of TeamCity? the version 10.0.2 has been released about 4 years ago :/

@ashwoods
Copy link
Author

@reatlat I probably also forked it a few years ago. I run teamcity inside a docker container now. https://hub.docker.com/r/jetbrains/teamcity-server/

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