My VSTS Agent fails to start when configured as a service

Problem:

When I try and install my agent as a service with a user account it fails to start.

image

Even if I try to start it from services window it fails.

image

Solution:

Make sure the account has the “Log on as a service” right.

Explanation:

After configuring my agent with the following command my agent failed to start.

.\config.cmd --url https://<Account>.visualstudio.com --auth PAT --token <token> --pool default --runasservice --windowslogonaccount <DOMAIN\USER_NAME> --password <MyPassword> --work _work --agent <AgentName>

Windows services begin to run as soon as Windows boots regardless if anyone logs into the machines or not. Therefore, any accounts used as the service identity must have the right to log on as a service.  I needed to run my service as a user account because package management systems like NPM install packages per user.  Those packages cannot be used by the Network Service account so I configure my service based agents to run under a user account.

To correct this you have two options. Your first option is to do everything from the Services window.

  1. Press the Windows Key
  2. Type services
  3. Click Services
    image
  4. Right-click on VSTS Agent (<account.agent Name>)
  5. Select Properties
  6. Click Log On
  7. Re-enter your password
  8. Click Apply
    Windows will automatically grant the Log on as a service right to your account.
    image
  9. Click OK
  10. Click OK
  11. Right-click on VSTS Agent (<account.agent Name>)
  12. Select Start
    Your agent should start

Your second option is to manually grant the Log on as a service right using Group Policy.

  1. Press the Windows Key
  2. Type group
  3. Click Edit group policy
    image
  4. From the tree expand Windows Settings / Security Settings / Local Policies
  5. Select User Rights Assignment
  6. Double-click Log on as a service
  7. Click Add User or Group
  8. Enter the name of the user
  9. Click Check Names
  10. Click OK
  11. Click OK
  12. Return to command prompt where you configured your agent
  13. Type
    net start “VSTS Agent (<account.agent Name>)”
    Replace <account.agent Name> with your information
    Your agent should start
    image

Add comment

Loading