Skip to content

Commit

Permalink
Add service configuration resource
Browse files Browse the repository at this point in the history
- Adds way to start or stop service at start
  • Loading branch information
brentm5 committed Apr 1, 2016
1 parent d6bee75 commit b66139a
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Berksfile.lock
.kitchen/
.kitchen.local.yml
vendor/
.rubocop-http*
5 changes: 1 addition & 4 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ provisioner:
audit_mode: :enabled

platforms:
- name: windows-2008R2
driver:
box: windows-2008r2-net451
gui: false
- name: windows-2008R2-cvent

suites:
- name: server
Expand Down
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
inherit_from: .rubocop_todo.yml
inherit_from:
- https://raw.githubusercontent.com/cvent/rubocop-rules-chef/master/rubocop.yml
Metrics/LineLength:
Max: 160
8 changes: 8 additions & 0 deletions libraries/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def display_name
'Octopus Deploy Server'
end

def service_name
'OctopusDeploy'
end

def server_install_location
'C:\Program Files\Octopus Deploy\Octopus'
end

def installer_url(version)
"https://download.octopusdeploy.com/octopus/Octopus.#{version}-x64.msi"
end
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
source_url 'https://github.com/cvent/octopus-deploy-cookbook'
issues_url 'https://github.com/cvent/octopus-deploy-cookbook/issues'
version '0.4.8'
version '0.5.0'

depends 'windows', '~> 1.38'
supports 'windows'
Expand Down
73 changes: 73 additions & 0 deletions providers/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# limitations under the License.
#

include OctopusDeploy::Shared
include OctopusDeploy::Server

use_inline_resources
Expand Down Expand Up @@ -50,6 +51,78 @@
new_resource.updated_by_last_action(download.updated_by_last_action? || install.updated_by_last_action?)
end

action :configure do
new_resource = @new_resource
name = new_resource.name
instance = new_resource.instance
checksum = new_resource.checksum
version = new_resource.version
home_path = new_resource.home_path
config_path = new_resource.config_path
connection_string = new_resource.connection_string
node_name = new_resource.node_name
admin_user = new_resource.admin_user
license = new_resource.license
create_database = new_resource.create_database
start_service = new_resource.start_service

install = octopus_deploy_server name do
action :install
checksum checksum
version version
end

create_instance = powershell_script "create-instance-#{instance}" do
action :run
cwd server_install_location
code <<-EOH
.\\Octopus.Server.exe create-instance --instance "#{instance}" --config "#{config_path}" --console
#{catch_powershell_error('Creating instance')}
EOH
not_if { ::File.exist?(config_path) }
end

configure = powershell_script "configure-server-#{instance}" do # ~FC009
action :run
cwd server_install_location
code <<-EOH
.\\Octopus.Server.exe configure --instance "#{instance}" --home "#{home_path}" --console
#{catch_powershell_error('Configuring Home Dir')}
.\\Octopus.Server.exe configure --instance "#{instance}" --storageConnectionString "#{connection_string}" --console
#{catch_powershell_error('Configuring Database Connection')}
.\\Octopus.Server.exe configure --instance "#{instance}" --upgradeCheck "True" --upgradeCheckWithStatistics "True" --console
#{catch_powershell_error('Configuring Upgrade Checks')}
.\\Octopus.Server.exe configure --instance "#{instance}" --webAuthenticationMode "Domain" --console
#{catch_powershell_error('Configuring authentication')}
.\\Octopus.Server.exe configure --instance "#{instance}" --serverNodeName "#{node_name}" --console
#{catch_powershell_error('Configuring Cluster Node Name')}
.\\Octopus.Server.exe configure --instance "#{instance}" --webForceSSL "False" --webListenPrefixes "http://localhost:80/" --commsListenPort "10943" --console
#{catch_powershell_error('Configuring Listen Ports')}
#{".\\Octopus.Server.exe database --instance \"#{instance}\" --create --console #{catch_powershell_error('Create Database')}" if create_database}
.\\Octopus.Server.exe service --instance "#{instance}" --stop --console
#{catch_powershell_error('Stop Service')}
#{".\\Octopus.Server.exe admin --instance \"#{instance}\" --username \"#{admin_user}\" --console #{catch_powershell_error('Set administrator')}" if admin_user}
#{".\\Octopus.Server.exe license --instance \"#{instance}\" --licenseBase64 \"#{Base64.encode64(license)}\"--console #{catch_powershell_error('Configuring License')}" if license}
.\\Octopus.Server.exe service --instance "#{instance}" --install --reconfigure --console
#{catch_powershell_error('Create Service')}
EOH
sensitive true
notifies :restart, "windows_service[#{service_name}]", :delayed
not_if { ::Win32::Service.exists?(service_name) }
end

# Make sure enabled and started
service = windows_service service_name do
if start_service
action [:enable, :start]
else
action [:stop, :disable]
end
end

new_resource.updated_by_last_action(actions_updated?([install, create_instance, configure, service]))
end

action :remove do
new_resource = @new_resource
version = new_resource.version
Expand Down
12 changes: 10 additions & 2 deletions resources/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@
# limitations under the License.
#

actions :install, :remove
actions :install, :configure, :remove
default_action :install

attribute :instance, kind_of: String, name_attribute: true
attribute :instance, kind_of: String, default: 'OctopusServer'
attribute :version, kind_of: String, required: true
attribute :checksum, kind_of: String
attribute :home_path, kind_of: String, default: 'C:\Octopus'
attribute :config_path, kind_of: String, default: 'C:\Octopus\OctopusServer.config'
attribute :connection_string, kind_of: String
attribute :node_name, kind_of: String
attribute :create_database, kind_of: [TrueClass, FalseClass], default: false
attribute :admin_user, kind_of: String
attribute :license, kind_of: String
attribute :start_service, kind_of: [TrueClass, FalseClass], default: true
14 changes: 14 additions & 0 deletions test/cookbooks/verify-octo/recipes/audit_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@
expect(file('C:\Program Files\Octopus Deploy\Octopus\Octopus.Server.exe')).to be_version(install_version)
end
end

control 'Octopus Deploy Server Configuration' do
it 'should have configured the service' do
expect(service('OctopusDeploy')).to be_installed
end

it 'should have enabled the service' do
expect(service('OctopusDeploy')).to be_enabled
end

it 'should have created the configuration file' do
expect(file('C:\Octopus\OctopusServer.config')).to be_file
end
end
end
4 changes: 3 additions & 1 deletion test/cookbooks/verify-octo/recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
end

octopus_deploy_server 'OctopusServer' do
action :install
action :configure
version node['verify-octo']['server']['version']
checksum node['verify-octo']['server']['checksum']
node_name 'octo-web-01'
connection_string 'Data Source=localhostdba;Initial Catalog=octo;Integrated Security=False;User ID=octo;Password=password'
end

include_recipe 'verify-octo::audit_server'

0 comments on commit b66139a

Please sign in to comment.