Skip to content

Commit f2bbe1e

Browse files
committed
Added code to uninstall tentacle on stop
1 parent 7531576 commit f2bbe1e

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
c:\Install\Tentacle\Tentacle.exe service --instance "Tentacle" --stop --uninstall --console
2+
c:\Install\Tentacle\Tentacle.exe delete-instance --instance "Tentacle" --console
3+
msiexec /uninstall "c:\InstallOctopus.Tentacle.msi" /quiet

AzureWebFarm.OctopusDeploy.Tests/Infrastructure/OctopusDeployTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ public void WhenConfiguringTentacle_ThenTheCorrectCommandsShouldBeSentToTentacle
4747
Approvals.Verify(b.ToString());
4848
}
4949

50+
[Fact]
51+
[UseReporter(typeof(DiffReporter))]
52+
[MethodImpl(MethodImplOptions.NoInlining)]
53+
public void WhenUninstallingTentacle_ThenTheCorrectCommandsShouldBeSentToTentacleExe()
54+
{
55+
var b = new StringBuilder();
56+
_container.Resolve<IProcessRunner>().WhenForAnyArgs(r => r.Run(null, null)).Do(a => b.AppendLine(string.Format("{0} {1}", a[0], a[1])));
57+
58+
_sut.UninstallTentacle();
59+
60+
Approvals.Verify(b.ToString());
61+
}
62+
5063
[Fact]
5164
public void WhenDeletingMachine_ThenDeleteTheMachineFromOctopusServer()
5265
{

AzureWebFarm.OctopusDeploy/Infrastructure/OctopusDeploy.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,34 @@ namespace AzureWebFarm.OctopusDeploy.Infrastructure
1313
{
1414
internal class OctopusDeploy
1515
{
16+
private const string InstanceArg = "--instance \"Tentacle\"";
1617
private readonly string _machineName;
1718
private readonly ConfigSettings _config;
1819
private readonly IProcessRunner _processRunner;
1920
private readonly IOctopusRepository _repository;
21+
private readonly string _tentaclePath;
22+
private readonly string _tentacleInstallPath;
2023

2124
public OctopusDeploy(string machineName, ConfigSettings config, IOctopusRepository repository, IProcessRunner processRunner)
2225
{
2326
_machineName = machineName;
2427
_config = config;
2528
_processRunner = processRunner;
2629
_repository = repository;
30+
_tentacleInstallPath = _config.TentacleInstallPath;
31+
_tentaclePath = Path.Combine(_tentacleInstallPath, "Tentacle", "Tentacle.exe");
2732
}
2833

2934
public void ConfigureTentacle()
3035
{
31-
const string instanceArg = "--instance \"Tentacle\"";
3236
var tentacleDeploymentsPath = _config.TentacleDeploymentsPath;
33-
var tentacleInstallPath = _config.TentacleInstallPath;
34-
var tentacleDir = Path.Combine(tentacleInstallPath, "Tentacle");
35-
var tentaclePath = Path.Combine(tentacleDir, "Tentacle.exe");
3637

37-
_processRunner.Run(tentaclePath, string.Format("create-instance {0} --config \"{1}\" --console", instanceArg, Path.Combine(tentacleInstallPath, "Tentacle.config")));
38-
_processRunner.Run(tentaclePath, string.Format("new-certificate {0} --console", instanceArg));
39-
_processRunner.Run(tentaclePath, string.Format("configure {0} --home \"{1}\" --console", instanceArg, tentacleDeploymentsPath.Substring(0, tentacleDeploymentsPath.Length - 1)));
40-
_processRunner.Run(tentaclePath, string.Format("configure {0} --app \"{1}\" --console", instanceArg, Path.Combine(tentacleDeploymentsPath, "Applications")));
41-
_processRunner.Run(tentaclePath, string.Format("register-with {0} --server \"{1}\" --environment \"{2}\" --role \"{3}\" --apiKey \"{4}\" --name \"{5}\" --comms-style TentacleActive --force --console", instanceArg, _config.OctopusServer, _config.TentacleEnvironment, _config.TentacleRole, _config.OctopusApiKey, _machineName));
42-
_processRunner.Run(tentaclePath, string.Format("service {0} --install --start --console", instanceArg));
38+
_processRunner.Run(_tentaclePath, string.Format("create-instance {0} --config \"{1}\" --console", InstanceArg, Path.Combine(_tentacleInstallPath, "Tentacle.config")));
39+
_processRunner.Run(_tentaclePath, string.Format("new-certificate {0} --console", InstanceArg));
40+
_processRunner.Run(_tentaclePath, string.Format("configure {0} --home \"{1}\" --console", InstanceArg, tentacleDeploymentsPath.Substring(0, tentacleDeploymentsPath.Length - 1)));
41+
_processRunner.Run(_tentaclePath, string.Format("configure {0} --app \"{1}\" --console", InstanceArg, Path.Combine(tentacleDeploymentsPath, "Applications")));
42+
_processRunner.Run(_tentaclePath, string.Format("register-with {0} --server \"{1}\" --environment \"{2}\" --role \"{3}\" --apiKey \"{4}\" --name \"{5}\" --comms-style TentacleActive --force --console", InstanceArg, _config.OctopusServer, _config.TentacleEnvironment, _config.TentacleRole, _config.OctopusApiKey, _machineName));
43+
_processRunner.Run(_tentaclePath, string.Format("service {0} --install --start --console", InstanceArg));
4344
}
4445

4546
public void DeleteMachine()
@@ -99,5 +100,12 @@ public static IOctopusRepository GetRepository(ConfigSettings config)
99100
{
100101
return new OctopusRepository(new OctopusServerEndpoint(config.OctopusServer, config.OctopusApiKey));
101102
}
103+
104+
public void UninstallTentacle()
105+
{
106+
_processRunner.Run(_tentaclePath, string.Format("service {0} --stop --uninstall --console", InstanceArg));
107+
_processRunner.Run(_tentaclePath, string.Format("delete-instance {0} --console", InstanceArg));
108+
_processRunner.Run("msiexec", string.Format("/uninstall \"{0}{1}\" /quiet", _tentacleInstallPath, "Octopus.Tentacle.msi"));
109+
}
102110
}
103111
}

AzureWebFarm.OctopusDeploy/WebFarmRole.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void Run()
7474
/// </summary>
7575
public void OnStop()
7676
{
77+
_octopusDeploy.UninstallTentacle();
7778
_octopusDeploy.DeleteMachine();
7879
IisEnvironment.WaitForAllHttpRequestsToEnd();
7980
}

0 commit comments

Comments
 (0)