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

Cookbook #63

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
319acef
OpsWorks + license as template
Nov 2, 2015
a5ee738
Create conf dir, proper apache attribute
Nov 5, 2015
c7adc0b
Merge pull request #1 from ptqa/master
ptqa Dec 9, 2015
abe502c
Added felix bundles automation for easier managing
Dec 9, 2015
eeed9a1
Merge pull request #2 from LibertyGlobal/dev
dexpetkovic Jan 18, 2016
963e3ea
Adding stop bundle feature
Feb 10, 2016
09e401e
Updated JVM options
Feb 24, 2016
dc88979
Moving GC into the aem-opsworks cookbook
Jun 14, 2016
5db646e
Work in progress, almost done
madeddie Sep 6, 2016
da0544b
Trying to fix bugs
Sep 7, 2016
e978b96
Bugfixes
Sep 8, 2016
3955a32
Adding /cache/headers section in dispatcher.any
Sep 13, 2016
9c9517f
Adding /cache/headers section in dispatcher.any
Sep 13, 2016
ca62c7a
Merge pull request #3 from LibertyGlobal/dev
dexpetkovic Sep 20, 2016
83b2eb4
Introducing receive timeout into dispatcher config
Dec 13, 2016
c0cfc37
Merge pull request #4 from LibertyGlobal/dev
dexpetkovic Dec 15, 2016
f95b433
WEB-3137 Automate prerequisites deployment on stack creation
invalid-email-address Feb 12, 2017
cbdfba9
WEB-3137
invalid-email-address Feb 23, 2017
c2d1f87
Revert "WEB-3137"
invalid-email-address Feb 23, 2017
7a80757
WEB-3137
invalid-email-address Feb 24, 2017
536d7f7
WEB-3137
invalid-email-address Feb 24, 2017
0810839
WEB-3137
invalid-email-address Feb 24, 2017
333fdf5
WEB-3137
invalid-email-address Feb 24, 2017
f6d1907
#WEB-3137 without cache
mavrik90 Apr 10, 2017
4d1d464
#WEB-3137 without cache
mavrik90 Apr 10, 2017
dac5bb9
refactor prerequesite_installer provider
Sep 27, 2017
ca46d02
refactor prerequesite_installer provider
Sep 27, 2017
4be68cf
tiny fix
Sep 27, 2017
06e0708
WEB-4617 tiny fix
Sep 27, 2017
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
21 changes: 20 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
default[:aem][:jar_name] = nil
default[:aem][:use_yum] = false
default[:aem][:download_url] = nil
default[:aem][:install_pkgs_on_start] = nil
default[:aem][:license_url] = nil
default[:aem][:license_customer_name] = nil
default[:aem][:license_download_id] = nil
default[:aem][:license_product_name] = 'Adobe CQ5'
default[:aem][:base_dir] = '/opt/aem'
default[:aem][:cluster_name] = nil
default[:aem][:geometrixx_priv_users] = [
Expand Down Expand Up @@ -140,6 +144,14 @@
# :action => [ :upload, :install, :activate ]
# }
],
install_pkgs_on_start: [
# Automate prerequisites deployment on stack creation WEB-3137
],
install_bundles: [],
delete_bundles: [],
restart_bundles: [],
stop_bundles: [],

# You changed these, right?
admin_user: 'admin',
admin_password: 'admin',
Expand Down Expand Up @@ -175,6 +187,9 @@
deploy_pkgs: [
# See the format in author, above
],
install_pkgs_on_start: [
# Automate prerequisites deployment on stack creation WEB-3137
],
admin_user: 'admin',
admin_password: 'admin',
new_admin_password: nil,
Expand All @@ -185,7 +200,11 @@
# :password => "the admin password on the remote"
# }
],
find_cache_hosts_dynamically: false
find_cache_hosts_dynamically: false,
install_bundles: [],
delete_bundles: [],
restart_bundles: [],
stop_bundles: []
}
default[:aem][:publish][:startup][:max_attempts] = 20
default[:aem][:publish][:startup][:wait_between_attempts] = 30
Expand Down
96 changes: 96 additions & 0 deletions providers/bundle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This provider manages AEM bundles. It is not intended for production use,
# though it can be useful for standing-up developer environments. If you
# really want to use this for production, you should add some real error
# checking on the output of the curl commands.

def set_vars
# Set up vars
vars = {}
vars[:bundle_name] = "#{new_resource.name}"
vars[:file_name] = "#{new_resource.name}-#{new_resource.version}" \
"#{new_resource.file_extension}"
vars[:download_url] = new_resource.bundle_url
vars[:file_path] = "#{Chef::Config[:file_cache_path]}/#{vars[:file_name]}"
vars[:user] = new_resource.user
vars[:password] = new_resource.password
vars[:port] = new_resource.port

vars[:install_cmd] = "curl -u #{vars[:user]}:#{vars[:password]} " \
"-F action=install -F bundlestartlevel=20 " \
"-F bundlefile=@#{vars[:file_path]} http://localhost:#{vars[:port]}/system/console/bundles"
vars[:stop_cmd] = "curl -u #{vars[:user]}:#{vars[:password]} " \
"-F action=stop " \
"http://localhost:#{vars[:port]}/system/console/bundles/#{vars[:bundle_name]}"
vars[:start_cmd] = "curl -u #{vars[:user]}:#{vars[:password]} " \
"-F action=start " \
"http://localhost:#{vars[:port]}/system/console/bundles/#{vars[:bundle_name]}"
# Delete command removes default Felix configuration so as to make sure that CRX configuration
# from /apps/config.runmode are correctly picked up
vars[:delete_cmd] = "curl -u #{vars[:user]}:#{vars[:password]} " \
"-F action=delete " \
"http://localhost:#{vars[:port]}/system/console/bundles/#{vars[:bundle_name]}"
# Uninstall command removes the bundle
vars[:uninstall_cmd] = "curl -u #{vars[:user]}:#{vars[:password]} " \
"-daction=uninstall " \
"http://localhost:#{vars[:port]}/system/console/bundles/#{vars[:bundle_name]}"
vars
end


action :install_bundle do
vars = set_vars
r = remote_file vars[:file_path] do
source vars[:download_url]
mode 0755
action :nothing
end
r.run_action(:create)

install = Mixlib::ShellOut.new(vars[:install_cmd])
log "Installing AEM Felix bundle with command: #{vars[:install_cmd]}"
install.run_command
install.error!
log install.stdout
end

action :stop_bundle do
vars = set_vars
stop = Mixlib::ShellOut.new(vars[:stop_cmd])
log "Stopping AEM bundle with command: #{vars[:stop_cmd]}"
stop.run_command
stop.error!
log stop.stdout
end

action :start_bundle do
vars = set_vars
start = Mixlib::ShellOut.new(vars[:start_cmd])
log "Starting AEM bundle with command: #{vars[:start_cmd]}"
start.run_command
start.error!
log start.stdout
end

action :delete_bundle do
vars = set_vars
delete = Mixlib::ShellOut.new(vars[:delete_cmd])
log "Deleting AEM bundle with command: #{vars[:delete_cmd]}"
delete.run_command
delete.error!
log delete.stdout
file vars[:file_path] do
action :delete
end
end

action :uninstall_bundle do
vars = set_vars
uninstall = Mixlib::ShellOut.new(vars[:uninstall_cmd])
log "Uninstalling AEM bundle with command: #{vars[:uninstall_cmd]}"
uninstall.run_command
uninstall.error!
log uninstall.stdout
file vars[:file_path] do
action :uninstall
end
end
2 changes: 1 addition & 1 deletion providers/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
owner 'root'
group 'root'
action :create
notifies :restart, service_name
notifies :restart, service_name, :delayed
end
else
# extract out the module.so
Expand Down
3 changes: 2 additions & 1 deletion providers/farm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
name: r[:fqdn],
hostname: r[:ipaddress],
port: r[:aem][cluster_type][:port],
timeout: timeout
timeout: timeout,
receiveTimeout: receiveTimeout
}
end
# Don't ever return an empty renders list, or apache won't start and
Expand Down
14 changes: 5 additions & 9 deletions providers/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ def set_vars
[ group, admin_user, admin_password, port, aem_version, path ]
end

def curl(url, user, password)
c = Curl::Easy.new(url)
c.http_auth_types = :basic
c.username = user
c.password = password
c.perform
c
def http_get(url, user, password)
res = RestClient::Resource.new(url, user, password)
res.get
end

def get_group_path(port, group, admin_user, admin_password)
url = "http://localhost:#{port}/bin/querybuilder.json?path=/home/groups&1_property=rep:authorizableId&1_property.value=#{group}&p.limit=-1"
c = curl(url, admin_user, admin_password)
group_json = JSON.parse(c.body_str)
res = http_get(url, admin_user, admin_password)
group_json = JSON.parse(res.body_str)

path = nil
hits = group_json['hits']
Expand Down
57 changes: 27 additions & 30 deletions providers/jcr_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,26 @@

# This provider manages an AEM JCR node

def curl(url, user, password)
c = Curl::Easy.new(url)
c.http_auth_types = :basic
c.username = user
c.password = password
c.perform
c
def http_get(url, user, password)
res = RestClient::Resource.new(url, user, password)
res.get
end

def curl_form(url, user, password, fields)
c = Curl::Easy.http_post(url, *fields)
c.http_auth_types = :basic
c.username = user
c.password = password
c.multipart_form_post = true
c.perform
c
def http_post(url, user, password, fields)
res = RestClient::Resource.new(url, user, password)
res.post(fields)
end

def check_node(url, user, password, name)
url = "#{url}/#{name}"
c = curl(url, user, password)
case c.response_code
res = http_get(url, user, password)
case res.code
when 200, 201
c.body_str
res.to_str
when 404
false
else
fail "Unable to read JCR node at #{url}. response_code: #{c.response_code} response: #{c.body_str}"
fail "Unable to read JCR node at #{url}. response_code: #{res.code} response: #{res.to_str}"
end
end

Expand All @@ -60,16 +51,21 @@ def make_url(new_resource)
case new_resource.type
when 'file'
unless check_node(url, new_resource.user, new_resource.password, new_resource.name) == new_resource.contents
fields = [
Curl::PostField.file(new_resource.name, new_resource.contents),
Curl::PostField.content("#{new_resource.name}@TypeHint", 'Binary')
]
c = curl_form(url, new_resource.user, new_resource.password, fields)
if c.response_code == 200 || c.response_code == 201
# EH This doesn't work!! Fields need to be in right format, need to figure out what AEM api expects
fields = {operation: 'post', metadata: new_resource.name, :content => new_resource.contents }

#[
# Curl::PostField.file(new_resource.name, new_resource.contents),
# Curl::PostField.content("#{new_resource.name}@TypeHint", 'Binary')
#]


res = http_post(url, new_resource.user, new_resource.password, fields)
if res.code == 200 || res.code == 201
new_resource.updated_by_last_action(true)
Chef::Log.debug("New jcr_node was created at #{new_resource.path}")
else
fail "JCR Node Creation failed. HTTP code: #{c.response_code}"
fail "JCR Node Creation failed. HTTP code: #{res.code}"
end
end
else
Expand All @@ -81,12 +77,13 @@ def make_url(new_resource)
url = make_url(new_resource)
if check_node(url, new_resource.user, new_resource.password, new_resource.name)
# If the node exists, delete it
fields = [Curl::PostField.content(':operation', 'delete')]
c = curl_form(url, new_resource.user, new_resource.password, fields)
if c.response_code == 200 || c.response_code == 201
# EH might not have to be multipart
fields = {operation: 'delete', multipart: true}
res = http_post(url, new_resource.user, new_resource.password, fields)
if res.code == 200 || res.code == 201
new_resource.updated_by_last_action(true)
else
fail "JCR Node Deletion failed. HTTP code: #{c.response_code}"
fail "JCR Node Deletion failed. HTTP code: #{res.code}"
end
end
end
47 changes: 47 additions & 0 deletions providers/prerequisite_installer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Cookbook Name:: aem
# Provider:: prerequisite_installer
#
# Copyright 2012, Tacit Knowledge, Inc.
#
# 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.

action :install do
# Use fallback attributes if property isn't passed
base_dir = new_resource.base_dir || node[:aem][:base_dir]
install_pkgs_on_start = new_resource.install_pkgs_on_start || node[:aem][:install_pkgs_on_start]
package_store_url = new_resource.package_store_url || node[:aem][:package_store_url]

install_dir = base_dir + '/install'

directory install_dir do
owner 'crx'
group 'crx'
mode '0755'
action :create
end

install_pkgs_on_start.each_with_index do |file,index|
# prepending index, since aem installs packages in alphabet order
file_name = index.to_s + '_' + ::File.basename(file)

remote_file "#{install_dir}/#{file_name}" do
source "#{package_store_url}/#{file}"
owner 'crx'
group 'crx'
mode "0644"
action :create_if_missing
end
end
end

4 changes: 2 additions & 2 deletions providers/url_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
creds = "-u #{new_resource.user}:#{new_resource.password}"
end
if new_resource.match_string
curl_validation_command = %(curl #{creds} --silent #{validation_url} | grep "#{new_resource.match_string}")
curl_validation_command = %(curl #{creds} -L --silent #{validation_url} | grep "#{new_resource.match_string}")
else
curl_validation_command = "curl #{creds} -o /dev/null --silent --head --write-out '%{http_code}' #{validation_url} | grep 200"
curl_validation_command = "curl #{creds} -L -o /dev/null --silent --head --write-out '%{http_code}' #{validation_url} | grep 200"
end

bash "wait for URL: #{validation_url}" do
Expand Down
14 changes: 5 additions & 9 deletions providers/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@ def set_vars
[user, password, admin_user, admin_password, port, aem_version, path, group]
end

def curl(url, user, password)
c = Curl::Easy.new(url)
c.http_auth_types = :basic
c.username = user
c.password = password
c.perform
c
def http_get(url, user, password)
res = RestClient::Resource.new(url, user, password)
res.get
end

def get_usr_path(port, user, admin_user, admin_password)
url_user = "http://localhost:#{port}/bin/querybuilder.json?path=/home/users&1_property=rep:authorizableId&1_property.value=#{user}&p.limit=-1"
c = curl(url_user, admin_user, admin_password)
usr_json = JSON.parse(c.body_str)
res = http_get(url_user, admin_user, admin_password)
usr_json = JSON.parse(res.to_str)

path = nil
hits = usr_json['hits']
Expand Down
Loading