Skip to content

Commit

Permalink
Merge pull request #110 from chef-partners/rhass/timeout-debug
Browse files Browse the repository at this point in the history
Fix Starter Kit Download issues add improvements for debugging.
  • Loading branch information
rhass authored Mar 20, 2018
2 parents 237076d + 4d6a136 commit cdf2084
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
8 changes: 6 additions & 2 deletions arm-templates/automate/automate_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
config.puts(%Q{api_fqdn "#{@fqdn}"})
end

environment = {
'HOME' => '/root'
}

# Configure the hostname
hostname = Mixlib::ShellOut.new("chef-marketplace-ctl hostname #{@fqdn}")
hostname = Mixlib::ShellOut.new("chef-marketplace-ctl hostname #{@fqdn}", env: environment)
hostname.run_command

# Configure Automate
configure = Mixlib::ShellOut.new("chef-marketplace-ctl setup --preconfigure")
configure = Mixlib::ShellOut.new("chef-marketplace-ctl setup --preconfigure", env: environment)
configure.run_command
1 change: 1 addition & 0 deletions cloudformation/marketplace_byol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Resources:
- |+
- - '#!/bin/bash -ex'
- export HOME=/root
- !If
- HasLicenseUrl
- !Sub >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
m["platform"] = "aws"
m["user"] = "ec2-user"
m["api_ssl_port"] = 443
m["update_channel"] = :stable
m["reporting"]["cron"]["enabled"] = true
m["reporting"]["cron"]["expression"] = "0 0 * * *"
m["reporting"]["cron"]["year"] = "date +%Y"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Chef Automate
chef_ingredient 'delivery' do
action :upgrade

channel node['chef-marketplace']['update_channel'].to_sym
notifies :run, 'bash[delivery-ctl reconfigure]', :immediately
notifies :run, 'bash[yum-clean-all]', :immediately
notifies :run, 'bash[apt-get-clean]', :immediately
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
upstream biscotti {
server 127.0.0.1:<%= node['chef-marketplace']['biscotti']['port'] %>;
# Disable fail_timeout and max_fails accounting for Unicorn.
# https://git.io/vAzf0
server 127.0.0.1:<%= node['chef-marketplace']['biscotti']['port'] %> max_fails=0 fail_timeout=0;
}
5 changes: 5 additions & 0 deletions files/chef-marketplace-ctl-commands/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
options.preconfigure = false
options.license_url = nil
options.license_base64 = nil
options.debug = false

OptionParser.new do |opts|
opts.banner = "Usage: chef-marketplace-ctl setup [options]"
Expand Down Expand Up @@ -60,6 +61,10 @@
options.license_base64 = license
end

opts.on("--debug", "Enable debug logging output.") do
options.debug = true
end

opts.on("-h", "--help", "Show this message") do
puts opts
exit
Expand Down
6 changes: 6 additions & 0 deletions files/chef-marketplace-ctl-commands/upgrade.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "json"

RELEASE_CHANNELS = %w(unstable current stable)

add_command_under_category "upgrade", "Maintenance", "Upgrade or install Chef software", 2 do
config = {
"chef-marketplace" => {
Expand Down Expand Up @@ -64,6 +66,10 @@
config["chef-marketplace"]["upgrade_packages"] << "automate"
end

opts.on("-r RELEASE_CHANNEL", "--channel RELEASE_CHANNEL", RELEASE_CHANNELS, "Release channel to use for downloading packages to install") do |channel|
config["chef-marketplace"]["update_channel"] = channel.to_sym
end

opts.on("-h", "--help", "Show this message") do
puts opts
exit(0)
Expand Down
44 changes: 26 additions & 18 deletions files/chef-marketplace-gem/lib/marketplace/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,41 @@ def setup_automate
# * determine correct email
# * create user with existing delivery.{pem,pub}
create_user = [
"chef-server-ctl user-create",
"delivery", # options.username.to_s.shellescape,
"Automate", # options.first_name.to_s.shellescape,
"User", # options.last_name.to_s.shellescape,
"[email protected]", # options.email.to_s.shellescape,
passwords["chef_user"].shellescape, # options.password.to_s.shellescape
"-f /etc/delivery/delivery.pem",
].join(" ")
"chef-server-ctl",
"user-create",
"delivery", # options.username,
"Automate", # options.first_name,
"User", # options.last_name,
"[email protected]", # options.email,
passwords["chef_user"], # options.password
"-f", "/etc/delivery/delivery.pem",
].shelljoin
retry_command(create_user, retries: 1)

# create chef server org
create_org = [
"chef-server-ctl org-create",
"delivery", # options.organization.to_s.shellescape,
"delivery", # options.organization.to_s.shellescape,
"-a",
"delivery" # options.username.to_s.shellescape
].join(" ")
"chef-server-ctl",
"org-create",
"delivery", # options.organization,
"delivery", # options.organization,
"-a", "delivery" # options.username
].shelljoin
retry_command(create_org, retries: 1)

# Try to wait for automate to come up before attempting to create the
# automate enterprise. This has the added bonus of being able to log
# the state of all the services while we wait.
retry_command("delivery-ctl status", retries: 60, seconds: 2) # Wait up to two minutes.

# create automate enterprise
create_ent = [
"delivery-ctl create-enterprise",
"delivery-ctl",
"create-enterprise",
"default", # enterprise name
"--ssh-pub-key-file=/etc/delivery/builder.pub", # builder public key
"--password=#{passwords['admin_user'].shellescape}", # admin password
"--builder-password=#{passwords['builder_user'].shellescape}" # builder password
].join(" ")
"--password=#{passwords['admin_user']}", # admin password
"--builder-password=#{passwords['builder_user']}" # builder password
].shelljoin
retry_command(create_ent, retries: 3, seconds: 10)
end

Expand Down Expand Up @@ -367,6 +374,7 @@ def retry_command(cmd, retries: 5, seconds: 2, env: {})
retries.times do
command = Mixlib::ShellOut.new(cmd)
command.environment = env unless env.empty?
command.live_stream = STDOUT if options.debug
command.run_command
return unless command.error?
ui.say("#{cmd} failed, retrying...")
Expand Down

0 comments on commit cdf2084

Please sign in to comment.