-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
410 additions
and
67 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/Agent.Listener/Configuration.FreeBSD/DaemonControlManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.Versioning; | ||
using System.Text; | ||
using Microsoft.VisualStudio.Services.Agent.Util; | ||
|
||
namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration | ||
{ | ||
[ServiceLocator(Default = typeof(DaemonControlManager))] | ||
[SupportedOSPlatform("freebsd")] | ||
public interface IFreeBSDServiceControlManager : IAgentService | ||
{ | ||
void GenerateScripts(AgentSettings settings); | ||
} | ||
|
||
[SupportedOSPlatform("freebsd")] | ||
public class DaemonControlManager : ServiceControlManager, IFreeBSDServiceControlManager | ||
{ | ||
private const string _svcNamePattern = "vsts.agent.{0}.{1}.{2}.service"; | ||
private const string _svcDisplayPattern = "Azure Pipelines Agent ({0}.{1}.{2})"; | ||
private const string _shTemplate = "daemon.svc.sh.template"; | ||
private const string _shName = "svc.sh"; | ||
|
||
public void GenerateScripts(AgentSettings settings) | ||
{ | ||
try | ||
{ | ||
string serviceName; | ||
string serviceDisplayName; | ||
CalculateServiceName(settings, _svcNamePattern, _svcDisplayPattern, out serviceName, out serviceDisplayName); | ||
|
||
string svcShPath = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), _shName); | ||
|
||
string svcShContent = File.ReadAllText(Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Bin), _shTemplate)); | ||
var tokensToReplace = new Dictionary<string, string> | ||
{ | ||
{ "{{SvcDescription}}", serviceDisplayName }, | ||
{ "{{SvcNameVar}}", serviceName } | ||
}; | ||
|
||
svcShContent = tokensToReplace.Aggregate( | ||
svcShContent, | ||
(current, item) => current.Replace(item.Key, item.Value)); | ||
|
||
File.WriteAllText(svcShPath, svcShContent, new UTF8Encoding(false)); | ||
|
||
var unixUtil = HostContext.CreateService<IUnixUtil>(); | ||
unixUtil.ChmodAsync("755", svcShPath).GetAwaiter().GetResult(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Trace.Error(ex); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.