Skip to content

Commit dcdecc7

Browse files
committed
Merge pull request #20 from morganjohnston/master
Added some text around deploying windows servies
2 parents 5e7cf10 + a9d44ae commit dcdecc7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,47 @@ Apart from adding the dependencies of the package and the dll the following acti
145145

146146
To see how we perform all of this "magic" checkout the [install.ps1](https://github.com/MRCollective/AzureWebFarm.OctopusDeploy/blob/master/AzureWebFarm.OctopusDeploy/Tools/install.ps1) file.
147147

148+
What if I want to deploy Windows Services?
149+
------------------------------------------
150+
You can deploy and host a non IIS based Windows Service in an Azure role using almost exactly the same approach as above for a standard web role with a few small modifications.
151+
* To your service project
152+
* Ensure that your service startup type is set to "Manual" and not "Automatic". Otherwise your service will start before Octopus and Azure can work their magic.
153+
154+
* To your cloud project
155+
* Open WebRole.cs and in the OnStop() method before anything else is called add some logic to ensure the service is stopped.
156+
```C#
157+
public override void OnStop()
158+
{
159+
StopService("Your Service Name");
160+
_webFarmRole.OnStop();
161+
}
162+
163+
private void StopService(string serviceName)
164+
{
165+
Log.Information("{serviceName} OnStop called", serviceName);
166+
try
167+
{
168+
var serviceController = new ServiceController(serviceName);
169+
Log.Information("{serviceName} current status is {serviceStatus}", serviceName, serviceController.Status);
170+
if (serviceController.Status == ServiceControllerStatus.Stopped)
171+
{
172+
Log.Warning("{serviceName} was already stopped. Nothing more to do", serviceName);
173+
}
174+
else
175+
{
176+
Log.Information("Attempting to stop {serviceName}", serviceName);
177+
serviceController.Stop();
178+
Log.Information("{serviceName} was successfully stopped", serviceName);
179+
}
180+
}
181+
catch (Exception ex)
182+
{
183+
Log.Fatal(ex, "Error occurred while attempting to stop {serviceName}", serviceName);
184+
throw;
185+
}
186+
}
187+
```
188+
148189
What if I want to deploy non-.NET applications?
149190
-----------------------------------------------
150191

0 commit comments

Comments
 (0)