From 6e0f1bacb0dc7452af28c0e4263af6453f087a1d Mon Sep 17 00:00:00 2001 From: Stan Iliev Date: Thu, 28 Apr 2016 18:01:07 -0400 Subject: [PATCH] Store the PATH enviroment variable during config and pass it to the linux service process. Tested change on Ubuntu 16.04 --- .../Configuration/LinuxServiceControlManager.cs | 11 ++++++----- src/Misc/layoutbin/vsts.agent.service.template | 10 +++++----- .../Configuration/LinuxServiceControlManagerL0.cs | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Agent.Listener/Configuration/LinuxServiceControlManager.cs b/src/Agent.Listener/Configuration/LinuxServiceControlManager.cs index 37bec1eebf..b4d314b902 100644 --- a/src/Agent.Listener/Configuration/LinuxServiceControlManager.cs +++ b/src/Agent.Listener/Configuration/LinuxServiceControlManager.cs @@ -50,11 +50,12 @@ public override bool ConfigureService( var unitContent = File.ReadAllText(Path.Combine(IOUtil.GetBinPath(), VstsAgentServiceTemplate)); var tokensToReplace = new Dictionary { - { "{Description}", settings.ServiceDisplayName }, - { "{BinDirectory}", IOUtil.GetBinPath() }, - { "{AgentRoot}", IOUtil.GetRootPath() }, - { "{ExternalsDirectory}", IOUtil.GetExternalsPath() }, - { "{User}", GetCurrentLoginName() } + { "{{Description}}", settings.ServiceDisplayName }, + { "{{BinDirectory}}", IOUtil.GetBinPath() }, + { "{{AgentRoot}}", IOUtil.GetRootPath() }, + { "{{ExternalsDirectory}}", IOUtil.GetExternalsPath() }, + { "{{User}}", GetCurrentLoginName() }, + { "{{Path}}", Environment.GetEnvironmentVariable("PATH") } }; unitContent = tokensToReplace.Aggregate( diff --git a/src/Misc/layoutbin/vsts.agent.service.template b/src/Misc/layoutbin/vsts.agent.service.template index beb27adb8b..b3b5e70e6e 100644 --- a/src/Misc/layoutbin/vsts.agent.service.template +++ b/src/Misc/layoutbin/vsts.agent.service.template @@ -1,13 +1,13 @@ [Unit] -Description={Description} +Description={{Description}} After=network.target [Service] -ExecStart={ExternalsDirectory}/node/bin/node {BinDirectory}/AgentService.js -User={User} -Environment=PATH=/usr/bin:/usr/local/bin +ExecStart={{ExternalsDirectory}}/node/bin/node {{BinDirectory}}/AgentService.js +User={{User}} +Environment=PATH={{Path}} Environment=NODE_ENV=production -WorkingDirectory={AgentRoot} +WorkingDirectory={{AgentRoot}} [Install] WantedBy=multi-user.target diff --git a/src/Test/L0/Listener/Configuration/LinuxServiceControlManagerL0.cs b/src/Test/L0/Listener/Configuration/LinuxServiceControlManagerL0.cs index ea1382bb62..c4ff248342 100644 --- a/src/Test/L0/Listener/Configuration/LinuxServiceControlManagerL0.cs +++ b/src/Test/L0/Listener/Configuration/LinuxServiceControlManagerL0.cs @@ -108,13 +108,13 @@ public void VerifyLinuxServiceConfigurationFileContent() [Service] ExecStart={0}/node/bin/node {1}/AgentService.js User={3} -Environment=PATH=/usr/bin:/usr/local/bin +Environment=PATH={4} Environment=NODE_ENV=production WorkingDirectory={2} [Install] WantedBy=multi-user.target -", IOUtil.GetExternalsPath(), IOUtil.GetBinPath(), IOUtil.GetRootPath(), testUser); +", IOUtil.GetExternalsPath(), IOUtil.GetBinPath(), IOUtil.GetRootPath(), testUser, Environment.GetEnvironmentVariable("PATH")); var agentSettings = new AgentSettings {