summaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-support/deploychef/files
diff options
context:
space:
mode:
authorMustapha Lansana <Mustapha.Lansana@windriver.com>2014-07-30 19:32:37 -0400
committerBruce Ashfield <bruce.ashfield@windriver.com>2014-09-26 09:09:21 -0400
commit261f7f857503d7dcd7dcdc4c36aeff1b57194f9b (patch)
tree62bfe5adcc46479e1d864cfa79635060a0e7cdb4 /meta-openstack/recipes-support/deploychef/files
parent48bd378fda4db37b519742bdcf98b6a48f83b594 (diff)
downloadmeta-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>
Diffstat (limited to 'meta-openstack/recipes-support/deploychef/files')
-rw-r--r--meta-openstack/recipes-support/deploychef/files/default_recipe.rb160
-rw-r--r--meta-openstack/recipes-support/deploychef/files/deploychef-inc82
-rw-r--r--meta-openstack/recipes-support/deploychef/files/deploychef.init33
-rw-r--r--meta-openstack/recipes-support/deploychef/files/run-deploychef22
-rw-r--r--meta-openstack/recipes-support/deploychef/files/run-openstackchef30
-rw-r--r--meta-openstack/recipes-support/deploychef/files/run-postinsts38
-rw-r--r--meta-openstack/recipes-support/deploychef/files/service-shutdown39
7 files changed, 322 insertions, 82 deletions
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
24require 'find'
25domain = node['hostname']
26domain += " " + node['platform']
27domain += " " + node['platform_version']
28domain += " " + node['ipaddress']
29log domain do
30 level:info
31end
32
33#The definition of IMAGES_ROOTS is to facilitate switching between development
34#environment and run-time environment
35node.default["IMAGE_ROOTFS"] = ""
36#node.default["IMAGE_ROOTFS"] = "/opt/rootfs/TestDeploychef"
37node.default["DEPLOYCHEF_ROOT_DIR"] = "#{node[:IMAGE_ROOTFS]}/opt/deploychef"
38node.default["DEPLOYCHEF_TEMPLATE_DIR"] = "#{node[:DEPLOYCHEF_ROOT_DIR]}/cookbooks/openstack/templates/default"
39
40node.default["ETC_DIR"]= "#{node[:IMAGE_ROOTFS]}/etc"
41node.default["INITD_DIR"]= "#{node[:ETC_DIR]}/init.d"
42node.default["POSTINSTS_DIR"]= "#{node[:ETC_DIR]}/rpm-postinsts"
43node.default["CONTROLLER_DAEMON"]= "#{node[:INITD_DIR]}/nova-api"
44node.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.
52def 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"
86end
87
88def 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
150end
151
152#Generate scripts and cofiguration files
153update_ip_and_hostname
154make_config_files_from_templates
155
156=begin
157service host[:hostname] do
158 action :restart
159endf
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
28RPM_POSTINSTS_DIR=%SYSCONFDIR%/rpm-postinsts
29LOG_DIR='/var/log/%PACKAGE_NAME%'
30LOG_FILE=$LOG_DIR/deploychef.log
31INITD_DIR=/etc/init.d
32
33make_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
40execute_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
55start_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
4i=%DEPLOYCHEF_ROOT_DIR%/generate-templates 4#configuration files that were registered with openstackchef class are
5if [ -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 7deploychef_root=%DEPLOYCHEF_ROOT_DIR%
8 rm -f $i 8LOG_DIR=/var/log/%PACKAGE_NAME%
9else 9LOG_FILE=$LOG_DIR/%PACKAGE_NAME%.log
10 echo "ERROR: $i failed." 10script_file=$deploychef_root/run-openstackchef
11chefsolo_success_file="%SYSCONFDIR%/chefsolo.ran"
12if [ ! -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
11fi 26fi
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
31bash 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
33chef-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
35chef-solo -f -c config.rb -j attributes.json
36#Restart services
37bash 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
30chef-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#
28RPM_POSTINSTS_DIR=$1 28source /opt/deploychef/deploychef-inc
29LOG_DIR='/var/log/%PACKAGE_NAME%/' 29#Run postinsts scripts
30mkdir -p $LOG_DIR 30execute_all_postinsts
31if [ ! -d $RPM_POSTINSTS_DIR ]; then
32 echo "Post Install script dir not set"
33 exit 1
34fi
35cd / #work-around for cinder-volume config file location
36echo "x$RPM_POSTINSTS_DIR" > "$LOD_DIR"log.run-postinsts
37for 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
45done
46
47
48#Start all the modules specified in startup-list 31#Start all the modules specified in startup-list
49INITD_DIR=/etc/init.d/ 32start_stop_services 'startup-list'
50services=$(cat %DEPLOYCHEF_ROOT_DIR%/startup-list)
51for 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
61done
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#
25INITD_DIR=/etc/init.d/ 25source /opt/deploychef/deploychef-inc
26services=$(cat %DEPLOYCHEF_ROOT_DIR%/shutdown-list)
27for 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
33done
34 26
27make_log_dir
28start_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 30if [ -f /etc/swift/swift_setup.sh ]; then
37 31 /etc/swift/swift_setup.sh clean
38#Delete all the know data base entries 32fi
39databases="ceilometer cinder glance heat keystone nova ovs_neutron \ 33#Now stop postgresql and delete database directory
40 postgres" 34if [ -e ${INITD_DIR}/postgresql ]; then
41for database in $databases; do 35 ${INITD_DIR}/postgresql stop
42 sudo -u postgres dropdb $database 36 killall postgres &
43 sleep 1 37 wait
44done 38 rm -rf /etc/postgresql &
45 39 wait
46#Now shutdown postgres and database directory
47if [ -e ${INITD_DIR}postgresql ]; then
48 ${INITD_DIR}postgresql stop
49 killall postgres
50 sleep 1
51 rm -rf /etc/postgresql
52 sleep 1
53fi 40fi
54 41