20

We are trying to setup a build agent and every time we start it the log shows the following messages:

[2012-09-18 12:52:01,805]   INFO -    jetbrains.buildServer.AGENT - Starting agent shutdown sequence, reason: Restart agent, failed to download upgrade from server 
[2012-09-18 12:52:01,821]   INFO -    jetbrains.buildServer.AGENT - Host configuration for downloading updates: HostConfiguration[host=http://localhost:8000] 
[2012-09-18 12:52:01,821]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/teamcity-agent.xml ==> E:\buildAgent\temp\m8a1mAwTuLIngev3yRUMPUuaYWZFmMSh 
[2012-09-18 12:52:01,849]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/agentSystemInfo.zip ==> E:\buildAgent\update\plugins\agentSystemInfo.zip 
[2012-09-18 12:52:01,880]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/amazonEC2.zip ==> E:\buildAgent\update\plugins\amazonEC2.zip 
[2012-09-18 12:52:01,921]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/ant.zip ==> E:\buildAgent\update\plugins\ant.zip 
[2012-09-18 12:52:02,056]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/antPlugin.zip ==> E:\buildAgent\update\plugins\antPlugin.zip 
[2012-09-18 12:52:02,078]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/assembly-info-patcher.zip ==> E:\buildAgent\update\plugins\assembly-info-patcher.zip 
[2012-09-18 12:52:02,098]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/clearcase-agent.zip ==> E:\buildAgent\update\plugins\clearcase-agent.zip 
[2012-09-18 12:52:02,106]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/commandLineRunner.jar ==> E:\buildAgent\update\plugins\commandLineRunner.jar 
[2012-09-18 12:52:02,118]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/coveragePlugin.zip ==> E:\buildAgent\update\plugins\coveragePlugin.zip 
[2012-09-18 12:52:02,151]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/crashDetector.zip ==> E:\buildAgent\update\plugins\crashDetector.zip 
[2012-09-18 12:52:02,163]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/cvsAgent.zip ==> E:\buildAgent\update\plugins\cvsAgent.zip 
[2012-09-18 12:52:02,183]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/dotCover.zip ==> E:\buildAgent\update\plugins\dotCover.zip 
[2012-09-18 12:52:02,308]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/dotNetPlugin.zip ==> E:\buildAgent\update\plugins\dotNetPlugin.zip 
[2012-09-18 12:52:03,830]   INFO - agent.impl.AgentPortFileWriter - Delete agent runtime file from E:\buildAgent\logs\buildAgent.port 
[2012-09-18 12:52:03,831]   INFO -    jetbrains.buildServer.AGENT - Unregistering from build server: 5 

Has anyone seen anything like this before? We've looked at the server logs and aren't seeing anything on them to indicate what could be wrong.

Shane Courtrille
  • 13,960
  • 22
  • 76
  • 113

7 Answers7

18

I ran into the same issue. Both the build agent and the server are installed on Windows Server 2012.

I stopped the build agent service and deleted the logs from BuildAgent\logs and restarted the build agent service so I could see a fresh log.

upgrade.log showed me that the build agent received a call from the teamcity server to upgrade. The log also showed the following:

"Please check TeamCity build agent service user have enough permissions to stop and start the service."

Using the Local Security Policy, I granted the build agent service user "logon as a service" rights but this is not sufficient to start and stop a service. By default, only members of the Administrators group can start, stop, pause, resume or restart a service. After I added the build agent service user to the Administrator group and restarted the build agent service, the upgrade finished successfully and the agent connected again.

Alternatively, as described by BatteryBackupUnit and https://web.archive.org/web/20171019005501/http://windowsitpro.com/security/letting-user-start-and-stop-services-without-granting-user-administrator-privileges, it's possible to give the TeamCity Windows user account the start, stop and pause permissions on the TeamCity Build Agent service. The article says that something like

subinacl /service spooler /grant=contoso\cortana=top

will suffice.

Or, if you don't want to use a tool that Microsoft no longer makes available, then you can use Process Explorer, as described at https://superuser.com/a/315709/12337.

Zian Choy
  • 2,846
  • 6
  • 33
  • 64
Frank Rem
  • 3,632
  • 2
  • 25
  • 37
  • 6
    If you don't want to grant the service-user administrative privileges (which you should not, from a security point of perspective), there's another way to just grant specific service start/stop privileges, see [here](http://windowsitpro.com/security/letting-user-start-and-stop-services-without-granting-user-administrator-privileges) – BatteryBackupUnit Feb 13 '15 at 08:27
  • The error logged in this case would include something along the lines of `Failed to stop TeamCity build agent service via net.exe.` indicating this would fix the problem, as it did for me. The logs above don't show any symptoms of this specifically. – pharma_joe Dec 09 '16 at 05:49
11

I had this problem when running the agent with systemd on Ubuntu 18.04. The agent exits with code 143 when upgrading and this is interpreted as an error. It needs to be added to the list of acceptable error codes with SuccessExitStatus=143 0

Here's the full configuration:

[Unit]
Description=TeamCity Build Agent
After=network.target

[Service]
Type=forking
RemainAfterExit=yes
PIDFile=/build-agent/logs/buildAgent.pid
ExecStart=/build-agent/bin/agent.sh start
ExecStop=/build-agent/bin/agent.sh stop
User=build
Group=build

Restart=on-failure
RestartSec=5s

# agent will exit with 143 during upgrade process
SuccessExitStatus=143 0

[Install]
WantedBy=multi-user.target
Steve Rukuts
  • 9,167
  • 3
  • 50
  • 72
8

The TeamCity build agent can sometimes take a long time to upgrade. If you believe that the upgrading takes too long with no positive results do as follows:

  1. Uninstall the build agent
  2. Download the build agent pack from your server
  3. Reinstall the agent

Upgrading process should go faster after this. If it does not help it is better to contact JetBrains tech support.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
6

A really simple way of doing this if your enterprise security policy doesn't allow you to add users to the 'Administrators' group, but the user your logged on as does have elevated rights. Stop the service running, via the Services.msc and then open a command prompt (with elevated rights) in the agent bin directory and run

agent.bat start

Let the agent update with this user and then once it has finished and you can see it successfully registered in the Teamcity UI. Kill the processes and restart the Service.

Colin Bull
  • 959
  • 7
  • 15
4

If you're using a "jailed" build user like we are, you'll see "Please check TeamCity build agent service user have enough permissions to stop and start the service."

There are workarounds but no graceful solution to this. Here's why:

  • Workaround 1: "TCBuildAgent" service needs "jailed" needs start/stop service credential access assigned to it. SubinACL is your best tool for assigning this (lengthy but full discussion).
    • TeamCity removes "TCBuildAgent" and installs a new one, effectively eliminating the service credentials assigned to it. So, you must issue SubinACL grant access commands every time you upgrade. Clumsy and annoying
  • Workaround 2: Aforementioned tip of adding "jailed" to Administrators group is viable and permits a proper upgrade, though violates the concept of a "jailed" user.

After much fiddling with SubinACL, I've thrown in the towel and just temporarily add "jailed" to Administrators group for the upgrade process then remove it afterward.

I trust that Jetbrains isn't gonna do something awful and malicious with TCBuildAgent... not during upgrade, anyway ;)

Community
  • 1
  • 1
Malachi
  • 2,260
  • 3
  • 27
  • 40
1

I had a similar problem. helped me to reinstall the antivirus.

http://devnet.jetbrains.com/thread/440728

Andrew Luzkovky
  • 251
  • 3
  • 10
-1
  1. Stop the agent:

    ./agent.bat stop

  2. Reinstall agent.

  3. Start the agent:

    ./agent.bat start

Max
  • 1
  • 3