From 261f7f857503d7dcd7dcdc4c36aeff1b57194f9b Mon Sep 17 00:00:00 2001 From: Mustapha Lansana Date: Wed, 30 Jul 2014 19:32:37 -0400 Subject: 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 --- .../recipes-support/deploychef/deploychef_0.1.bb | 83 ++++------- .../deploychef/files/default_recipe.rb | 160 +++++++++++++++++++++ .../deploychef/files/deploychef-inc | 82 +++++++++++ .../deploychef/files/deploychef.init | 33 +++-- .../deploychef/files/run-deploychef | 22 ++- .../deploychef/files/run-openstackchef | 30 ++++ .../recipes-support/deploychef/files/run-postinsts | 38 +---- .../deploychef/files/service-shutdown | 39 ++--- 8 files changed, 347 insertions(+), 140 deletions(-) create mode 100644 meta-openstack/recipes-support/deploychef/files/default_recipe.rb create mode 100644 meta-openstack/recipes-support/deploychef/files/deploychef-inc create mode 100644 meta-openstack/recipes-support/deploychef/files/run-openstackchef (limited to 'meta-openstack/recipes-support') 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" LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" -PR = "r0" +PR = "r1" -require deploychef.inc RDEPENDS_${PN} = "chef" SRC_URI = "\ file://deploychef.init \ file://attributes.json \ file://config.rb \ + file://default_recipe.rb \ + file://run-openstackchef \ file://run-postinsts \ file://run-deploychef \ file://service-shutdown \ - file://startup-list \ - file://shutdown-list \ - file://chefsolo_default_attribute.rb \ - file://chefsolo_default_recipe.rb \ - file://conf-templates/* \ + file://deploychef-inc \ " inherit update-rc.d identity hosts default_configs @@ -38,11 +35,12 @@ S = "${WORKDIR}" #Since this package does not need to be ran for each boot-up #There is no need for an init scrpt so install it in /opt/${BPN} DEPLOYCHEF_ROOT_DIR ?= "/opt/${BPN}" +POSTINSTS_DIR ?= "rpm-postinsts" + #Provide a mechanism for these strings to be over-written if necessary COOKBOOK_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/" ATTRIBUTE_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/attributes/" RECIPE_DIR = "${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/recipes/" -TEMPLATES_CONF_DIR = "${DEPLOYCHEF_ROOT_DIR}/conf-templates/" FILES_${PN} += " \ ${DEPLOYCHEF_ROOT_DIR}/* \ @@ -50,8 +48,8 @@ FILES_${PN} += " \ ${DEPLOYCHEF_ROOT_DIR}/cookbooks/* \ ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/recipes/* \ ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/* \ - ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/default/* \ - ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/default/excluded/* \ + ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/templates/default \ + ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/attributes \ ${DEPLOYCHEF_ROOT_DIR}/cookbooks/openstack/attributes/* \ " #Read the module config files and make them into @@ -65,65 +63,34 @@ do_install() { install -d ${D}/${DEPLOYCHEF_ROOT_DIR} #Copy the template configuration scripts to image directory - cp -r ${S}/conf-templates ${D}/${DEPLOYCHEF_ROOT_DIR} - install -m 0755 ${S}/generate-templates ${D}/${DEPLOYCHEF_ROOT_DIR} install -m 0644 ${S}/config.rb ${D}/${DEPLOYCHEF_ROOT_DIR}/config.rb install -m 0644 ${S}/attributes.json ${D}/${DEPLOYCHEF_ROOT_DIR}/attributes.json - install -m 0644 ${S}/run-postinsts ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts - install -m 0644 ${S}/shutdown-list ${D}/${DEPLOYCHEF_ROOT_DIR}/shutdown-list + install -m 0755 ${S}/run-postinsts ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts + install -m 0755 ${S}/run-openstackchef ${D}/${DEPLOYCHEF_ROOT_DIR}/run-openstackchef install -m 0755 ${S}/run-deploychef ${D}/${DEPLOYCHEF_ROOT_DIR}/run-deploychef - install -m 0644 ${S}/service-shutdown ${D}/${DEPLOYCHEF_ROOT_DIR}/service-shutdown - install -m 0644 ${S}/startup-list ${D}/${DEPLOYCHEF_ROOT_DIR}/startup-list - #Copy the respective services configuration script files and convert them to - #chefsolo recipes - install -d ${D}/${ATTRIBUTE_DIR} - install -m 0644 ${S}/chefsolo_default_attribute.rb ${D}/${ATTRIBUTE_DIR}/default.rb - + install -m 0755 ${S}/service-shutdown ${D}/${DEPLOYCHEF_ROOT_DIR}/service-shutdown + install -m 0644 ${S}/deploychef-inc ${D}/${DEPLOYCHEF_ROOT_DIR}/deploychef-inc + #Copy the chefsolo recipe file to chefsolo recipe folder install -d ${D}/${RECIPE_DIR} - install -m 0644 ${S}/chefsolo_default_recipe.rb ${D}/${RECIPE_DIR}/default.rb + install -m 0644 ${S}/default_recipe.rb ${D}/${RECIPE_DIR}/default.rb fi } do_install_append() { - sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${sysconfdir}/init.d/${BPN} - #Replace all the place holders in the respective files - sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${ATTRIBUTE_DIR}default.rb - sed -i s:%SYSCONFDIR%:${sysconfdir}:g ${D}/${ATTRIBUTE_DIR}default.rb - sed -i s:%SYSCONFDIR%:${sysconfdir}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/generate-templates - sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/generate-templates - #chef-solo requires location of script files to be absolute, provide absolute path - sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/service-shutdown - sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts - sed -i s:%PACKAGE_NAME%:${BPN}:g ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts - #Populate chefsolo attribute file and - #Populate deploychef.inc file used in the generation of chefsolo templates - for file in ${D}/${ATTRIBUTE_DIR}default.rb ${D}/${TEMPLATES_CONF_DIR}/constants.inc; do - sed -i s:%CONTROLLER_IP%:${CONTROLLER_IP}:g $file - sed -i s:%CONTROLLER_HOST%:${CONTROLLER_HOST}:g $file - sed -i s:%COMPUTE_IP%:${COMPUTE_IP}:g $file - sed -i s:%COMPUTE_HOST%:${COMPUTE_HOST}:g $file - sed -i s:%ADMIN_PASSWORD%:${ADMIN_PASSWORD}:g $file - sed -i s:%ADMIN_USER%:${ADMIN_USER}:g $file - sed -i s:%SERVICE_PASSWORD%:${SERVICE_PASSWORD}:g $file - sed -i s:%SERVICE_TENANT_NAME%:${SERVICE_TENANT_NAME}:g $file - sed -i s:%SERVICE_USER%:${SERVICE_USER}:g $file - sed -i s:%SERVICE_TOKEN%:${SERVICE_TOKEN}:g $file - sed -i s:%DEMO_USER%:${DEMO_USER}:g $file - sed -i s:%DEMO_PASSWORD%:${DEMO_PASSWORD}:g $file - sed -i s:%OS_TENANT_NAME%:${OS_TENANT_NAME}:g $file - sed -i s:%OS_USERNAME%:${OS_USERNAME}:g $file - sed -i s:%OS_PASSWORD%:${OS_PASSWORD}:g $file - sed -i s:%DB_NAME%:${DB_NAME}:g $file - sed -i s:%DB_USER%:${DB_USER}:g $file - sed -i s:%DB_PASSWORD%:${DB_PASSWORD}:g $file - done + #Replace all required placeholders + for file in "${D}/${DEPLOYCHEF_ROOT_DIR}/run-deploychef \ + ${D}/${DEPLOYCHEF_ROOT_DIR}/service-shutdown \ + ${D}/${DEPLOYCHEF_ROOT_DIR}/deploychef-inc \ + ${D}/${DEPLOYCHEF_ROOT_DIR}/run-postinsts \ + ${D}/${DEPLOYCHEF_ROOT_DIR}/run-openstackchef \ + ${D}/${RECIPE_DIR}/default.rb \ + ${D}/${sysconfdir}/init.d/${BPN} "; do - #Replace the rpm-postinsts dir - for file in "${D}/${ATTRIBUTE_DIR}default.rb \ - ${D}/${DEPLOYCHEF_ROOT_DIR}/run-deploychef \ - ${D}/${DEPLOYCHEF_ROOT_DIR}/generate-templates"; do + sed -i s:%SYSCONFDIR%:${sysconfdir}:g $file sed -i s:%POSTINSTS_DIR%:${POSTINSTS_DIR}:g $file + sed -i s:%PACKAGE_NAME%:${BPN}:g $file + sed -i s:%DEPLOYCHEF_ROOT_DIR%:${DEPLOYCHEF_ROOT_DIR}:g $file done } 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 @@ +# default.rb +# +# Copyright (c) 2014 Wind River Systems, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# This is our main recipe that chef-solo bakes to configure our openstack deployment +require 'find' +domain = node['hostname'] +domain += " " + node['platform'] +domain += " " + node['platform_version'] +domain += " " + node['ipaddress'] +log domain do + level:info +end + +#The definition of IMAGES_ROOTS is to facilitate switching between development +#environment and run-time environment +node.default["IMAGE_ROOTFS"] = "" +#node.default["IMAGE_ROOTFS"] = "/opt/rootfs/TestDeploychef" +node.default["DEPLOYCHEF_ROOT_DIR"] = "#{node[:IMAGE_ROOTFS]}/opt/deploychef" +node.default["DEPLOYCHEF_TEMPLATE_DIR"] = "#{node[:DEPLOYCHEF_ROOT_DIR]}/cookbooks/openstack/templates/default" + +node.default["ETC_DIR"]= "#{node[:IMAGE_ROOTFS]}/etc" +node.default["INITD_DIR"]= "#{node[:ETC_DIR]}/init.d" +node.default["POSTINSTS_DIR"]= "#{node[:ETC_DIR]}/rpm-postinsts" +node.default["CONTROLLER_DAEMON"]= "#{node[:INITD_DIR]}/nova-api" +node.default["COMPUTE_DAEMON"]= "#{node[:INITD_DIR]}/nova-compute" + +#Indicate whether or not we successfully created the configuration files +#from templates. +$chefsolo_success = false +#This function enables us to over-ride the hostname and ip address +#attributes based on the type of node installation +#we are running on. +def update_ip_and_hostname() + if File.executable?(node[:CONTROLLER_DAEMON]) and \ + File.executable?(node[:COMPUTE_DAEMON]) + #All in one installation + if node[:ipaddress].length + node.default["CONTROLLER_IP"]=node.default["COMPUTE_IP"]=node.default["PUBLIC_IP"]=node[:ipaddress] + end + if node[:hostname].length + node.default["CONTROLLER_HOST"]=node.default["COMPUTE_HOST"]=node[:hostname] + end + node.default["NODE_TYPE"] ="allinone" + elsif File.executable?(node[:CONTROLLER_DAEMON]) + if node[:ipaddress].length + node.default["CONTROLLER_IP"]=node.default["PUBLIC_IP"]=node[:ipaddress] + end + if node[:hostname].length + node.default["CONTROLLER_HOST"]=node[:hostname] + end + node.default["NODE_TYPE"] ="controller" + else + if node[:ipaddress].length + node.default["COMPUTE_IP"]=node.default["PUBLIC_IP"]=node[:ipaddress] + end + if node[:hostname].length + node.default["COMPUTE_HOST"]=node[:hostname] + end + node.default["NODE_TYPE"] ="compute" + end + #Both private and public IP's default to an empty string in ceph + #So provide default values when this is the case + if not #{default[:PRIVATE_IP]}.length + node.default["PRIVATE_IP"]="127.0.0.1" + end + node.default["PUBIC_DOMAIN"]="#{node[:PUBLIC_IP]}/24" +end + +def make_config_files_from_templates() + #Make it easier to move from development environment to target + output_dir = node[:ETC_DIR] + template_dir = node[:DEPLOYCHEF_TEMPLATE_DIR] + '/etc' + #See if output directory exist if not create one + if not File.directory?(output_dir) + execute "Create #{output_dir} #{template_dir} directory" do + command "mkdir -p #{output_dir}" + end + end + #Get the list of all template files and create their corresponding config + #files + dirs = Dir.glob(template_dir) + for dir in dirs do + next if File.file?(dir) or dir == '.' or dir == '..' + Find.find(dir) do | file_name | + if File.file?(file_name) + abs_path_conf_file = "#{file_name}" + if abs_path_conf_file.include?(".erb.") + abs_path_conf_file, throw_away = abs_path_conf_file.split(".erb") + else + abs_path_conf_file.gsub!(".erb","") + end + base_path, abs_path_conf_file = abs_path_conf_file.split('/default') + base_path = node[:IMAGE_ROOTFS] + File.dirname(abs_path_conf_file) + abs_path_conf_file = "#{base_path}/" + File.basename(abs_path_conf_file) + #This test is only true for test bed but for sake of portability + #we leave it in place + if not File.exist?(base_path) + execute "Creating conf file dir: #{abs_path_conf_file}" do + command "mkdir -p #{base_path}" + end + elsif File.exist?(abs_path_conf_file) + execute "Delete file to force recreation: #{abs_path_conf_file}" do + command "rm -f #{abs_path_conf_file}" + end + end + execute "Created file: #{base_path}: #{abs_path_conf_file}" do + command "echo #{abs_path_conf_file}" + end + if File.executable?(file_name) + template abs_path_conf_file do + source File.basename(file_name) + #Preserve mode, owner and group + mode "0755" + end + else + template abs_path_conf_file do + source File.basename(file_name) + #Preserve mode, owner and group + mode "0644" + end + end + $chefsolo_success = true + end + end + end + if $chefsolo_success + execute "Make the postinsts script executables" do + command "touch #{node[:ETC_DIR]}/chefsolo.ran" + end + end +end + +#Generate scripts and cofiguration files +update_ip_and_hostname +make_config_files_from_templates + +=begin +service host[:hostname] do + action :restart +endf +=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 @@ +#!/bin/sh +# deploychef_inc +# +# Copyright (c) 2014 Wind River Systems, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +#This file is a helper file that implements functions +#used by the service-shutdown and run-postinsts scripts for +#the deploychef package. + +RPM_POSTINSTS_DIR=%SYSCONFDIR%/rpm-postinsts +LOG_DIR='/var/log/%PACKAGE_NAME%' +LOG_FILE=$LOG_DIR/deploychef.log +INITD_DIR=/etc/init.d + +make_log_dir() { + if [ ! -d $RPM_POSTINSTS_DIR ]; then + mkdir -p $LOG_DIR + echo "Log dir: $LOG_DIR created" > $LOG_FILE + fi +} + +execute_all_postinsts(){ + cd / #work-around for cinder-volume config file location + echo "x$RPM_POSTINSTS_DIR" >> "$LOD_FILE" + for i in `ls $RPM_POSTINSTS_DIR/ 2> /dev/null`; do + i=$RPM_POSTINSTS_DIR/$i + echo "Running postinst $i..." >> $LOG_FILE + if [ -f $i ] && $i; then + rm $i + else + echo "ERROR: postinst $i failed. $? " >> $LOG_FILE + fi + done +} + +#Start/stop services pass in first argument as startup-list or shutdown-list +start_stop_services(){ + dir_name=%DEPLOYCHEF_ROOT_DIR% + file_name=$dir_name/$1 + if [ -f $file_name ]; then + services=$(sort -d $file_name) + for service in $services; do + start_stop=$(echo $service | awk -F'[0-9]+' '{print $1}') + service=$(echo $service | awk -F'[SK][0-9]+' '{print $2}') + if [ $service != postgresql ]; then + if [ $start_stop = 'S' ]; then + if [ -e $INITD_DIR/$service ]; then + echo "Starting $INITD_DIR/$service" >> $LOG_FILE + if [ $service = 'cinder-volume' ]; then + $INITD_DIR/$service reload & + else + $INITD_DIR/$service start & + fi + wait + fi + else + echo "Stopping $INITD_DIR/$service" >> $LOG_FILE + $INITD_DIR/$service stop & + wait + fi + fi + done + fi +} 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 @@ #!/bin/bash -#After this script runs, chefsolo postinsts templates -#script will all be in chefsolo default templates directory -i=%DEPLOYCHEF_ROOT_DIR%/generate-templates -if [ -f $i ] && $i; then - echo "Chefsolo templates made successfully" - rm -f /etc/rcS.d/S96deploychef - rm -f $i -else - echo "ERROR: $i failed." +#After this script executes, it runs the 'run-openstackchef' script found in +#/opt/deploychef/ directory. After that, all the +#configuration files that were registered with openstackchef class are +#created using run-time environment variables and default values +# found in /opt/deploychef/cookbooks/openstack/attributes/default.rb +deploychef_root=%DEPLOYCHEF_ROOT_DIR% +LOG_DIR=/var/log/%PACKAGE_NAME% +LOG_FILE=$LOG_DIR/%PACKAGE_NAME%.log +script_file=$deploychef_root/run-openstackchef +chefsolo_success_file="%SYSCONFDIR%/chefsolo.ran" +if [ ! -f $chefsolo_success_file ]; then + if [ -f $script_file ] ; then + mkdir -p $LOG_DIR + #Remove deploy init script if present + rm -f /etc/init.d/deploy 2>/dev/null + cd $deploychef_root + . $(basename $script_file) + if [ $? = 0 ]; then + echo "Deploychef successfully created chefsolo configuration files" \ + > $LOG_FILE + else + echo "deploychef ERROR: $i failed." > $LOG_FILE + fi + fi 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 @@ #!/bin/bash -# run-chefsolo +# run-deploychef # # Copyright (c) 2014 Wind River Systems, Inc. # @@ -22,16 +22,12 @@ # THE SOFTWARE. # # -# This file is the main file that the install will call in order to reconfig -# and Openstack node -# bash run-chefsolo +# This file is the main script file that reconfigures the stack when any of +# the attributes variables change at run-time. # -# -#Shutdown all openstack modules -bash service-shutdown -#Use chefsolo to bake our recipe and generate configuration files/scripts -chef-solo -f -c config.rb -j attributes.json -#Workaround to force the files to be copied from postinsts dir -chef-solo -f -c config.rb -j attributes.json -#Restart services -bash run-postinsts /etc/%POSTINSTS_DIR%/ +#Shutdown all registered services +. service-shutdown +#Re-generate configuration files from template files +. run-openstackchef +#Run post-install script and then start services +. run-postinsts 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 @@ +#!/bin/bash +# run-openstackchef +# +# Copyright (c) 2014 Wind River Systems, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# +# This script just runs chefsolo to generate our configuration files +# +# +#Use chefsolo to generate configuration files/scripts base on +#templates if templates/default +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 @@ # to run the posinstall script and start the services # # -RPM_POSTINSTS_DIR=$1 -LOG_DIR='/var/log/%PACKAGE_NAME%/' -mkdir -p $LOG_DIR -if [ ! -d $RPM_POSTINSTS_DIR ]; then - echo "Post Install script dir not set" - exit 1 -fi -cd / #work-around for cinder-volume config file location -echo "x$RPM_POSTINSTS_DIR" > "$LOD_DIR"log.run-postinsts -for i in `ls $RPM_POSTINSTS_DIR 2> /dev/null`; do - i=$RPM_POSTINSTS_DIR$i - echo "Running postinst $i..." - if [ -f $i ] && $i; then - rm $i - else - echo "ERROR: postinst $i failed. $? " >> "$LOG_DIR"log.run-postinsts - fi -done - - +source /opt/deploychef/deploychef-inc +#Run postinsts scripts +execute_all_postinsts #Start all the modules specified in startup-list -INITD_DIR=/etc/init.d/ -services=$(cat %DEPLOYCHEF_ROOT_DIR%/startup-list) -for service in $services; do - service=$(echo $service | awk -F'S..' '{print $2}') - if [ -e $INITD_DIR$service ]; then - if [ $service = 'cinder-volume' ]; then - $INITD_DIR$service reload - else - $INITD_DIR$service start - fi - sleep 1 - fi -done - +start_stop_services 'startup-list' #Restart cloud service cloud-init /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 @@ # THE SOFTWARE. # # -INITD_DIR=/etc/init.d/ -services=$(cat %DEPLOYCHEF_ROOT_DIR%/shutdown-list) -for service in $services; do - service=$(echo $service | awk -F'K..' '{print $2}') - if [ -e $INITD_DIR$service ]; then - $INITD_DIR$service stop - sleep 1 - fi -done +source /opt/deploychef/deploychef-inc +make_log_dir +start_stop_services 'shutdown-list' #Clean up swift installation and all stale files -/etc/swift/swift_setup.sh clean - -#Delete all the know data base entries -databases="ceilometer cinder glance heat keystone nova ovs_neutron \ - postgres" -for database in $databases; do - sudo -u postgres dropdb $database - sleep 1 -done - -#Now shutdown postgres and database directory -if [ -e ${INITD_DIR}postgresql ]; then - ${INITD_DIR}postgresql stop - killall postgres - sleep 1 - rm -rf /etc/postgresql - sleep 1 +if [ -f /etc/swift/swift_setup.sh ]; then + /etc/swift/swift_setup.sh clean +fi +#Now stop postgresql and delete database directory +if [ -e ${INITD_DIR}/postgresql ]; then + ${INITD_DIR}/postgresql stop + killall postgres & + wait + rm -rf /etc/postgresql & + wait fi -- cgit v1.2.3-54-g00ecf