Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows2012 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions containers/couchbase/Windows2012/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM microsoft/windowsservercore

RUN powershell -Command \
Invoke-WebRequest -Method Get \
-Uri http://packages.couchbase.com/releases/4.5.1-Win10DP/couchbase-server-enterprise_4.5.1-Win10DP-windows_amd64.exe \
-OutFile c:\couchbase.exe

COPY install.iss C:/

RUN C:\Couchbase.exe /s /f1"C:\install.iss"

RUN dir "C:\Program Files\Couchbase\Server"

COPY wait-service.ps1 C:/
CMD powershell.exe -file c:\Wait-Service.ps1 -ServiceName CouchbaseServer -AllowServiceRestart
20 changes: 20 additions & 0 deletions containers/couchbase/Windows2012/install.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[{B457D40B-E596-E1D4-417A-4DD6219B64B0}-DlgOrder]
Dlg0={B457D40B-E596-E1D4-417A-4DD6219B64B0}-SdWelcome-0
Count=5
Dlg1={B457D40B-E596-E1D4-417A-4DD6219B64B0}-SdAskDestPath-0
Dlg2={B457D40B-E596-E1D4-417A-4DD6219B64B0}-SdStartCopy2-0
Dlg3={B457D40B-E596-E1D4-417A-4DD6219B64B0}-MessageBox-0
Dlg4={B457D40B-E596-E1D4-417A-4DD6219B64B0}-SdFinish-0
[{B457D40B-E596-E1D4-417A-4DD6219B64B0}-SdWelcome-0]
Result=1
[{B457D40B-E596-E1D4-417A-4DD6219B64B0}-SdAskDestPath-0]
szDir=C:\Program Files\Couchbase\Server\
Result=1
[{B457D40B-E596-E1D4-417A-4DD6219B64B0}-SdStartCopy2-0]
Result=1
[{B457D40B-E596-E1D4-417A-4DD6219B64B0}-MessageBox-0]
Result=1
[{B457D40B-E596-E1D4-417A-4DD6219B64B0}-SdFinish-0]
Result=1
bOpt1=0
bOpt2=0
157 changes: 157 additions & 0 deletions containers/couchbase/Windows2012/wait-service.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<#
.NOTES
Copyright (c) Microsoft Corporation. All rights reserved.

.SYNOPSIS
Waits for a service to stop.

.DESCRIPTION
Finds the service specified by name, waits the specified amount of time for the service to start and then waits for the service to exit.
Upon exit the return code of the service will be the return code of the cmdlet.
If AllowServiceRestarts is true if the service is restarted the script automatically re-executes.

.PARAMETER ServiceName
The name of the service to wait for.

.PARAMETER StartupTimeout
The amount of time in seconds to wait for the service to start after initating the script. Default is 10sec.

.PARAMETER AllowServiceRestart
Automtically restart the wait process when the service exits looping for the StartupTimeout again.

.EXAMPLE
.\Wait-Service.ps1 -ServiceName W3SVC
#>

[CmdletBinding()]
param(
#The name of the service to wait for.
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]
$ServiceName,

#The amount of time in seconds to wait for the service to start after initating the script. Default is 10sec.
[ValidateNotNullOrEmpty()]
[int]
$StartupTimeout = 10,

#Automtically restart the wait process when the service exits looping for the StartupTimeout again.
[switch]
$AllowServiceRestart
)


function Wait-Service()
{
[CmdletBinding()]
param(
#The name of the service to wait for.
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]
$ServiceName,

#The amount of time in seconds to wait for the service to start after initating the script. Default is 10sec.
[ValidateNotNullOrEmpty()]
[int]
$StartupTimeout = 10,

#Automtically restart the wait process when the service exits looping for the StartupTimeout again.
[switch]
$AllowServiceRestart
)
#Allow Service Restart
do
{
#Importing the System.ServiceProcess Assembly
Add-Type -AssemblyName System.ServiceProcess -ErrorAction SilentlyContinue

#Adding a PInvoke call for QueryServiceStatus which is used to get the error return.
# https://github.com/dotnet/corefx/blob/master/src/Common/src/Interop/Windows/mincore/Interop.ENUM_SERVICE_STATUS.cs
# https://github.com/dotnet/corefx/blob/master/src/Common/src/Interop/Windows/mincore/Interop.QueryServiceStatus.cs
Add-Type -Name Advapi32 -Namespace Interop -PassThru -MemberDefinition @'
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms685996(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
public struct SERVICE_STATUS
{
public int serviceType;
public int currentState;
public int controlsAccepted;
public int win32ExitCode;
public int serviceSpecificExitCode;
public int checkPoint;
public int waitHint;
}

[DllImport("api-ms-win-service-winsvc-l1-1-0.dll", CharSet = CharSet.Unicode, SetLastError=true)]
public static extern bool QueryServiceStatus(
System.Runtime.InteropServices.SafeHandle serviceHandle,
out SERVICE_STATUS pStatus);
'@ | Out-Null


$ServiceProcess = New-Object System.ServiceProcess.ServiceController($ServiceName)

if ($ServiceProcess -eq $null)
{
throw "The specified service does not exist or can not be found."
}
#Startup timeout block
try
{
$ServiceProcess.WaitForStatus(
[System.ServiceProcess.ServiceControllerStatus]::Running,
[System.TimeSpan]::FromSeconds($StartupTimeout))
}
catch [System.ServiceProcess.TimeoutException]
{
$exception = New-Object System.TimeoutException(
[System.String]::Format(
"The Service '{0}' did not enter the 'Running' state within the {1} sec timeout.",
$ServiceName, $StartupTimeout),
$_.Exception
)
throw $exception
}

#Service is in the Running State. In a sleep loop waiting for service to stop.
Write-Host (
[System.String]::Format("The Service '{0}' is in the 'Running' state.", $ServiceName))

do {
Start-Sleep -Milliseconds 100
$ServiceProcess.Refresh()
}
while ($ServiceProcess.Status -eq [System.ServiceProcess.ServiceControllerStatus]::Running)

#Stop/Error State
$serviceStatus = New-Object Interop.Advapi32+SERVICE_STATUS
[Interop.Advapi32]::QueryServiceStatus($ServiceProcess.ServiceHandle, [ref] $serviceStatus) |Out-Null

$logString = [System.String]::Format(
"The Service '{0}' has stopped. The service control manager reported it's Exit Status as {1}",
$ServiceName, $serviceStatus.win32ExitCode)

if ($serviceStatus.win32ExitCode -ne 0)
{
Write-Error $logString
}
else
{
Write-Host $logString
}
}
while ($AllowServiceRestart)

return $serviceStatus.win32ExitCode
}

if ($AllowServiceRestart)
{
Wait-Service -ServiceName $ServiceName -StartupTimeout $StartupTimeout -AllowServiceRestart
}
else
{
Wait-Service -ServiceName $ServiceName -StartupTimeout $StartupTimeout
}
7 changes: 7 additions & 0 deletions lib/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const ( // iota is reset to 0

const UBUNTU_OS_DIR = "Ubuntu14"
const CENTOS_OS_DIR = "CentOS7"
const WINDOWS_OS_DIR = "Windows2012"
const DEFAULT_DOCKER_PROVIDER_CONF = "providers/docker/options.yml"

type Provider interface {
Expand Down Expand Up @@ -346,6 +347,9 @@ func (p *DockerProvider) ProvideCouchbaseServers(filename *string, servers []Ser
if p.Opts.OS == "centos7" {
osPath = CENTOS_OS_DIR
}
if p.Opts.OS == "windows2012" {
osPath = WINDOWS_OS_DIR
}
var imgName = fmt.Sprintf("couchbase_%s.%s",
build,
strings.ToLower(osPath))
Expand Down Expand Up @@ -540,6 +544,9 @@ func (p *SwarmProvider) ProvideCouchbaseServer(serverName string, portOffset int
if p.Opts.OS == "centos7" {
osPath = CENTOS_OS_DIR
}
if p.Opts.OS == "windows2012" {
osPath = WINDOWS_OS_DIR
}
var imgName = fmt.Sprintf("couchbase_%s.%s",
build,
strings.ToLower(osPath))
Expand Down
2 changes: 1 addition & 1 deletion providers/docker/options.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# container os, supported values = ubuntu14, centos7
# container os, supported values = ubuntu14, centos7, windows2012
os: centos7

# build version
Expand Down