Skip to content

Improved Bootstrapping #2

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

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
default['zendserver']['basedirdeb'] = 'deb'
default['zendserver']['basedirrpm'] = 'rpm'

default['zendserver']['version'] = '6.1'
default['zendserver']['version'] = '6.2'
default['zendserver']['phpversion'] = '5.4'

# GUI default passwords
Expand Down
18 changes: 15 additions & 3 deletions libraries/zendserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@ def get_node_id_by_name(name, keyname, secret)
end

def is_server_bootstrapped(keyname, secret)
system_info = "#{node[:zendserver][:zsmanage]} system-info -N #{keyname} -K #{secret} -U http://#{node[:hostname]}:10081/ZendServer/"
p = shell_out(system_info)
!p.stderr.include? "Bootstrap is needed"
system_info = "#{node[:zendserver][:zsmanage]} system-info"
system_info << " -N #{keyname}" unless keyname.nil? || keyname.empty?
system_info << " -K #{secret}" unless secret.nil? || secret.empty?
system_info << " -U http://#{node[:hostname]}:10081/ZendServer/" unless node[:hostname].nil? || node[:hostname].empty?

p = shell_out(system_info)
!p.stderr.include? "Bootstrap is needed"
end

def is_node_joined(keyname, secret)
system_info = "#{node[:zendserver][:zsmanage]} system-info -N #{keyname} -K #{secret} -U http://#{node[:hostname]}:10081/ZendServer/"
p = shell_out(system_info)
p.stdout.include? "ZendServerCluster"
end

CHARS = ('0'..'9').to_a + ('a'..'z').to_a

def get_random_chef_admin_apikeyname ()
apikeyname = "chef-admin-"
apikeyname << CHARS.sort_by { rand }.join[0...8]
apikeyname.to_s
end
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'All rights reserved'
description 'Installs/Configures zendserver'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.8.0'
version '0.9.0'

depends "apt"
depends "yum"
Expand Down Expand Up @@ -135,4 +135,4 @@
:required => "optional",
:recipes => [
"zendserver::joincluster"
]
]
38 changes: 21 additions & 17 deletions recipes/bootstrapsingle.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# Recipe to bootstrap a single server

node.default[:zendserver][:chef_admin_apikeyname] = "chef-admin-12345678"
node.default[:zendserver][:chef_admin_apikeysecret] = "00000"

ruby_block "set chef admin api credentials" do
block do
node.set[:zendserver][:chef_admin_apikeyname] = get_random_chef_admin_apikeyname()
set_api = "#{node[:zendserver][:zsmanage]} api-keys-add-key -n #{node[:zendserver][:chef_admin_apikeyname]} -u admin"
p = Chef::Mixin::ShellOut.shell_out(set_api)

node.set[:zendserver][:chef_admin_apikeysecret] = p.stdout.split(/\n/).grep(/KEY_HASH/)[0].split(/=/)[1].strip()
end
notifies :run, "execute[bootstrap-single-server]", :immediately
not_if { is_server_bootstrapped(node[:zendserver][:chef_admin_apikeyname], node[:zendserver][:chef_admin_apikeysecret]) }
end

include_recipe "zendserver::manage"

admin_password = node[:zendserver][:adminpassword]
order_number = node[:zendserver][:ordernumber]
license_key = node[:zendserver][:licensekey]
license_key = node[:zendserver][:licensekey]
production = node[:zendserver][:production]
admin_email = node[:zendserver][:adminemail]
dev_password = node[:zendserver][:devpassword]
Expand All @@ -16,18 +29,9 @@
bs_command << " -e #{admin_email}" unless admin_email.nil? || admin_email.empty?
bs_command << " -d #{devpassword}" unless dev_password.nil? || dev_password.empty?


execute "create-api-key" do
command "/usr/local/zend/bin/zs-manage api-keys-add-key -n #{node[:zendserver][:apikeyname]} -s #{node[:zendserver][:apikeysecret]}"
retries 5
retry_delay 5
ignore_failure false
not_if { is_server_bootstrapped(node[:zendserver][:apikeyname], node[:zendserver][:apikeysecret]) }
end

execute "bootstrap-single-server" do
command bs_command
command lazy {bs_command}
ignore_failure false
notifies :run, 'execute[restart-api]'
not_if { is_server_bootstrapped(node[:zendserver][:apikeyname], node[:zendserver][:apikeysecret]) }
end
notifies :run, 'execute[restart-api]', :delayed
action :nothing
end
46 changes: 23 additions & 23 deletions recipes/joincluster.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#This recipe is used to join a cluster of Zend Servers

key_name = node[:zendserver][:apikeyname]
key_secret = node[:zendserver][:apikeysecret]
db_host = node[:zendserver][:dbhost]
db_user = node[:zendserver][:dbusername]
db_pass = node[:zendserver][:dbpassword]
node_ip = node[:zendserver][:node_ip].nil? ? node['ipaddress'] : node[:zendserver][:node_ip]
ruby_block "server add to cluster" do
block do
apikeyname = node[:zendserver][:chef_admin_apikeyname]
apikeysecret = node[:zendserver][:chef_admin_apikeysecret]
dbhost = node[:zendserver][:dbhost]
dbusername = node[:zendserver][:dbusername]
dbpassword = node[:zendserver][:dbpassword]
node_ip = node[:zendserver][:node_ip].nil? ? node['ipaddress'] : node[:zendserver][:node_ip]

Log "Using ip: #{node_ip}"

# check before install that a suitable key is provided, if not bail out
Chef::Application.fatal!("Zend Server db_host missing", 2) if db_host.nil? || db_host.empty?
Chef::Application.fatal!("Zend Server db_user missing", 2) if db_user.nil? || db_user.empty?
Chef::Application.fatal!("Zend Server db_pass missing", 2) if db_pass.nil? || db_pass.empty?

join_command = "#{node[:zendserver][:zsmanage]} server-add-to-cluster -N #{key_name} -K #{key_secret} -U http://#{node[:hostname]}:10081/ZendServer/ -n #{node['hostname']} -i #{node_ip} -o #{db_host} -u #{db_user} -p #{db_pass} -s"

log "Adding server node to cluster - Executing #{join_command}" if !is_node_joined(key_name, key_secret)

execute "cluster-join-server" do
command join_command
ignore_failure false
retries 5
retry_delay 3
not_if { is_node_joined(key_name, key_secret) }
# check before install that a suitable key is provided, if not bail out
Chef::Application.fatal!("Zend Server API Key Name missing", 2) if apikeyname.nil? || apikeyname.empty?
Chef::Application.fatal!("Zend Server API Key Secret missing", 2) if apikeysecret.nil? || apikeysecret.empty? || apikeysecret == "00000"
Chef::Application.fatal!("Zend Server dbhost missing", 2) if dbhost.nil? || dbhost.empty?
Chef::Application.fatal!("Zend Server dbhost missing", 2) if dbhost.nil? || dbhost.empty?
Chef::Application.fatal!("Zend Server dbusername missing", 2) if dbusername.nil? || dbusername.empty?
Chef::Application.fatal!("Zend Server dbpassword missing", 2) if dbpassword.nil? || dbpassword.empty?

join_command = "#{node[:zendserver][:zsmanage]} server-add-to-cluster -N #{apikeyname} -K #{apikeysecret} -n #{node['hostname']} -i #{node_ip} -o #{dbhost} -u #{dbusername} -p #{dbpassword} -s"
p = Chef::Mixin::ShellOut.shell_out(join_command)

node.set[:zendserver][:chef_admin_apikeyname] = p.stdout.split(/\n/).grep(/WEB_API_KEY/)[0].split(/=/)[1].strip()
node.set[:zendserver][:chef_admin_apikeysecret] = p.stdout.split(/\n/).grep(/WEB_API_KEY_HASH/)[0].split(/=/)[1].strip()
end
not_if { is_node_joined(node[:zendserver][:chef_admin_apikeyname], node[:zendserver][:chef_admin_apikeysecret]) }
end
2 changes: 1 addition & 1 deletion recipes/manage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

execute "restart-api" do
action :nothing
command "#{node[:zendserver][:zsmanage]} #{restart} -N #{node[:zendserver][:apikeyname]} -K #{node[:zendserver][:apikeysecret]}"
command lazy {"#{node[:zendserver][:zsmanage]} #{restart} -N #{node[:zendserver][:chef_admin_apikeyname]} -K #{node[:zendserver][:chef_admin_apikeysecret]} "}
retries 3
retry_delay 3
end