Skip to content

Instantly share code, notes, and snippets.

@AlainODea
Created April 16, 2014 18:17
Show Gist options
  • Save AlainODea/10916188 to your computer and use it in GitHub Desktop.
Save AlainODea/10916188 to your computer and use it in GitHub Desktop.
sysv init.d script for TeamCity (tested on Ubuntu)
#!/bin/bash
#
# chkconfig: 235 10 90
# description: TeamCity startup script
#
TEAMCITY_USER=teamcity
TEAMCITY_DIR=/home/teamcity/TeamCity/
TEAMCITY_SERVER=bin/teamcity-server.sh
TEAMCITY_DATADIR="/home/teamcity/.BuildServer"
CATALINA_OPTS="-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses"
case "$1" in
start)
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8543
sudo -u $TEAMCITY_USER -s -- sh -c "cd $TEAMCITY_DIR; TEAMCITY_DATA_PATH=$TEAMCITY_DATADIR CATALINA_OPTS='$CATALINA_OPTS' $TEAMCITY_SERVER start"
;;
stop)
sudo -u $TEAMCITY_USER -s -- sh -c "cd $TEAMCITY_DIR; TEAMCITY_DATA_PATH=$TEAMCITY_DATADIR CATALINA_OPTS='$CATALINA_OPTS' $TEAMCITY_SERVER stop"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
exit 0
@AlainODea
Copy link
Author

Write that file to /etc/init.d/teamcity and run:

chmod +x /etc/init.d/teamcity
update-rc.d teamcity

And you're golden.

The -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses is a workaround for TeamCity's Tomcat binding tcp6 listeners rather than tcp listeners. If you are actually using IPv6 then you'll want to comment out CATALINA_OPTS.

@jasich
Copy link

jasich commented Jul 7, 2014

Running on Debian 7.5 (wheezy) I had to run the following update-rc.d teamcity defaults to set it up to run.

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