Skip to content

Instantly share code, notes, and snippets.

@ismell
Last active July 20, 2018 09:52
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save ismell/6284563 to your computer and use it in GitHub Desktop.
Save ismell/6284563 to your computer and use it in GitHub Desktop.
Ubuntu Upstart Script for Team City

Ubuntu Upstart Script for Team City

  1. Install TeamCity.conf and TeamCityAgent.conf in /etc/init/

  2. Create TeamCity in /etc/default/TeamCity

  3. Make sure TEAMCITY_DATA_PATH and TEAMCITY_SERVER_PATH are owned by www-data

  4. Start TeamCity

     sudo service TeamCity start
    
  5. Start TeamCityAgent

     sudo service TeamCityAgent start
    
# TeamCity Configuration Options
TEAMCITY_SERVER_ENABLED=yes
TEAMCITY_SERVER_PATH="/var/lib/TeamCity/8.0.3"
TEAMCITY_SERVER_MEM_OPTS="-Xms750m -Xmx750m -XX:MaxPermSize=270m"
TEAMCITY_DATA_PATH="/var/lib/TeamCity/BuildServer"
TEAMCITY_SERVER_OPTS=""
TEAMCITY_AGENT_ENABLED=yes
TEAMCITY_AGENT_PATH="/var/lib/TeamCity/8.0.3/buildAgent"
TEAMCITY_AGENT_MEM_OPTS="-Xmx384m"
TEAMCITY_AGENT_CONFIG_FILE="/var/lib/TeamCity/BuildAgent/buildAgent.properties"
TEAMCITY_AGENT_LOG_DIR="/var/lib/TeamCity/BuildAgent/logs"
TEAMCITY_AGENT_OPTS=""
description "TeamCity Server"
start on runlevel [2345]
stop on runlevel [016]
# TeamCity can take a while to shutdown
kill timeout 30
respawn
pre-start script
[ ! -f /etc/default/TeamCity ] && { stop; exit 0; }
. /etc/default/TeamCity
[ "$TEAMCITY_SERVER_ENABLED" != "yes" ] && { stop; exit 0; }
exit 0
end script
script
. /etc/default/TeamCity
CATALINA_OPTS="$CATALINA_OPTS $TEAMCITY_SERVER_OPTS -server $TEAMCITY_SERVER_MEM_OPTS -Dlog4j.configuration=\"file:${TEAMCITY_SERVER_PATH}/conf/teamcity-server-log4j.xml\" -Dteamcity_logs=${TEAMCITY_SERVER_PATH}/logs -Djava.awt.headless=true"
export CATALINA_OPTS
export TEAMCITY_DATA_PATH
exec start-stop-daemon --start -c www-data --exec "${TEAMCITY_SERVER_PATH}/bin/catalina.sh" -- run
end script
description "TeamCity Build Agent"
start on runlevel [2345]
stop on runlevel [016]
# TeamCity can take a while to shutdown
kill timeout 30
respawn
pre-start script
[ ! -f /etc/default/TeamCity ] && { stop; exit 0; }
. /etc/default/TeamCity
[ "$TEAMCITY_AGENT_ENABLED" != "yes" ] && { stop; exit 0; }
[ ! -f "${TEAMCITY_AGENT_PATH}/bin/agent.sh" ] && { stop; exit 0; }
exit 0
end script
script
. /etc/default/TeamCity
export TEAMCITY_AGENT_MEM_OPTS
export TEAMCITY_AGENT_OPTS
export CONFIG_FILE="${TEAMCITY_AGENT_CONFIG_FILE}"
export LOG_DIR="${TEAMCITY_AGENT_LOG_DIR}"
exec start-stop-daemon --start -c www-data --exec "${TEAMCITY_AGENT_PATH}/bin/agent.sh" -- run
end script
@VladRassokhin
Copy link

It's better to start TeamCity server with teamcity-server.sh, but it need some patching to allow 'run' command ;)

@Br41nbug
Copy link

For TEAMCITY 9.02 edit in /etc/default/TeamCity :

TEAMCITY_AGENT_ENABLED=yes
TEAMCITY_AGENT_PATH="/var/TeamCity/buildAgent"
TEAMCITY_AGENT_MEM_OPTS="-Xmx384m"
TEAMCITY_AGENT_CONFIG_FILE="/var/TeamCity/buildAgent/conf/buildAgent.properties"
TEAMCITY_AGENT_LOG_DIR="/var/TeamCity/buildAgent/logs"
TEAMCITY_AGENT_OPTS=""

@grundic
Copy link

grundic commented Apr 13, 2015

You are missing chdir in start-stop-daemon:
exec start-stop-daemon --start -c teamcity --chdir "${TEAMCITY_SERVER_PATH}/bin" --exec "${TEAMCITY_SERVER_PATH}/bin/catalina.sh" -- run
Otherwise process would try to create velocity.log in the / folder and would spam log with access denied errors.

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