8

I've successfully installed TeamCity ib CentOS 6.2 Minimal. I'm stuck on trying to run a script automatically on system startup:

/opt/TeamCity/bin/teamcity-server.sh start

I've googled around and tried various methods all of which seems to fail. Most of the methods points to adding the startup script to one of the rc.local files:

/etc/rc.d/rc.local
/etc/rc.local

And the contents of rc.local contains the line:

/opt/TeamCity/bin/teamcity-server.sh start

None of which will start the teamcity server

There are no problems if i run the script manually.

Seems simple but how do i get a shell script to auto run?

atp03
  • 209
  • 1
  • 2
  • 5
  • 1
    You'll need to describe what you mean by 'none of which works'. Because without it, everyone's guessing. Maybe describe in more detail what you've done and what output or failure messages or events occurred? – EightBitTony May 14 '12 at 17:06
  • that is the correct place to put it, so it seems that something is not kosher with the /etc/rc.d/rc.local entry or with the script itself. Are you able to post the contents of the script & the rc.local? Also, does the teamcity-server.sh shell script run when you do it manually? – Quinn Murphy May 14 '12 at 17:09
  • Yes, the teamcity-server runs fine manually. But its not practical to do this every time the server is restarted... – atp03 May 14 '12 at 17:15
  • Getting it to run manually but not through rc.local implies environmental differences. What's your PATH? Any other env variables? – cjc May 14 '12 at 18:00
  • @cjc Not sure what you mean by 'PATH' - However if i run /etc/rc.d/rc.local manually the teamcity server can also start fine. Does this still make a difference? – atp03 May 15 '12 at 02:04
  • The /etc/rc.local script executes with a minimal environment. It may not know where to find the necessary executables and libraries. But, since you can run it by hand, that implies that your shell has the right environmental variables to run the teamcity server. One of those environmental variables is the PATH (which is used by your shell to find executables, and, by default, doesn't include something like /opt/TeamCity/bin in it) and possibly library file locations (the LD_LIBRARY_PATH). If you run `env` in your shell, it will show you what environmental variables you have set. – cjc May 15 '12 at 02:20

3 Answers3

15

If the teamcity start script is a LSB-compliant init script (that is, if it provides start, stop and other arguments), you can just copy the script to /etc/init.d folder and run (as root):

# chkconfig --add <script_name>
# chkconfig <script_name> on

A symbolic link for the file should be OK too. So try (as root):

# ln -s /opt/TeamCity/bin/teamcity-server.sh /etc/init.d/teamcity-server
# chkconfig --add teamcity-server
# chkconfig teamcity-server on

If it doesn't start on initialization, but starting manually without problems, you should check:

  1. permissions (maybe the program can not be run as root. Try to log on as root and run it), and;
  2. your PATH (maybe the script need something but it does not know where it is).

To print the content of your PATH just run:

echo $PATH

To check if the reason to the script not start is the PATH, try:

$ cd /
$ PATH= /opt/TeamCity/bin/teamcity-server.sh

This command will temporary clear your PATH and run the command. If the command need some specific info on the PATH it will fail (be careful to run exactly as stated above, THERE IS a space between PATH= and the remaining of the command).

Diego Queiroz
  • 280
  • 1
  • 9
6

in Fedora 17 command

# chkconfig --add teamcity-server

say: service teamcity-server does not support chkconfig you should add header like:

#! /bin/bash
# chkconfig: - 10 90

only after that run first command.

burtsevyg
  • 158
  • 2
  • 7
2

When the script is run manually, it works correctly. But, when run automatically it doesn't work.

I've found the culprit: TeamCity runs under the user teamcity. It must be present in the /etc/sudoers file and you should add, using visudo a line like this:

Defaults:teamcity !requiretty
dawud
  • 14,918
  • 3
  • 41
  • 61
kupolua
  • 21
  • 2