3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using System . Threading ;
6
+ using Microsoft . Win32 ;
6
7
using Microsoft . WindowsAzure . ServiceRuntime ;
7
8
using Octopus . Client ;
8
9
using Octopus . Client . Model ;
@@ -13,33 +14,36 @@ namespace AzureWebFarm.OctopusDeploy.Infrastructure
13
14
{
14
15
internal class OctopusDeploy
15
16
{
17
+ private const string InstanceArg = "--instance \" Tentacle\" " ;
16
18
private readonly string _machineName ;
17
19
private readonly ConfigSettings _config ;
18
20
private readonly IProcessRunner _processRunner ;
21
+ private readonly IRegistryEditor _registryEditor ;
19
22
private readonly IOctopusRepository _repository ;
23
+ private readonly string _tentaclePath ;
24
+ private readonly string _tentacleInstallPath ;
20
25
21
- public OctopusDeploy ( string machineName , ConfigSettings config , IOctopusRepository repository , IProcessRunner processRunner )
26
+ public OctopusDeploy ( string machineName , ConfigSettings config , IOctopusRepository repository , IProcessRunner processRunner , IRegistryEditor registryEditor )
22
27
{
23
28
_machineName = machineName ;
24
29
_config = config ;
25
30
_processRunner = processRunner ;
31
+ _registryEditor = registryEditor ;
26
32
_repository = repository ;
33
+ _tentacleInstallPath = _config . TentacleInstallPath ;
34
+ _tentaclePath = Path . Combine ( _tentacleInstallPath , "Tentacle" , "Tentacle.exe" ) ;
27
35
}
28
36
29
37
public void ConfigureTentacle ( )
30
38
{
31
- const string instanceArg = "--instance \" Tentacle\" " ;
32
39
var tentacleDeploymentsPath = _config . TentacleDeploymentsPath ;
33
- var tentacleInstallPath = _config . TentacleInstallPath ;
34
- var tentacleDir = Path . Combine ( tentacleInstallPath , "Tentacle" ) ;
35
- var tentaclePath = Path . Combine ( tentacleDir , "Tentacle.exe" ) ;
36
40
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 ) ) ;
41
+ _processRunner . Run ( _tentaclePath , string . Format ( "create-instance {0} --config \" {1}\" --console" , InstanceArg , Path . Combine ( _tentacleInstallPath , "Tentacle.config" ) ) ) ;
42
+ _processRunner . Run ( _tentaclePath , string . Format ( "new-certificate {0} --console" , InstanceArg ) ) ;
43
+ _processRunner . Run ( _tentaclePath , string . Format ( "configure {0} --home \" {1}\" --console" , InstanceArg , tentacleDeploymentsPath . Substring ( 0 , tentacleDeploymentsPath . Length - 1 ) ) ) ;
44
+ _processRunner . Run ( _tentaclePath , string . Format ( "configure {0} --app \" {1}\" --console" , InstanceArg , Path . Combine ( tentacleDeploymentsPath , "Applications" ) ) ) ;
45
+ _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 ) ) ;
46
+ _processRunner . Run ( _tentaclePath , string . Format ( "service {0} --install --start --console" , InstanceArg ) ) ;
43
47
}
44
48
45
49
public void DeleteMachine ( )
@@ -99,5 +103,13 @@ public static IOctopusRepository GetRepository(ConfigSettings config)
99
103
{
100
104
return new OctopusRepository ( new OctopusServerEndpoint ( config . OctopusServer , config . OctopusApiKey ) ) ;
101
105
}
106
+
107
+ public void UninstallTentacle ( )
108
+ {
109
+ _processRunner . Run ( _tentaclePath , string . Format ( "service {0} --stop --uninstall --console" , InstanceArg ) ) ;
110
+ _processRunner . Run ( _tentaclePath , string . Format ( "delete-instance {0} --console" , InstanceArg ) ) ;
111
+ _processRunner . Run ( "msiexec" , string . Format ( "/uninstall \" {0}{1}\" /quiet" , _tentacleInstallPath , "Octopus.Tentacle.msi" ) ) ;
112
+ _registryEditor . DeleteLocalMachineTree ( "Software" , "Octopus" ) ;
113
+ }
102
114
}
103
115
}
0 commit comments