Skip to content

Commit

Permalink
Add prompt for autostarting service on Windows (#3534)
Browse files Browse the repository at this point in the history
* add prompt for service start

* fix strings json to prettify it

* remove rus language

* fix code style

* update for using from cmd

* prettyfy

* remove additional arg

* add param to strings

Co-authored-by: Ilya Kuleshov <[email protected]>
Co-authored-by: Anatoly Bolshakov <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2021
1 parent 9e36097 commit 0eff66a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Agent.Listener/CommandLine/ConfigureAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public class ConfigureAgent : ConfigureOrRemoveBase
[Option(Constants.Agent.CommandLine.Flags.Once)]
public bool RunOnce { get; set; }

[Option(Constants.Agent.CommandLine.Flags.PreventServiceStart)]
public bool PreventServiceStart { get; set; }

[Option(Constants.Agent.CommandLine.Args.SslCACert)]
public string SslCACert { get; set; }

Expand Down
10 changes: 10 additions & 0 deletions src/Agent.Listener/CommandSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ public bool GetRunAsService()
defaultValue: false);
}

public bool GetPreventServiceStart()
{
return TestFlagOrPrompt(
value: Configure?.PreventServiceStart,
name: Constants.Agent.CommandLine.Flags.PreventServiceStart,
description: StringUtil.Loc("PreventServiceStartDescription"),
defaultValue: false
);
}

public bool GetRunAsAutoLogon()
{
return TestFlagOrPrompt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ public void ConfigureService(AgentSettings settings, CommandSettings command)
_windowsServiceHelper.CreateVstsAgentRegistryKey();

Trace.Info("Configuration was successful, trying to start the service");
_windowsServiceHelper.StartService(serviceName);
if(!command.GetPreventServiceStart())
{
_windowsServiceHelper.StartService(serviceName);
}

}

public void UnconfigureService()
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.VisualStudio.Services.Agent/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static class Flags
public const string Once = "once";
public const string RunAsAutoLogon = "runasautologon";
public const string RunAsService = "runasservice";
public const string PreventServiceStart = "preventservicestart";
public const string SslSkipCertValidation = "sslskipcertvalidation";
public const string Unattended = "unattended";
public const string Version = "version";
Expand Down
5 changes: 5 additions & 0 deletions src/Misc/layoutbin/en-US/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"Startup options (Windows only):",
" --runAsService Configure the agent to run as a Windows service. Requires",
" administrator permission.",
" --preventServiceStart Configure Windows service to not run immediately after configuration.",
" --runAsAutoLogon Configure auto logon and run the agent on startup. Requires",
" administrator permission.",
" --windowsLogonAccount <account> Used with --runAsService or --runAsAutoLogon. Specify the Windows user",
Expand Down Expand Up @@ -182,6 +183,9 @@
"Run as a Windows service that logs on as a domain account (Windows only)",
".\\config.cmd --unattended --url https://myaccount.visualstudio.com --auth pat --token myToken --pool default --agent myAgent --runAsService --windowsLogonAccount myDomain\\myUserName --windowsLogonPassword myPassword",
"",
"Run as a Windows service that logs on as a domain account (Windows only) and doesn't start service immediately",
".\\config.cmd --unattended --url https://myaccount.visualstudio.com --auth pat --token myToken --pool default --agent myAgent --runAsService --preventServiceStart --windowsLogonAccount myDomain\\myUserName --windowsLogonPassword myPassword ",
"",
"Run as an auto logon agent (Windows only)",
".\\config.cmd --unattended --url https://myaccount.visualstudio.com --auth pat --token myToken --pool default --agent myAgent --runAsAutoLogon --windowsLogonAccount myDomain\\myUserName --windowsLogonPassword myPassword",
"",
Expand Down Expand Up @@ -438,6 +442,7 @@
"PrepareTaskExecutionHandler": "Preparing task execution handler.",
"Prepending0WithDirectoryContaining1": "Prepending {0} environment variable with directory containing '{1}'.",
"PrerequisitesSectionHeader": "Prerequisites",
"PreventServiceStartDescription": "whether to prevent service starting immediately after configuration is finished? (Y/N)",
"ProcessCompletedWithCode0Errors1": "Process completed with exit code {0} and had {1} error(s) written to the error stream.",
"ProcessCompletedWithExitCode0": "Process completed with exit code {0}.",
"ProcessExitCode": "Exit code {0} returned from process: file name '{1}', arguments '{2}'.",
Expand Down

0 comments on commit 0eff66a

Please sign in to comment.