Permalink
Browse files

Working on Rehab, an automatic service updater for Topshelf

  • Loading branch information...
phatboyg committed Aug 26, 2012
1 parent aff3fef commit ab002ec73e0785e2f945a6356ad512767fd175cc
View
@@ -1,5 +1,5 @@
---
-:patch: 0
+:patch: 1
:special: ""
:major: 3
:minor: 0
View
@@ -57,13 +57,15 @@
task :copy35 => [:build35] do
copyOutputFiles File.join(props[:src], "Topshelf/bin/Release/v3.5"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
copyOutputFiles File.join(props[:src], "Topshelf.Log4Net/bin/Release/v3.5"), "Topshelf.Log4Net.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
- copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release/v3.5"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
+ copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release/v3.5"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
+ copyOutputFiles File.join(props[:src], "Topshelf.Rehab/bin/Release/v3.5"), "Topshelf.Rehab.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
end
task :copy4 => [:build4] do
copyOutputFiles File.join(props[:src], "Topshelf/bin/Release"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
copyOutputFiles File.join(props[:src], "Topshelf.Log4Net/bin/Release"), "Topshelf.Log4Net.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
- copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
+ copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
+ copyOutputFiles File.join(props[:src], "Topshelf.Rehab/bin/Release"), "Topshelf.Rehab.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
end
desc "Only compiles the application."
@@ -126,7 +128,8 @@ def copyOutputFiles(fromDir, filePattern, outDir)
task :nuget => [:versioning, :create_nuspec] do
sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.Log4Net.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
- sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.NLog.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
+ sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.NLog.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
+ sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.Rehab.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
end
nuspec :create_nuspec do |nuspec|
@@ -184,6 +187,24 @@ def copyOutputFiles(fromDir, filePattern, outDir)
nuspec.file(File.join(props[:src], "Topshelf.NLog\\**\\*.cs").gsub("/","\\"), "src")
end
+nuspec :create_nuspec do |nuspec|
+ nuspec.id = 'Topshelf.Rehab'
+ nuspec.version = NUGET_VERSION
+ nuspec.authors = 'Chris Patterson, Dru Sellers, Travis Smith'
+ nuspec.summary = 'Topshelf, Friction-free Windows Services'
+ nuspec.description = 'Rehab provides automatic updates to services. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
+ nuspec.title = 'Topshelf.Rehab'
+ nuspec.projectUrl = 'http://github.com/Topshelf/Topshelf'
+ nuspec.iconUrl = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
+ nuspec.language = "en-US"
+ nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
+ nuspec.requireLicenseAcceptance = "false"
+ nuspec.dependency "Topshelf", NUGET_VERSION
+ nuspec.output_file = File.join(props[:artifacts], 'Topshelf.Rehab.nuspec')
+ add_files props[:output], 'Topshelf.Rehab.{dll,pdb,xml}', nuspec
+ nuspec.file(File.join(props[:src], "Topshelf.Rehab\\**\\*.cs").gsub("/","\\"), "src")
+end
+
def project_outputs(props)
props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.dll" }.
concat( props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.exe" } ).
@@ -0,0 +1,27 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+// this file except in compliance with the License. You may obtain a copy of the
+// License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software distributed
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations under the License.
+namespace SampleTopshelfUpdaterService
+{
+ using Topshelf;
+
+ class Program
+ {
+ static void Main()
+ {
+ HostFactory.Run(x =>
+ {
+ x.RehabService<SampleService>();
+ });
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("SampleTopshelfUpdaterService")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("SampleTopshelfUpdaterService")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("83633c39-76dc-4f56-89e7-cd8f46ed7ed3")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,67 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+// this file except in compliance with the License. You may obtain a copy of the
+// License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software distributed
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations under the License.
+namespace SampleTopshelfUpdaterService
+{
+ using System;
+ using System.Threading;
+ using Topshelf;
+ using Topshelf.Logging;
+
+ class SampleService :
+ ServiceControl
+ {
+ static readonly LogWriter _log = HostLogger.Get<SampleService>();
+
+ public bool Start(HostControl hostControl)
+ {
+ _log.Info("SampleService Starting...");
+
+ hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(10));
+
+ Thread.Sleep(1000);
+
+ ThreadPool.QueueUserWorkItem(x =>
+ {
+ Thread.Sleep(3000);
+
+ _log.Info("Requesting stop");
+
+ hostControl.Stop();
+ });
+ _log.Info("SampleService Started");
+
+ return true;
+ }
+
+ public bool Stop(HostControl hostControl)
+ {
+ _log.Info("SampleService Stopped");
+
+ return true;
+ }
+
+ public bool Pause(HostControl hostControl)
+ {
+ _log.Info("SampleService Paused");
+
+ return true;
+ }
+
+ public bool Continue(HostControl hostControl)
+ {
+ _log.Info("SampleService Continued");
+
+ return true;
+ }
+ }
+}
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{C4838A12-9DFE-4CAE-894A-9845898AFDB2}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SampleTopshelfUpdaterService</RootNamespace>
+ <AssemblyName>SampleTopshelfUpdaterService</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Data" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="SampleService.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Topshelf.Rehab\Topshelf.Rehab.csproj">
+ <Project>{26B9ADA3-4CF1-423C-B1FB-A5F982876E39}</Project>
+ <Name>Topshelf.Rehab</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Topshelf\Topshelf.csproj">
+ <Project>{A52AD64D-6455-4A22-8CCF-581851086578}</Project>
+ <Name>Topshelf</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
@@ -9,5 +9,5 @@
[assembly: ComVisibleAttribute(false)]
[assembly: CLSCompliantAttribute(true)]
-[assembly: AssemblyInformationalVersion("3.0.0.0c3f56")]
+[assembly: AssemblyInformationalVersion("3.0.0.aff3fe")]
@@ -0,0 +1,43 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+// this file except in compliance with the License. You may obtain a copy of the
+// License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software distributed
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations under the License.
+namespace Topshelf.Rehab
+{
+ using System;
+
+ public class AppDomainHostControl :
+ MarshalByRefObject,
+ HostControl
+ {
+ readonly HostControl _hostControl;
+
+ public AppDomainHostControl(HostControl hostControl)
+ {
+ _hostControl = hostControl;
+ }
+
+ public void RequestAdditionalTime(TimeSpan timeRemaining)
+ {
+ _hostControl.RequestAdditionalTime(timeRemaining);
+ }
+
+ public void Stop()
+ {
+ _hostControl.Stop();
+ }
+
+ public void Restart()
+ {
+ _hostControl.Restart();
+ }
+ }
+}
@@ -0,0 +1,58 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+// this file except in compliance with the License. You may obtain a copy of the
+// License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software distributed
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations under the License.
+namespace Topshelf.Rehab
+{
+ using System;
+ using Topshelf.Builders;
+ using Topshelf.HostConfigurators;
+ using Topshelf.Runtime;
+
+ public class AppDomainServiceHandle :
+ MarshalByRefObject,
+ ServiceHandle
+ {
+ ServiceHandle _serviceHandle;
+
+ public bool Start(HostControl hostControl)
+ {
+ return _serviceHandle.Start(hostControl);
+ }
+
+ public bool Stop(HostControl hostControl)
+ {
+ return _serviceHandle.Stop(hostControl);
+ }
+
+ public bool Pause(HostControl hostControl)
+ {
+ return _serviceHandle.Pause(hostControl);
+ }
+
+ public bool Continue(HostControl hostControl)
+ {
+ return _serviceHandle.Continue(hostControl);
+ }
+
+ public void Dispose()
+ {
+ _serviceHandle.Dispose();
+ }
+
+ public void Create(ServiceBuilderFactory serviceBuilderFactory, HostSettings settings)
+ {
+ ServiceBuilder serviceBuilder = serviceBuilderFactory(settings);
+
+ _serviceHandle = serviceBuilder.Build(settings);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit ab002ec

Please sign in to comment.