diff options
author | Mustapha Lansana <Mustapha.Lansana@windriver.com> | 2014-07-30 19:32:37 -0400 |
---|---|---|
committer | Bruce Ashfield <bruce.ashfield@windriver.com> | 2014-09-26 09:09:21 -0400 |
commit | 261f7f857503d7dcd7dcdc4c36aeff1b57194f9b (patch) | |
tree | 62bfe5adcc46479e1d864cfa79635060a0e7cdb4 | |
parent | 48bd378fda4db37b519742bdcf98b6a48f83b594 (diff) | |
download | meta-cloud-services-261f7f857503d7dcd7dcdc4c36aeff1b57194f9b.tar.gz |
deploychef: adaptation of deploychef to support openstackchef
The deploychef package has been adapted to implement the
run-time functionality required by decentralized openstackchef
class.
It does this by executing a script (deploychef) which instruct chef-solo
to recreate configuration files from all template files placed
at
/opt/deploychef/cookbooks/openstack/templates/default
by openstackchef class at build-time.
The deploychef init script run-level is lower than run-postinsts
script, which runs all openstack post-install scripts at first boot.
The deploychef script makes a call to run-chefsolo script,
which then creates openstack configuration files from all template
files mentioned above as directed by a recipe file.
This enables us to reconfigure an openstack image on first-boot,
thereby, updating the image with environment variables like IP address.
Like the template files above, there is a list of all default
variables used by the services in an openstack installation.
These variables, like the templates files above are created by
the openstackchef class and saved to a file under deploychef
directory at:
/opt/deploychef/cookbooks/openstack/attributes/default.rb
Whenever it's desired to reconfigure an openstack deployment
with an updated value of any of the variables in the attributes file
above, the script file run-deploychef should be executed to
reconfigure the stack as shown below.
cd /opt/deploychef
./run-deploychef
Signed-off-by: Mustapha Lansana <Mustapha.Lansana@windriver.com>
8 files changed, 347 insertions, 140 deletions
diff --git a/meta-openstack/recipes-support/deploychef/deploychef_0.1.bb b/meta-openstack/recipes-support/deploychef/deploychef_0.1.bb index 7bd7510..3471a2c 100644 --- a/meta-openstack/recipes-support/deploychef/deploychef_0.1.bb +++ b/meta-openstack/recipes-support/deploychef/deploychef_0.1.bb | |||
@@ -14,23 +14,20 @@ LICENSE = "MIT" | |||
14 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ | 14 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ |
15 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | 15 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" |
16 | 16 | ||
17 | PR = "r0" | 17 | PR = "r1" |
18 | 18 | ||
19 | require deploychef.inc | ||
20 | 19 | ||
21 | RDEPENDS_${PN} = "chef" | 20 | RDEPENDS_${PN} = "chef" |
22 | SRC_URI = "\ | 21 | SRC_URI = "\ |
23 | file://deploychef.init \ | 22 | file://deploychef.init \ |
24 | file://attributes.json \ | 23 | file://attributes.json \ |
25 | file://config.rb \ | 24 | file://config.rb \ |
25 | file://default_recipe.rb \ | ||
26 | file://run-openstackchef \ | ||
26 | file://run-postinsts \ | 27 | file://run-postinsts \ |
27 | file://run-deploychef \ | 28 | file://run-deploychef \ |
28 | file://service-shutdown \ | 29 | file://service-shutdown \ |
29 | file://startup-list \ | 30 | file://deploychef-inc \ |
30 | file://shutdown-list \ | ||
31 | file://chefsolo_default_attribute.rb \ | ||
32 | file://chefsolo_default_recipe.rb \ | ||
33 | file://conf-templates/* \ | ||
34 | " | 31 | " |
35 | inherit update-rc.d identity hosts default_configs | 32 | inherit update-rc.d identity hosts default_configs |
36 | 33 | ||
@@ -38,11 +35,12 @@ S = "${WORKDIR}" | |||
38 | #Since this package does not need to be ran for each boot-up | 35 | #Since this package does not need to be ran for each boot-up |
39 | #There is no need for an init scrpt so install it in /opt/${BPN} | 36 | #There is no need for an init scrpt so install it in /opt/${BPN} |
40 | DEPLOYCHEF_ROOT_DIR ?= "/opt/${BPN}" | 37 | DEPLOYCHEF_ROOT_DIR ?= "/opt/${BPN}" |
38 | POSTINSTS_DIR ?= "rpm-postinsts" | ||
39 | |||
41 | #Provide a mechanism for these strings to be over-written if necessary | 40 | #Provide a mechanism for these strings to be over-written if necessary |
42 | COOKBOOK_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/" | 41 | COOKBOOK_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/" |
43 | ATTRIBUTE_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/attributes/" | 42 | ATTRIBUTE_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/attributes/" |
44 | RECIPE_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/recipes/" | 43 | RECIPE_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/recipes/" |
45 | TEMPLATES_CONF_DIR = "${DEPLOYCHEF_ROOT_DIR}/conf-templates/" | ||
46 | 44 | ||
47 | FILES_${PN} += " \ | 45 | FILES_${PN} += " \ |
48 | ${DEPLOYCHEF_ROOT_DIR}/* \ | 46 | ${DEPLOYCHEF_ROOT_DIR}/* \ |
@@ -50,8 +48,8 @@ FILES_${PN} += " \ | |||
50 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/* \ | 48 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/* \ |
51 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/recipes/* \ | 49 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/recipes/* \ |
52 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/* \ | 50 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/* \ |
53 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/default/* \ | 51 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/default \ |
54 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/default/excluded/* \ | 52 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/attributes \ |
55 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/attributes/* \ | 53 | ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/attributes/* \ |
56 | " | 54 | " |
57 | #Read the module config files and make them into | 55 | #Read the module config files and make them into |
@@ -65,65 +63,34 @@ do_install() { | |||
65 | 63 | ||
66 | install -d ${D}/${DEPLOYCHEF_ROOT_DIR} | 64 | install -d ${D}/${DEPLOYCHEF_ROOT_DIR} |
67 | #Copy the template configuration scripts to image directory | 65 | #Copy the template configuration scripts to image directory |
68 | cp -r ${S}/conf-templates ${D}/${DEPLOYCHEF_ROOT_DIR} | ||
69 | install -m 0755 ${S}/generate-templates ${D}/${DEPLOYCHEF_ROOT_DIR} | ||
70 | install -m 0644 ${S}/config.rb ${D}/${DEPLOYCHEF_ROOT_DIR}/config.rb | 66 | install -m 0644 ${S}/config.rb ${D}/${DEPLOYCHEF_ROOT_DIR}/config.rb |
71 | install -m 0644 ${S}/attributes.json ${D}/${DEPLOYCHEF_ROOT_DIR}/attributes.json | 67 | install -m 0644 ${S}/attributes.json ${D}/${DEPLOYCHEF_ROOT_DIR}/attributes.json |
72 | install -m 0644 ${S}/run-postinsts ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts | 68 | install -m 0755 ${S}/run-postinsts ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts |
73 | install -m 0644 ${S}/shutdown-list ${D}/${DEPLOYCHEF_ROOT_DIR}/shutdown-list | 69 | install -m 0755 ${S}/run-openstackchef ${D}/${DEPLOYCHEF_ROOT_DIR}/run-openstackchef |
74 | install -m 0755 ${S}/run-deploychef ${D}/${DEPLOYCHEF_ROOT_DIR}/run-deploychef | 70 | install -m 0755 ${S}/run-deploychef ${D}/${DEPLOYCHEF_ROOT_DIR}/run-deploychef |
75 | install -m 0644 ${S}/service-shutdown ${D}/${DEPLOYCHEF_ROOT_DIR}/service-shutdown | 71 | install -m 0755 ${S}/service-shutdown ${D}/${DEPLOYCHEF_ROOT_DIR}/service-shutdown |
76 | install -m 0644 ${S}/startup-list ${D}/${DEPLOYCHEF_ROOT_DIR}/startup-list | 72 | install -m 0644 ${S}/deploychef-inc ${D}/${DEPLOYCHEF_ROOT_DIR}/deploychef-inc |
77 | #Copy the respective services configuration script files and convert them to | 73 | #Copy the chefsolo recipe file to chefsolo recipe folder |
78 | #chefsolo recipes | ||
79 | install -d ${D}/${ATTRIBUTE_DIR} | ||
80 | install -m 0644 ${S}/chefsolo_default_attribute.rb ${D}/${ATTRIBUTE_DIR}/default.rb | ||
81 | |||
82 | install -d ${D}/${RECIPE_DIR} | 74 | install -d ${D}/${RECIPE_DIR} |
83 | install -m 0644 ${S}/chefsolo_default_recipe.rb ${D}/${RECIPE_DIR}/default.rb | 75 | install -m 0644 ${S}/default_recipe.rb ${D}/${RECIPE_DIR}/default.rb |
84 | fi | 76 | fi |
85 | } | 77 | } |
86 | 78 | ||
87 | do_install_append() { | 79 | do_install_append() { |
88 | sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${sysconfdir}/init.d/${BPN} | ||
89 | #Replace all the place holders in the respective files | ||
90 | sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${ATTRIBUTE_DIR}default.rb | ||
91 | sed -i s:%SYSCONFDIR%:${sysconfdir}:g ${D}/${ATTRIBUTE_DIR}default.rb | ||
92 | sed -i s:%SYSCONFDIR%:${sysconfdir}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/generate-templates | ||
93 | sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/generate-templates | ||
94 | #chef-solo requires location of script files to be absolute, provide absolute path | ||
95 | sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/service-shutdown | ||
96 | sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts | ||
97 | sed -i s:%PACKAGE_NAME%:${BPN}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts | ||
98 | 80 | ||
99 | #Populate chefsolo attribute file and | 81 | #Replace all required placeholders |
100 | #Populate deploychef.inc file used in the generation of chefsolo templates | 82 | for file in "${D}/${DEPLOYCHEF_ROOT_DIR}/run-deploychef \ |
101 | for file in ${D}/${ATTRIBUTE_DIR}default.rb ${D}/${TEMPLATES_CONF_DIR}/constants.inc; do | 83 | ${D}/${DEPLOYCHEF_ROOT_DIR}/service-shutdown \ |
102 | sed -i s:%CONTROLLER_IP%:${CONTROLLER_IP}:g $file | 84 | ${D}/${DEPLOYCHEF_ROOT_DIR}/deploychef-inc \ |
103 | sed -i s:%CONTROLLER_HOST%:${CONTROLLER_HOST}:g $file | 85 | ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts \ |
104 | sed -i s:%COMPUTE_IP%:${COMPUTE_IP}:g $file | 86 | ${D}/${DEPLOYCHEF_ROOT_DIR}/run-openstackchef \ |
105 | sed -i s:%COMPUTE_HOST%:${COMPUTE_HOST}:g $file | 87 | ${D}/${RECIPE_DIR}/default.rb \ |
106 | sed -i s:%ADMIN_PASSWORD%:${ADMIN_PASSWORD}:g $file | 88 | ${D}/${sysconfdir}/init.d/${BPN} "; do |
107 | sed -i s:%ADMIN_USER%:${ADMIN_USER}:g $file | ||
108 | sed -i s:%SERVICE_PASSWORD%:${SERVICE_PASSWORD}:g $file | ||
109 | sed -i s:%SERVICE_TENANT_NAME%:${SERVICE_TENANT_NAME}:g $file | ||
110 | sed -i s:%SERVICE_USER%:${SERVICE_USER}:g $file | ||
111 | sed -i s:%SERVICE_TOKEN%:${SERVICE_TOKEN}:g $file | ||
112 | sed -i s:%DEMO_USER%:${DEMO_USER}:g $file | ||
113 | sed -i s:%DEMO_PASSWORD%:${DEMO_PASSWORD}:g $file | ||
114 | sed -i s:%OS_TENANT_NAME%:${OS_TENANT_NAME}:g $file | ||
115 | sed -i s:%OS_USERNAME%:${OS_USERNAME}:g $file | ||
116 | sed -i s:%OS_PASSWORD%:${OS_PASSWORD}:g $file | ||
117 | sed -i s:%DB_NAME%:${DB_NAME}:g $file | ||
118 | sed -i s:%DB_USER%:${DB_USER}:g $file | ||
119 | sed -i s:%DB_PASSWORD%:${DB_PASSWORD}:g $file | ||
120 | done | ||
121 | 89 | ||
122 | #Replace the rpm-postinsts dir | 90 | sed -i s:%SYSCONFDIR%:${sysconfdir}:g $file |
123 | for file in "${D}/${ATTRIBUTE_DIR}default.rb \ | ||
124 | ${D}/${DEPLOYCHEF_ROOT_DIR}/run-deploychef \ | ||
125 | ${D}/${DEPLOYCHEF_ROOT_DIR}/generate-templates"; do | ||
126 | sed -i s:%POSTINSTS_DIR%:${POSTINSTS_DIR}:g $file | 91 | sed -i s:%POSTINSTS_DIR%:${POSTINSTS_DIR}:g $file |
92 | sed -i s:%PACKAGE_NAME%:${BPN}:g $file | ||
93 | sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g $file | ||
127 | done | 94 | done |
128 | } | 95 | } |
129 | 96 | ||
diff --git a/meta-openstack/recipes-support/deploychef/files/default_recipe.rb b/meta-openstack/recipes-support/deploychef/files/default_recipe.rb new file mode 100644 index 0000000..5e28878 --- /dev/null +++ b/meta-openstack/recipes-support/deploychef/files/default_recipe.rb | |||
@@ -0,0 +1,160 @@ | |||
1 | # default.rb | ||
2 | # | ||
3 | # Copyright (c) 2014 Wind River Systems, Inc. | ||
4 | # | ||
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | # of this software and associated documentation files (the "Software"), to deal | ||
7 | # in the Software without restriction, including without limitation the rights | ||
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | # copies of the Software, and to permit persons to whom the Software is | ||
10 | # furnished to do so, subject to the following conditions: | ||
11 | # | ||
12 | # The above copyright notice and this permission notice shall be included in | ||
13 | # all copies or substantial portions of the Software. | ||
14 | # | ||
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
21 | # THE SOFTWARE. | ||
22 | # | ||
23 | # This is our main recipe that chef-solo bakes to configure our openstack deployment | ||
24 | require 'find' | ||
25 | domain = node['hostname'] | ||
26 | domain += " " + node['platform'] | ||
27 | domain += " " + node['platform_version'] | ||
28 | domain += " " + node['ipaddress'] | ||
29 | log domain do | ||
30 | level:info | ||
31 | end | ||
32 | |||
33 | #The definition of IMAGES_ROOTS is to facilitate switching between development | ||
34 | #environment and run-time environment | ||
35 | node.default["IMAGE_ROOTFS"] = "" | ||
36 | #node.default["IMAGE_ROOTFS"] = "/opt/rootfs/TestDeploychef" | ||
37 | node.default["DEPLOYCHEF_ROOT_DIR"] = "#{node[:IMAGE_ROOTFS]}/opt/deploychef" | ||
38 | node.default["DEPLOYCHEF_TEMPLATE_DIR"] = "#{node[:DEPLOYCHEF_ROOT_DIR]}/cookbooks/openstack/templates/default" | ||
39 | |||
40 | node.default["ETC_DIR"]= "#{node[:IMAGE_ROOTFS]}/etc" | ||
41 | node.default["INITD_DIR"]= "#{node[:ETC_DIR]}/init.d" | ||
42 | node.default["POSTINSTS_DIR"]= "#{node[:ETC_DIR]}/rpm-postinsts" | ||
43 | node.default["CONTROLLER_DAEMON"]= "#{node[:INITD_DIR]}/nova-api" | ||
44 | node.default["COMPUTE_DAEMON"]= "#{node[:INITD_DIR]}/nova-compute" | ||
45 | |||
46 | #Indicate whether or not we successfully created the configuration files | ||
47 | #from templates. | ||
48 | $chefsolo_success = false | ||
49 | #This function enables us to over-ride the hostname and ip address | ||
50 | #attributes based on the type of node installation | ||
51 | #we are running on. | ||
52 | def update_ip_and_hostname() | ||
53 | if File.executable?(node[:CONTROLLER_DAEMON]) and \ | ||
54 | File.executable?(node[:COMPUTE_DAEMON]) | ||
55 | #All in one installation | ||
56 | if node[:ipaddress].length | ||
57 | node.default["CONTROLLER_IP"]=node.default["COMPUTE_IP"]=node.default["PUBLIC_IP"]=node[:ipaddress] | ||
58 | end | ||
59 | if node[:hostname].length | ||
60 | node.default["CONTROLLER_HOST"]=node.default["COMPUTE_HOST"]=node[:hostname] | ||
61 | end | ||
62 | node.default["NODE_TYPE"] ="allinone" | ||
63 | elsif File.executable?(node[:CONTROLLER_DAEMON]) | ||
64 | if node[:ipaddress].length | ||
65 | node.default["CONTROLLER_IP"]=node.default["PUBLIC_IP"]=node[:ipaddress] | ||
66 | end | ||
67 | if node[:hostname].length | ||
68 | node.default["CONTROLLER_HOST"]=node[:hostname] | ||
69 | end | ||
70 | node.default["NODE_TYPE"] ="controller" | ||
71 | else | ||
72 | if node[:ipaddress].length | ||
73 | node.default["COMPUTE_IP"]=node.default["PUBLIC_IP"]=node[:ipaddress] | ||
74 | end | ||
75 | if node[:hostname].length | ||
76 | node.default["COMPUTE_HOST"]=node[:hostname] | ||
77 | end | ||
78 | node.default["NODE_TYPE"] ="compute" | ||
79 | end | ||
80 | #Both private and public IP's default to an empty string in ceph | ||
81 | #So provide default values when this is the case | ||
82 | if not #{default[:PRIVATE_IP]}.length | ||
83 | node.default["PRIVATE_IP"]="127.0.0.1" | ||
84 | end | ||
85 | node.default["PUBIC_DOMAIN"]="#{node[:PUBLIC_IP]}/24" | ||
86 | end | ||
87 | |||
88 | def make_config_files_from_templates() | ||
89 | #Make it easier to move from development environment to target | ||
90 | output_dir = node[:ETC_DIR] | ||
91 | template_dir = node[:DEPLOYCHEF_TEMPLATE_DIR] + '/etc' | ||
92 | #See if output directory exist if not create one | ||
93 | if not File.directory?(output_dir) | ||
94 | execute "Create #{output_dir} #{template_dir} directory" do | ||
95 | command "mkdir -p #{output_dir}" | ||
96 | end | ||
97 | end | ||
98 | #Get the list of all template files and create their corresponding config | ||
99 | #files | ||
100 | dirs = Dir.glob(template_dir) | ||
101 | for dir in dirs do | ||
102 | next if File.file?(dir) or dir == '.' or dir == '..' | ||
103 | Find.find(dir) do | file_name | | ||
104 | if File.file?(file_name) | ||
105 | abs_path_conf_file = "#{file_name}" | ||
106 | if abs_path_conf_file.include?(".erb.") | ||
107 | abs_path_conf_file, throw_away = abs_path_conf_file.split(".erb") | ||
108 | else | ||
109 | abs_path_conf_file.gsub!(".erb","") | ||
110 | end | ||
111 | base_path, abs_path_conf_file = abs_path_conf_file.split('/default') | ||
112 | base_path = node[:IMAGE_ROOTFS] + File.dirname(abs_path_conf_file) | ||
113 | abs_path_conf_file = "#{base_path}/" + File.basename(abs_path_conf_file) | ||
114 | #This test is only true for test bed but for sake of portability | ||
115 | #we leave it in place | ||
116 | if not File.exist?(base_path) | ||
117 | execute "Creating conf file dir: #{abs_path_conf_file}" do | ||
118 | command "mkdir -p #{base_path}" | ||
119 | end | ||
120 | elsif File.exist?(abs_path_conf_file) | ||
121 | execute "Delete file to force recreation: #{abs_path_conf_file}" do | ||
122 | command "rm -f #{abs_path_conf_file}" | ||
123 | end | ||
124 | end | ||
125 | execute "Created file: #{base_path}: #{abs_path_conf_file}" do | ||
126 | command "echo #{abs_path_conf_file}" | ||
127 | end | ||
128 | if File.executable?(file_name) | ||
129 | template abs_path_conf_file do | ||
130 | source File.basename(file_name) | ||
131 | #Preserve mode, owner and group | ||
132 | mode "0755" | ||
133 | end | ||
134 | else | ||
135 | template abs_path_conf_file do | ||
136 | source File.basename(file_name) | ||
137 | #Preserve mode, owner and group | ||
138 | mode "0644" | ||
139 | end | ||
140 | end | ||
141 | $chefsolo_success = true | ||
142 | end | ||
143 | end | ||
144 | end | ||
145 | if $chefsolo_success | ||
146 | execute "Make the postinsts script executables" do | ||
147 | command "touch #{node[:ETC_DIR]}/chefsolo.ran" | ||
148 | end | ||
149 | end | ||
150 | end | ||
151 | |||
152 | #Generate scripts and cofiguration files | ||
153 | update_ip_and_hostname | ||
154 | make_config_files_from_templates | ||
155 | |||
156 | =begin | ||
157 | service host[:hostname] do | ||
158 | action :restart | ||
159 | endf | ||
160 | =end | ||
diff --git a/meta-openstack/recipes-support/deploychef/files/deploychef-inc b/meta-openstack/recipes-support/deploychef/files/deploychef-inc new file mode 100644 index 0000000..861ea39 --- /dev/null +++ b/meta-openstack/recipes-support/deploychef/files/deploychef-inc | |||
@@ -0,0 +1,82 @@ | |||
1 | #!/bin/sh | ||
2 | # deploychef_inc | ||
3 | # | ||
4 | # Copyright (c) 2014 Wind River Systems, Inc. | ||
5 | # | ||
6 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | # of this software and associated documentation files (the "Software"), to deal | ||
8 | # in the Software without restriction, including without limitation the rights | ||
9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | # copies of the Software, and to permit persons to whom the Software is | ||
11 | # furnished to do so, subject to the following conditions: | ||
12 | # | ||
13 | # The above copyright notice and this permission notice shall be included in | ||
14 | # all copies or substantial portions of the Software. | ||
15 | |||
16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
22 | # THE SOFTWARE. | ||
23 | # | ||
24 | #This file is a helper file that implements functions | ||
25 | #used by the service-shutdown and run-postinsts scripts for | ||
26 | #the deploychef package. | ||
27 | |||
28 | RPM_POSTINSTS_DIR=%SYSCONFDIR%/rpm-postinsts | ||
29 | LOG_DIR='/var/log/%PACKAGE_NAME%' | ||
30 | LOG_FILE=$LOG_DIR/deploychef.log | ||
31 | INITD_DIR=/etc/init.d | ||
32 | |||
33 | make_log_dir() { | ||
34 | if [ ! -d $RPM_POSTINSTS_DIR ]; then | ||
35 | mkdir -p $LOG_DIR | ||
36 | echo "Log dir: $LOG_DIR created" > $LOG_FILE | ||
37 | fi | ||
38 | } | ||
39 | |||
40 | execute_all_postinsts(){ | ||
41 | cd / #work-around for cinder-volume config file location | ||
42 | echo "x$RPM_POSTINSTS_DIR" >> "$LOD_FILE" | ||
43 | for i in `ls $RPM_POSTINSTS_DIR/ 2> /dev/null`; do | ||
44 | i=$RPM_POSTINSTS_DIR/$i | ||
45 | echo "Running postinst $i..." >> $LOG_FILE | ||
46 | if [ -f $i ] && $i; then | ||
47 | rm $i | ||
48 | else | ||
49 | echo "ERROR: postinst $i failed. $? " >> $LOG_FILE | ||
50 | fi | ||
51 | done | ||
52 | } | ||
53 | |||
54 | #Start/stop services pass in first argument as startup-list or shutdown-list | ||
55 | start_stop_services(){ | ||
56 | dir_name=%DEPLOYCHEF_ROOT_DIR% | ||
57 | file_name=$dir_name/$1 | ||
58 | if [ -f $file_name ]; then | ||
59 | services=$(sort -d $file_name) | ||
60 | for service in $services; do | ||
61 | start_stop=$(echo $service | awk -F'[0-9]+' '{print $1}') | ||
62 | service=$(echo $service | awk -F'[SK][0-9]+' '{print $2}') | ||
63 | if [ $service != postgresql ]; then | ||
64 | if [ $start_stop = 'S' ]; then | ||
65 | if [ -e $INITD_DIR/$service ]; then | ||
66 | echo "Starting $INITD_DIR/$service" >> $LOG_FILE | ||
67 | if [ $service = 'cinder-volume' ]; then | ||
68 | $INITD_DIR/$service reload & | ||
69 | else | ||
70 | $INITD_DIR/$service start & | ||
71 | fi | ||
72 | wait | ||
73 | fi | ||
74 | else | ||
75 | echo "Stopping $INITD_DIR/$service" >> $LOG_FILE | ||
76 | $INITD_DIR/$service stop & | ||
77 | wait | ||
78 | fi | ||
79 | fi | ||
80 | done | ||
81 | fi | ||
82 | } | ||
diff --git a/meta-openstack/recipes-support/deploychef/files/deploychef.init b/meta-openstack/recipes-support/deploychef/files/deploychef.init index b456e35..22f318b 100644 --- a/meta-openstack/recipes-support/deploychef/files/deploychef.init +++ b/meta-openstack/recipes-support/deploychef/files/deploychef.init | |||
@@ -1,11 +1,26 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | #After this script runs, chefsolo postinsts templates | 2 | #After this script executes, it runs the 'run-openstackchef' script found in |
3 | #script will all be in chefsolo default templates directory | 3 | #/opt/deploychef/ directory. After that, all the |
4 | i=%DEPLOYCHEF_ROOT_DIR%/generate-templates | 4 | #configuration files that were registered with openstackchef class are |
5 | if [ -f $i ] && $i; then | 5 | #created using run-time environment variables and default values |
6 | echo "Chefsolo templates made successfully" | 6 | # found in /opt/deploychef/cookbooks/openstack/attributes/default.rb |
7 | rm -f /etc/rcS.d/S96deploychef | 7 | deploychef_root=%DEPLOYCHEF_ROOT_DIR% |
8 | rm -f $i | 8 | LOG_DIR=/var/log/%PACKAGE_NAME% |
9 | else | 9 | LOG_FILE=$LOG_DIR/%PACKAGE_NAME%.log |
10 | echo "ERROR: $i failed." | 10 | script_file=$deploychef_root/run-openstackchef |
11 | chefsolo_success_file="%SYSCONFDIR%/chefsolo.ran" | ||
12 | if [ ! -f $chefsolo_success_file ]; then | ||
13 | if [ -f $script_file ] ; then | ||
14 | mkdir -p $LOG_DIR | ||
15 | #Remove deploy init script if present | ||
16 | rm -f /etc/init.d/deploy 2>/dev/null | ||
17 | cd $deploychef_root | ||
18 | . $(basename $script_file) | ||
19 | if [ $? = 0 ]; then | ||
20 | echo "Deploychef successfully created chefsolo configuration files" \ | ||
21 | > $LOG_FILE | ||
22 | else | ||
23 | echo "deploychef ERROR: $i failed." > $LOG_FILE | ||
24 | fi | ||
25 | fi | ||
11 | fi | 26 | fi |
diff --git a/meta-openstack/recipes-support/deploychef/files/run-deploychef b/meta-openstack/recipes-support/deploychef/files/run-deploychef index 03e8807..e8a8a57 100644 --- a/meta-openstack/recipes-support/deploychef/files/run-deploychef +++ b/meta-openstack/recipes-support/deploychef/files/run-deploychef | |||
@@ -1,5 +1,5 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # run-chefsolo | 2 | # run-deploychef |
3 | # | 3 | # |
4 | # Copyright (c) 2014 Wind River Systems, Inc. | 4 | # Copyright (c) 2014 Wind River Systems, Inc. |
5 | # | 5 | # |
@@ -22,16 +22,12 @@ | |||
22 | # THE SOFTWARE. | 22 | # THE SOFTWARE. |
23 | # | 23 | # |
24 | # | 24 | # |
25 | # This file is the main file that the install will call in order to reconfig | 25 | # This file is the main script file that reconfigures the stack when any of |
26 | # and Openstack node | 26 | # the attributes variables change at run-time. |
27 | # bash run-chefsolo | ||
28 | # | 27 | # |
29 | # | 28 | #Shutdown all registered services |
30 | #Shutdown all openstack modules | 29 | . service-shutdown |
31 | bash service-shutdown | 30 | #Re-generate configuration files from template files |
32 | #Use chefsolo to bake our recipe and generate configuration files/scripts | 31 | . run-openstackchef |
33 | chef-solo -f -c config.rb -j attributes.json | 32 | #Run post-install script and then start services |
34 | #Workaround to force the files to be copied from postinsts dir | 33 | . run-postinsts |
35 | chef-solo -f -c config.rb -j attributes.json | ||
36 | #Restart services | ||
37 | bash run-postinsts /etc/%POSTINSTS_DIR%/ | ||
diff --git a/meta-openstack/recipes-support/deploychef/files/run-openstackchef b/meta-openstack/recipes-support/deploychef/files/run-openstackchef new file mode 100644 index 0000000..18e6a68 --- /dev/null +++ b/meta-openstack/recipes-support/deploychef/files/run-openstackchef | |||
@@ -0,0 +1,30 @@ | |||
1 | #!/bin/bash | ||
2 | # run-openstackchef | ||
3 | # | ||
4 | # Copyright (c) 2014 Wind River Systems, Inc. | ||
5 | # | ||
6 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | # of this software and associated documentation files (the "Software"), to deal | ||
8 | # in the Software without restriction, including without limitation the rights | ||
9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | # copies of the Software, and to permit persons to whom the Software is | ||
11 | # furnished to do so, subject to the following conditions: | ||
12 | # | ||
13 | # The above copyright notice and this permission notice shall be included in | ||
14 | # all copies or substantial portions of the Software. | ||
15 | |||
16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
22 | # THE SOFTWARE. | ||
23 | # | ||
24 | # | ||
25 | # This script just runs chefsolo to generate our configuration files | ||
26 | # | ||
27 | # | ||
28 | #Use chefsolo to generate configuration files/scripts base on | ||
29 | #templates if templates/default | ||
30 | chef-solo -f -c config.rb -j attributes.json | ||
diff --git a/meta-openstack/recipes-support/deploychef/files/run-postinsts b/meta-openstack/recipes-support/deploychef/files/run-postinsts index 35d46f0..737012d 100644 --- a/meta-openstack/recipes-support/deploychef/files/run-postinsts +++ b/meta-openstack/recipes-support/deploychef/files/run-postinsts | |||
@@ -25,40 +25,10 @@ | |||
25 | # to run the posinstall script and start the services | 25 | # to run the posinstall script and start the services |
26 | # | 26 | # |
27 | # | 27 | # |
28 | RPM_POSTINSTS_DIR=$1 | 28 | source /opt/deploychef/deploychef-inc |
29 | LOG_DIR='/var/log/%PACKAGE_NAME%/' | 29 | #Run postinsts scripts |
30 | mkdir -p $LOG_DIR | 30 | execute_all_postinsts |
31 | if [ ! -d $RPM_POSTINSTS_DIR ]; then | ||
32 | echo "Post Install script dir not set" | ||
33 | exit 1 | ||
34 | fi | ||
35 | cd / #work-around for cinder-volume config file location | ||
36 | echo "x$RPM_POSTINSTS_DIR" > "$LOD_DIR"log.run-postinsts | ||
37 | for i in `ls $RPM_POSTINSTS_DIR 2> /dev/null`; do | ||
38 | i=$RPM_POSTINSTS_DIR$i | ||
39 | echo "Running postinst $i..." | ||
40 | if [ -f $i ] && $i; then | ||
41 | rm $i | ||
42 | else | ||
43 | echo "ERROR: postinst $i failed. $? " >> "$LOG_DIR"log.run-postinsts | ||
44 | fi | ||
45 | done | ||
46 | |||
47 | |||
48 | #Start all the modules specified in startup-list | 31 | #Start all the modules specified in startup-list |
49 | INITD_DIR=/etc/init.d/ | 32 | start_stop_services 'startup-list' |
50 | services=$(cat %DEPLOYCHEF_ROOT_DIR%/startup-list) | ||
51 | for service in $services; do | ||
52 | service=$(echo $service | awk -F'S..' '{print $2}') | ||
53 | if [ -e $INITD_DIR$service ]; then | ||
54 | if [ $service = 'cinder-volume' ]; then | ||
55 | $INITD_DIR$service reload | ||
56 | else | ||
57 | $INITD_DIR$service start | ||
58 | fi | ||
59 | sleep 1 | ||
60 | fi | ||
61 | done | ||
62 | |||
63 | #Restart cloud service cloud-init | 33 | #Restart cloud service cloud-init |
64 | /etc/init.d/cloud-init start | 34 | /etc/init.d/cloud-init start |
diff --git a/meta-openstack/recipes-support/deploychef/files/service-shutdown b/meta-openstack/recipes-support/deploychef/files/service-shutdown index b89f9fa..00b571f 100644 --- a/meta-openstack/recipes-support/deploychef/files/service-shutdown +++ b/meta-openstack/recipes-support/deploychef/files/service-shutdown | |||
@@ -22,33 +22,20 @@ | |||
22 | # THE SOFTWARE. | 22 | # THE SOFTWARE. |
23 | # | 23 | # |
24 | # | 24 | # |
25 | INITD_DIR=/etc/init.d/ | 25 | source /opt/deploychef/deploychef-inc |
26 | services=$(cat %DEPLOYCHEF_ROOT_DIR%/shutdown-list) | ||
27 | for service in $services; do | ||
28 | service=$(echo $service | awk -F'K..' '{print $2}') | ||
29 | if [ -e $INITD_DIR$service ]; then | ||
30 | $INITD_DIR$service stop | ||
31 | sleep 1 | ||
32 | fi | ||
33 | done | ||
34 | 26 | ||
27 | make_log_dir | ||
28 | start_stop_services 'shutdown-list' | ||
35 | #Clean up swift installation and all stale files | 29 | #Clean up swift installation and all stale files |
36 | /etc/swift/swift_setup.sh clean | 30 | if [ -f /etc/swift/swift_setup.sh ]; then |
37 | 31 | /etc/swift/swift_setup.sh clean | |
38 | #Delete all the know data base entries | 32 | fi |
39 | databases="ceilometer cinder glance heat keystone nova ovs_neutron \ | 33 | #Now stop postgresql and delete database directory |
40 | postgres" | 34 | if [ -e ${INITD_DIR}/postgresql ]; then |
41 | for database in $databases; do | 35 | ${INITD_DIR}/postgresql stop |
42 | sudo -u postgres dropdb $database | 36 | killall postgres & |
43 | sleep 1 | 37 | wait |
44 | done | 38 | rm -rf /etc/postgresql & |
45 | 39 | wait | |
46 | #Now shutdown postgres and database directory | ||
47 | if [ -e ${INITD_DIR}postgresql ]; then | ||
48 | ${INITD_DIR}postgresql stop | ||
49 | killall postgres | ||
50 | sleep 1 | ||
51 | rm -rf /etc/postgresql | ||
52 | sleep 1 | ||
53 | fi | 40 | fi |
54 | 41 | ||