Problem:
When I try and install my agent as a service with a user account it fails to start.
Even if I try to start it from services window it fails.
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.
- Press the Windows Key
- Type services
- Click Services
- Right-click on VSTS Agent (<account.agent Name>)
- Select Properties
- Click Log On
- Re-enter your password
- Click Apply
Windows will automatically grant the Log on as a service right to your account.
- Click OK
- Click OK
- Right-click on VSTS Agent (<account.agent Name>)
- Select Start
Your agent should start
Your second option is to manually grant the Log on as a service right using Group Policy.
- Press the Windows Key
- Type group
- Click Edit group policy
- From the tree expand Windows Settings / Security Settings / Local Policies
- Select User Rights Assignment
- Double-click Log on as a service
- Click Add User or Group
- Enter the name of the user
- Click Check Names
- Click OK
- Click OK
- Return to command prompt where you configured your agent
- Type
net start “VSTS Agent (<account.agent Name>)”
Replace <account.agent Name> with your information
Your agent should start