-
Notifications
You must be signed in to change notification settings - Fork 0
/
teamcity-install.sh
92 lines (74 loc) · 2.58 KB
/
teamcity-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
#title :teamcity-install.sh
#description :The script to install TeamCity 9.x
#more :https://confluence.jetbrains.com/display/TCD9/Installing+and+Configuring+the+TeamCity+Server
#author :Tomas Pecserke
#date :2016-05-03T14:43+0100
#usage :/bin/bash teamcity-install.sh
#tested-version :9.1.7
#tested-distros :Ubuntu 16.04
TEAMCITY_VERSION=9.1.7
TEAMCITY_FILENAME=TeamCity-$TEAMCITY_VERSION
TEAMCITY_ARCHIVE_NAME=$TEAMCITY_FILENAME.tar.gz
TEAMCITY_DOWNLOAD_ADDRESS=https://download.jetbrains.com/teamcity/$TEAMCITY_ARCHIVE_NAME
INSTALL_DIR=/opt
TEAMCITY_DIR=$INSTALL_DIR/teamcity
TEAMCITY_USER="teamcity"
TEAMCITY_GROUP="teamcity"
TEAMCITY_SERVICE="teamcity"
TEAMCITY_SERVICE_STARTUP_TIMEOUT=240
TEAMCITY_SERVICE_SHUTDOWN_TIMEOUT=30
if [ $EUID -ne 0 ]; then
echo "This script must be run as root."
exit 1
fi
if [ ! -x /bin/systemctl ]; then
echo "Systemd not found. This script uses systemd service to manage TeamCity."
exit 1
fi
if [ $(java -version 2>&1 | head -n 1 | grep 1.8 -c) -ne 1 ]; then
echo "Java 1.8 is required."
exit 1
fi
echo "Downloading: $TEAMCITY_DOWNLOAD_ADDRESS..."
cd /tmp
if [ -e "$TEAMCITY_ARCHIVE_NAME" ]; then
echo 'TeamCity archive already exists.'
else
curl -L -O $TEAMCITY_DOWNLOAD_ADDRESS
if [ $? -ne 0 ]; then
echo "Not possible to download TeamCity."
exit 1
fi
fi
echo "Creating user and group..."
getent group $TEAMCITY_GROUP > /dev/null || \
groupadd $TEAMCITY_GROUP
getent passwd $TEAMCITY_USER > /dev/null || \
useradd -s /bin/false -g $TEAMCITY_GROUP -d $INSTALL_DIR $TEAMCITY_USER
echo "Installation..."
mkdir $TEAMCITY_DIR -p
tar -xzf $TEAMCITY_ARCHIVE_NAME -C $TEAMCITY_DIR --strip-components=1
chown -R $TEAMCITY_USER:$TEAMCITY_GROUP $TEAMCITY_DIR
chown -R $TEAMCITY_USER:$TEAMCITY_GROUP $TEAMCITY_DIR/
echo "Registering service..."
cat > /etc/systemd/system/$TEAMCITY_SERVICE.service << "EOF"
[Unit]
Description=TeamCity continuous integration and deployment server
After=network.target
[Service]
Type=forking
ExecStart=$TEAMCITY_DIR/bin/runAll.sh start
ExecStop=$TEAMCITY_DIR/bin/runAll.sh stop
User=$TEAMCITY_USER
Group=$TEAMCITY_GROUP
[Install]
WantedBy=multi-user.target
EOF
sed -i -e 's,$TEAMCITY_DIR,'$TEAMCITY_DIR',g' /etc/systemd/system/$TEAMCITY_SERVICE.service
sed -i -e 's,$TEAMCITY_USER,'$TEAMCITY_USER',g' /etc/systemd/system/$TEAMCITY_SERVICE.service
sed -i -e 's,$TEAMCITY_GROUP,'$TEAMCITY_GROUP',g' /etc/systemd/system/$TEAMCITY_SERVICE.service
systemctl daemon-reload
systemctl enable $TEAMCITY_SERVICE
echo "Starting service..."
systemctl start $TEAMCITY_SERVICE