diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/COPYING @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a312aac --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +#!/usr/bin/make -f +# +# Makefile for the OpenStack resource agents toolsuite +# +# Copyright (C) 2012 hastexo Professional Services GmbH +# +# 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. + +# define some common variables +INSTALL = /usr/bin/install + +install: + mkdir -p $(DESTDIR)/resource.d/openstack + for file in ocf/*; do \ + $(INSTALL) -t $(DESTDIR)/usr/lib/ocf/resource.d/openstack -m 0755 $${file} ; \ + done diff --git a/ocf/glance-api b/ocf/glance-api new file mode 100644 index 0000000..8b129b3 --- /dev/null +++ b/ocf/glance-api @@ -0,0 +1,367 @@ +#!/bin/sh +# +# +# OpenStack ImageService (glance-api) +# +# Description: Manages an OpenStack ImageService (glance-api) process as an HA resource +# +# Authors: Martin Gerhard Loschwitz +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# (c) 2012 hastexo Professional Services GmbH +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_client_binary +# OCF_RESKEY_config +# OCF_RESKEY_os_username +# OCF_RESKEY_os_password +# OCF_RESKEY_os_tenant_name +# OCF_RESKEY_os_auth_url +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="glance-api" +OCF_RESKEY_config_default="/etc/glance/glance-api.conf" +OCF_RESKEY_user_default="glance" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_client_binary_default="glance" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_client_binary=${OCF_RESKEY_client_binary_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack ImageService Service (glance-api) +May manage a glance-api instance or a clone set that +creates a distributed glance-api cluster. + +Manages the OpenStack ImageService (glance-api) + + + + +Location of the OpenStack ImageService server binary (glance-api) + +OpenStack ImageService server binary (glance-api) + + + + + +Location of the OpenStack ImageService (glance-api) configuration file + +OpenStack ImageService (glance registry) config file + + + + + +User running OpenStack ImageService (glance-api) + +OpenStack ImageService (glance-api) user + + + + + +The pid file to use for this OpenStack ImageService (glance-api) instance + +OpenStack ImageService (glance-api) pid file + + + + + +The username to use when logging into ImageService (glance-api) for monitoring purposes + +ImageService (glance-api) monitoring login + + + + + +The password to use when logging into ImageService (glance-api) for monitoring purposes + +ImageService (glance-api) monitoring password + + + + + +The tenant to use when logging into ImageService (glance-api) for monitoring purposes + +ImageService (glance-api) monitoring tenant + + + + + +The URL pointing to this ImageService (glance-api) instance to use when logging in for monitoring purposes + +ImageService (glance-api) URL for monitoring login + + + + + +Location of the OpenStack ImageService client binary (glance) + +OpenStack ImageService server binary (glance) + + + + + +Additional parameters to pass on to the OpenStack ImageService (glance-api) + +Additional parameters for glance-api + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +glance_api_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +glance_api_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack ImageService (glance-api) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack ImageService (glance-api) is not running" + return $OCF_NOT_RUNNING + fi +} + +glance_api_monitor() { + local rc + local token + + glance_api_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into glance-api + # and do it if that's the case. + if [ -n "$OCF_RESKEY_os_username" ] && [ -n "$OCF_RESKEY_os_password" ] \ + && [ -n "$OCF_RESKEY_os_tenant_name" ] && [ -n "$OCF_RESKEY_os_auth_url" ]; then + if ! check_binary $OCF_RESKEY_client_binary; then ocf_log warn "$OCF_RESKEY_client_binary \ + missing, can not monitor!" else + ocf_run -q $OCF_RESKEY_client_binary \ + --username "$OCF_RESKEY_os_username" \ + --password "$OCF_RESKEY_os_password" \ + --tenant_name "$OCF_RESKEY_os_tenant_name" \ + --auth_url "$OCF_RESKEY_os_auth_url" \ + index > /dev/null 2>&1; fi + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "Failed to connect to the OpenStack ImageService (glance-api): $rc" + return $OCF_NOT_RUNNING + fi + fi + + ocf_log debug "OpenStack ImageService (glance-api) monitor succeeded" + return $OCF_SUCCESS +} + +glance_api_start() { + local rc + + glance_api_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack ImageService (glance-api) already running" + return $OCF_SUCCESS + fi + + # run the actual glance-api daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --config-file $OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + while true; do + glance_api_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack ImageService (glance-api) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack ImageService (glance-api) started" + return $OCF_SUCCESS +} + +glance_api_stop() { + local rc + local pid + + glance_api_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack ImageService (glance-api) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack ImageService (glance-api) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + glance_api_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack ImageService (glance-api) still hasn't stopped yet. Waiting ..." + done + + glance_api_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack ImageService (glance-api) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack ImageService (glance-api) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +glance_api_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) glance_api_start;; + stop) glance_api_stop;; + status) glance_api_status;; + monitor) glance_api_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac diff --git a/ocf/glance-registry b/ocf/glance-registry new file mode 100644 index 0000000..4f2db89 --- /dev/null +++ b/ocf/glance-registry @@ -0,0 +1,381 @@ +#!/bin/sh +# +# +# OpenStack ImageService (glance-registry) +# +# Description: Manages an OpenStack ImageService (glance-registry) process as an HA resource +# +# Authors: Martin Gerhard Loschwitz +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# (c) 2012 hastexo Professional Services GmbH +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_os_username +# OCF_RESKEY_os_password +# OCF_RESKEY_os_tenant_name +# OCF_RESKEY_os_auth_url +# OCF_RESKEY_keystone_url +# OCF_RESKEY_url +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="glance-registry" +OCF_RESKEY_config_default="/etc/glance/glance-registry.conf" +OCF_RESKEY_user_default="glance" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_url_default="http://127.0.0.1:9191/images" +OCF_RESKEY_keystone_url_default="http://127.0.0.1:5000/v2.0/tokens" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_url=${OCF_RESKEY_url_default}} +: ${OCF_RESKEY_keystone_url=${OCF_RESKEY_keystone_url_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack ImageService Service (glance-registry) +May manage a glance-registry instance or a clone set that +creates a distributed glance-registry cluster. + +Manages the OpenStack ImageService (glance-registry) + + + + +Location of the OpenStack ImageService server binary (glance-registry) + +OpenStack ImageService server binary (glance-registry) + + + + + +Location of the OpenStack ImageService (glance-registry) configuration file + +OpenStack ImageService (glance registry) config file + + + + + +User running OpenStack ImageService (glance-registry) + +OpenStack ImageService (glance-registry) user + + + + + +The pid file to use for this OpenStack ImageService (glance-registry) instance + +OpenStack ImageService (glance-registry) pid file + + + + + +The default URL to use for monitoring this instance (glance-registry) via curl + +OpenStack ImageService (glance-registry) monitor url + + + + + +The default URL to use to acquire a ImageService (glance-registry) token for monitoring this instance +of OpenStack ImageService (glance-registry) + +OpenStack ImageService (glance-registry) url + + + + + +The username to use when connecting with ImageService (glance-registry) for monitoring purposes + +ImageService (glance-registry) monitoring login + + + + + +The password to use when connecting ImageService (glance-registry) for monitoring purposes + +ImageService (glance-registry) monitoring password + + + + + +The tenant to use when connecting ImageService (glance-registry) for monitoring purposes + +ImageService (glance-registry) monitoring tenant + + + + + +The URL pointing to this ImageService (glance-registry) instance to use when connecting for monitoring purposes + +ImageService (glance-registry) URL for monitoring login + + + + + +Additional parameters to pass on to the OpenStack ImageService (glance-registry) + +Additional parameters for glance-registry + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +glance_registry_validate() { + local rc + + check_binary $OCF_RESKEY_binary + check_binary curl + check_binary tr + check_binary grep + check_binary cut + check_binary head + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +glance_registry_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack ImageService (glance-registry) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack ImageService (glance-registry) is not running" + return $OCF_NOT_RUNNING + fi +} + +glance_registry_monitor() { + local rc + local token + + glance_registry_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into glance-registry + # and do it if that's the case. + if [ -n "$OCF_RESKEY_os_username" ] && [ -n "$OCF_RESKEY_os_password" ] \ + && [ -n "$OCF_RESKEY_os_tenant_name" ] && [ -n "$OCF_RESKEY_os_auth_url" ]; then + TOKEN=`curl -s -d "{\"auth\":{\"passwordCredentials\": {\"username\": \"$OCF_RESKEY_os_username\", \ + \"password\": \"$OCF_RESKEY_os_password\"}, \"tenantName\": \"$OCF_RESKEY_os_tenant_name\"}}" \ + -H "Content-type: application/json" $OCF_RESKEY_keystone_url | tr ',' '\n' | grep '"id":' \ + | cut -d'"' -f4 | head --lines 1` + ocf_run -q curl -H "X-Auth-Token: $TOKEN" $OCF_RESKEY_url > /dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "Failed to connect to the OpenStack ImageService (glance-registry): $rc" + return $OCF_NOT_RUNNING + fi + fi + + ocf_log debug "OpenStack ImageService (glance-registry) monitor succeeded" + return $OCF_SUCCESS +} + +glance_registry_start() { + local rc + + glance_registry_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack ImageService (glance-registry) already running" + return $OCF_SUCCESS + fi + + # run the actual glance-registry daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --config-file $OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + while true; do + glance_registry_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack ImageService (glance-registry) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack ImageService (glance-registry) started" + return $OCF_SUCCESS +} + +glance_registry_stop() { + local rc + local pid + + glance_registry_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack ImageService (glance-registry) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack ImageService (glance-registry) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + glance_registry_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack ImageService (glance-registry) still hasn't stopped yet. Waiting ..." + done + + glance_registry_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack ImageService (glance-registry) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack ImageService (glance-registry) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +glance_registry_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) glance_registry_start;; + stop) glance_registry_stop;; + status) glance_registry_status;; + monitor) glance_registry_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac diff --git a/ocf/keystone b/ocf/keystone new file mode 100644 index 0000000..2e6b2dc --- /dev/null +++ b/ocf/keystone @@ -0,0 +1,369 @@ +#!/bin/sh +# +# +# OpenStack Keystone +# +# Description: Manages an OpenStack Keystone process as an HA resource +# +# Authors: Martin Gerhard Loschwitz +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# (c) 2012 hastexo Professional Services GmbH +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_client_binary +# OCF_RESKEY_config +# OCF_RESKEY_os_username +# OCF_RESKEY_os_password +# OCF_RESKEY_os_tenant_name +# OCF_RESKEY_os_auth_url +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="keystone-all" +OCF_RESKEY_config_default="/etc/keystone/keystone.conf" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_user_default="keystone" +OCF_RESKEY_client_binary_default="keystone" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_client_binary=${OCF_RESKEY_client_binary_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack Identity Service (Keystone) +May manage a keystone-all instance or a clone set that +creates a distributed keystone cluster. + +Manages the OpenStack Identity Service (Keystone) + + + + +Location of the OpenStack Identity Service server binary (keystone-all) + +Keystone server binary (keystone-all) + + + + + +Location of the OpenStack Identity Service client binary (keystone) + +Keystone server binary (keystone) + + + + + +Location of the OpenStack Identity Service configuration file + +Keystone configuration file + + + + + +The username to use when logging into Keystone for monitoring purposes + +Keystone monitoring login + + + + + +The password to use when logging into Keystone for monitoring purposes + +Keystone monitoring password + + + + + +The tenant to use when logging into Keystone for monitoring purposes + +Keystone monitoring tenant + + + + + +The URL pointing to this Keystone instance to use when logging in for monitoring purposes + +Keystone URL for monitoring login + + + + + +User running OpenStack Identity (Keystone) + +OpenStack Identity (Keystone) user + + + + + +The pid file to use for this Keystone instance (keystone-all) + +OpenStack Identity (Keystone) pid file + + + + + +Additional parameters to pass on to the Keystone server (keystone-all) + +Additional parameters for the Keystone server + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +keystone_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +keystone_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack Identity (Keystone) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack Identity (Keystone) is not running" + return $OCF_NOT_RUNNING + fi +} + +keystone_monitor() { + local rc + + keystone_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into Keystone + # and do it if that's the case. + if [ -n "$OCF_RESKEY_client_binary" ] && [ -n "$OCF_RESKEY_os_username" ] \ + && [ -n "$OCF_RESKEY_os_password" ] && [ -n "$OCF_RESKEY_os_tenant_name" ] \ + && [ -n "$OCF_RESKEY_os_auth_url" ]; then + if ! check_binary $OCF_RESKEY_client_binary; then + ocf_log warn "$OCF_RESKEY_client_binary missing, can not monitor!" + else + ocf_run -q $OCF_RESKEY_client_binary \ + --username "$OCF_RESKEY_os_username" \ + --password "$OCF_RESKEY_os_password" \ + --tenant_name "$OCF_RESKEY_os_tenant_name" \ + --auth_url "$OCF_RESKEY_os_auth_url" \ + user-list > /dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "Failed to connect to the OpenStack Identity (Keystone): $rc" + return $OCF_NOT_RUNNING + fi + fi + fi + + ocf_log debug "OpenStack Identity (Keystone) monitor succeeded" + return $OCF_SUCCESS +} + +keystone_start() { + local rc + + keystone_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack Identity (Keystone) already running" + return $OCF_SUCCESS + fi + + # run the actual keystone daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --config-file $OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + while true; do + sleep 1 + keystone_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack Identity (Keystone) start failed" + exit $OCF_ERR_GENERIC + fi + done + + ocf_log info "OpenStack Identity (Keystone) started" + return $OCF_SUCCESS +} + +keystone_stop() { + local rc + local pid + + keystone_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack Identity (Keystone) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack Identity (Keystone) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + keystone_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack Identity (Keystone) still hasn't stopped yet. Waiting ..." + done + + keystone_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack Identity (Keystone) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack Identity (Keystone) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +keystone_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) keystone_start;; + stop) keystone_stop;; + status) keystone_status;; + monitor) keystone_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac diff --git a/ocf/nova-api b/ocf/nova-api new file mode 100644 index 0000000..bfcff48 --- /dev/null +++ b/ocf/nova-api @@ -0,0 +1,323 @@ +#!/bin/sh +# +# +# OpenStack NovaAPI (nova-api) +# +# Description: Manages an OpenStack NovaAPI (nova-api) process as an HA resource +# +# Authors: Sébastien Han +# Mainly inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLpr +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_monitor_binary +# OCF_RESKEY_api_listened_port +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="nova-api" +OCF_RESKEY_config_default="/etc/nova/nova.conf" +OCF_RESKEY_user_default="nova" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_monitor_binary_default="netstat" +OCF_RESKEY_api_listened_port_default="8773|8774|8775|8776" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_monitor_binary=${OCF_RESKEY_monitor_binary_default}} +: ${OCF_RESKEY_api_listened_port=${OCF_RESKEY_api_listened_port_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack NovaAPI Service (nova-api) +May manage a nova-api instance or a clone set that +creates a distributed nova-api cluster. + +Manages the OpenStack NovaAPI (nova-api) + + + + +Location of the OpenStack NovaAPI server binary (nova-api) + +OpenStack NovaAPI server binary (nova-api) + + + + + +Location of the OpenStack NovaAPI (nova-api) configuration file + +OpenStack NovaAPI (nova-api registry) config file + + + + + +User running OpenStack NovaAPI (nova-api) + +OpenStack NovaAPI (nova-api) user + + + + + +The pid file to use for this OpenStack NovaAPI (nova-api) instance + +OpenStack NovaAPI (nova-api) pid file + + + + + +Additional parameters to pass on to the OpenStack NovaAPI (nova-api) + +Additional parameters for nova-api + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +nova_api_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +nova_api_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack NovaAPI (nova-api) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack NovaAPI (nova-api) is not running" + return $OCF_NOT_RUNNING + fi +} + +nova_api_monitor() { + local rc + local token + + nova_api_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into nova-api + # and do it if that's the case. + if ! check_binary $OCF_RESKEY_monitor_binary; then + ocf_log warn "$OCF_RESKEY_monitor_binary missing, can not monitor!" + else + # Check ec2, osapi_compute, osapi_volume and metadata ports + API_LIST_CHECK=`"$OCF_RESKEY_monitor_binary" -a | egrep -E "\"$OCF_RESKEY_api_listened_port\"" | grep -q "LISTEN"` + fi + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "Nova API doesn't listen properly: $rc" + return $OCF_NOT_RUNNING + fi + + ocf_log debug "OpenStack NovaAPI (nova-api) monitor succeeded" + return $OCF_SUCCESS +} + +nova_api_start() { + local rc + + nova_api_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack NovaAPI (nova-api) already running" + return $OCF_SUCCESS + fi + + # run the actual nova-api daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --flagfile=$OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + sleep 1 + while true; do + nova_api_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack NovaAPI (nova-api) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack NovaAPI (nova-api) started" + return $OCF_SUCCESS +} + +nova_api_stop() { + local rc + local pid + + nova_api_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack NovaAPI (nova-api) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack NovaAPI (nova-api) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + nova_api_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack NovaAPI (nova-api) still hasn't stopped yet. Waiting ..." + done + + nova_api_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack NovaAPI (nova-api) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack NovaAPI (nova-api) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +nova_api_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) nova_api_start;; + stop) nova_api_stop;; + status) nova_api_status;; + monitor) nova_api_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac + diff --git a/ocf/nova-cert b/ocf/nova-cert new file mode 100644 index 0000000..f756070 --- /dev/null +++ b/ocf/nova-cert @@ -0,0 +1,366 @@ +#!/bin/sh +# +# +# OpenStack Nova Cert (nova-cert) +# +# Description: Manages an OpenStack Nova Cert (nova-cert) process as an HA resource +# +# Authors: Sébastien Han +# Mainly inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLpr +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_monitor_binary +# OCF_RESKEY_database_server_port +# OCF_RESKEY_amqp_server_port +# OCF_RESKEY_zeromq +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="nova-cert" +OCF_RESKEY_config_default="/etc/nova/nova.conf" +OCF_RESKEY_user_default="nova" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_monitor_binary_default="netstat" +OCF_RESKEY_database_server_port_default="3306" +OCF_RESKEY_amqp_server_port_default="5672" +OCF_RESKEY_zeromq_default="false" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_monitor_binary=${OCF_RESKEY_monitor_binary_default}} +: ${OCF_RESKEY_database_server_port=${OCF_RESKEY_database_server_port_default}} +: ${OCF_RESKEY_amqp_server_port=${OCF_RESKEY_amqp_server_port_default}} +: ${OCF_RESKEY_zeromq=${OCF_RESKEY_zeromq_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack Nova Cert Service (nova-cert) +May manage a nova-cert instance or a clone set that +creates a distributed nova-cert cluster. + +Manages the OpenStack Nova Cert (nova-cert) + + + + +Location of the OpenStack Nova Cert server binary (nova-cert) + +OpenStack Nova Cert server binary (nova-cert) + + + + + +Location of the OpenStack Nova Cert (nova-cert) configuration file + +OpenStack Nova Cert (nova-cert registry) config file + + + + + +User running OpenStack Nova Cert (nova-cert) + +OpenStack Nova Cert (nova-cert) user + + + + + +The pid file to use for this OpenStack Nova Cert (nova-cert) instance + +OpenStack Nova Cert (nova-cert) pid file + + + + + +The listening port number of the database server. Mandatory to perform a monitor check + +Database listening port + + + + + +The listening port number of the AMQP server. Mandatory to perform a monitor check + +AMQP listening port + + + + + +If zeromq is used, this will disable the connection test to the AMQP server + +Zero-MQ usage + + + + + +Additional parameters to pass on to the OpenStack Nova Cert (nova-cert) + +Additional parameters for nova-cert + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +nova_cert_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +nova_cert_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack Nova Cert (nova-cert) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack Nova Cert (nova-cert) is not running" + return $OCF_NOT_RUNNING + fi +} + +nova_cert_monitor() { + local rc + local token + + nova_cert_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into nova-cert + # and do it if that's the case. + if ! check_binary $OCF_RESKEY_monitor_binary; then + ocf_log warn "$OCF_RESKEY_monitor_binary missing, can not monitor!" + else + if [ $OCF_RESKEY_zeromq = true ]; then + PID=`cat $OCF_RESKEY_pid` + CERT_DATABASE_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_database_server_port" | grep "$PID" | grep -q "ESTABLISHED"` + rc_database=$? + if [ $rc_database -ne 0 ]; then + ocf_log err "Nova Cert is not connected to the database server: $rc_database" + return $OCF_NOT_RUNNING + fi + else + PID=`cat $OCF_RESKEY_pid` + # check the connections according to the PID + CERT_DATABASE_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_database_server_port" | grep "$PID" | grep -q "ESTABLISHED"` + rc_database=$? + CERT_AMQP_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_amqp_server_port" | grep "$PID" | grep -q "ESTABLISHED"` + rc_amqp=$? + if [ $rc_amqp -ne 0 ] || [ $rc_database -ne 0 ]; then + ocf_log err "Nova Cert is not connected to the AMQP server and/or the database server: AMQP connection test returned $rc_amqp and database connection test returned $rc_database" + return $OCF_NOT_RUNNING + fi + fi + fi + + ocf_log debug "OpenStack Nova Cert (nova-cert) monitor succeeded" + return $OCF_SUCCESS +} + +nova_cert_start() { + local rc + + nova_cert_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack Nova Cert (nova-cert) already running" + return $OCF_SUCCESS + fi + + # run the actual nova-cert daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --flagfile=$OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + sleep 1 + while true; do + nova_cert_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack Nova Cert (nova-cert) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack Nova Cert (nova-cert) started" + return $OCF_SUCCESS +} + +nova_cert_stop() { + local rc + local pid + + nova_cert_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack Nova Cert (nova-cert) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack Nova Cert (nova-cert) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + nova_cert_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack Nova Cert (nova-cert) still hasn't stopped yet. Waiting ..." + done + + nova_cert_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack Nova Cert (nova-cert) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack Nova Cert (nova-cert) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +nova_cert_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) nova_cert_start;; + stop) nova_cert_stop;; + status) nova_cert_status;; + monitor) nova_cert_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac + diff --git a/ocf/nova-consoleauth b/ocf/nova-consoleauth new file mode 100644 index 0000000..fa8b797 --- /dev/null +++ b/ocf/nova-consoleauth @@ -0,0 +1,366 @@ +#!/bin/sh +# +# +# OpenStack Nova ConsoleAuth (nova-consoleauth) +# +# Description: Manages an OpenStack Nova ConsoleAuth (nova-consoleauth) process as an HA resource +# +# Authors: Sébastien Han +# Mainly inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLpr +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_monitor_binary +# OCF_RESKEY_database_server_port +# OCF_RESKEY_amqp_server_port +# OCF_RESKEY_zeromq +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="nova-consoleauth" +OCF_RESKEY_config_default="/etc/nova/nova.conf" +OCF_RESKEY_user_default="nova" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_monitor_binary_default="netstat" +OCF_RESKEY_database_server_port_default="3306" +OCF_RESKEY_amqp_server_port_default="5672" +OCF_RESKEY_zeromq_default="false" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_monitor_binary=${OCF_RESKEY_monitor_binary_default}} +: ${OCF_RESKEY_database_server_port=${OCF_RESKEY_database_server_port_default}} +: ${OCF_RESKEY_amqp_server_port=${OCF_RESKEY_amqp_server_port_default}} +: ${OCF_RESKEY_zeromq=${OCF_RESKEY_zeromq_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack Nova ConsoleAuth Service (nova-consoleauth) +May manage a nova-consoleauth instance or a clone set that +creates a distributed nova-consoleauth cluster. + +Manages the OpenStack Nova ConsoleAuth (nova-consoleauth) + + + + +Location of the OpenStack Nova ConsoleAuth server binary (nova-consoleauth) + +OpenStack Nova ConsoleAuth server binary (nova-consoleauth) + + + + + +Location of the OpenStack Nova ConsoleAuth (nova-consoleauth) configuration file + +OpenStack Nova ConsoleAuth (nova-consoleauth registry) config file + + + + + +User running OpenStack Nova ConsoleAuth (nova-consoleauth) + +OpenStack Nova ConsoleAuth (nova-consoleauth) user + + + + + +The pid file to use for this OpenStack Nova ConsoleAuth (nova-consoleauth) instance + +OpenStack Nova ConsoleAuth (nova-consoleauth) pid file + + + + + +The listening port number of the database server. Mandatory to perform a monitor check + +Database listening port + + + + + +The listening port number of the AMQP server. Mandatory to perform a monitor check + +AMQP listening port + + + + + +If zeromq is used, this will disable the connection test to the AMQP server + +Zero-MQ usage + + + + + +Additional parameters to pass on to the OpenStack Nova ConsoleAuth (nova-consoleauth) + +Additional parameters for nova-consoleauth + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +nova_consoleauth_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +nova_consoleauth_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack Nova ConsoleAuth (nova-consoleauth) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack Nova ConsoleAuth (nova-consoleauth) is not running" + return $OCF_NOT_RUNNING + fi +} + +nova_consoleauth_monitor() { + local rc + local token + + nova_consoleauth_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into nova-consoleauth + # and do it if that's the case. + if ! check_binary $OCF_RESKEY_monitor_binary; then + ocf_log warn "$OCF_RESKEY_monitor_binary missing, can not monitor!" + else + if [ $OCF_RESKEY_zeromq = true ]; then + PID=`cat $OCF_RESKEY_pid` + CONSOLE_DATABASE_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_database_server_port" | grep "$PID" | grep -q "ESTABLISHED"` + rc_database=$? + if [ $rc_database -ne 0 ]; then + ocf_log err "Nova ConsoleAuth is not connected to the database server: $rc_database" + return $OCF_NOT_RUNNING + fi + else + PID=`cat $OCF_RESKEY_pid` + # check the connections according to the PID + CONSOLE_DATABASE_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_database_server_port" | grep "$PID" | grep -q "ESTABLISHED"` + rc_database=$? + CONSOLE_AMQP_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_amqp_server_port" | egrep "$PID" | grep -q "ESTABLISHED"` + rc_amqp=$? + if [ $rc_amqp -ne 0 ] || [ $rc_database -ne 0 ]; then + ocf_log err "Nova ConsoleAuth is not connected to the AMQP server and/or the database server: AMQP connection test returned $rc_amqp and database connection test returned $rc_database" + return $OCF_NOT_RUNNING + fi + fi + fi + + ocf_log debug "OpenStack Nova ConsoleAuth (nova-consoleauth) monitor succeeded" + return $OCF_SUCCESS +} + +nova_consoleauth_start() { + local rc + + nova_consoleauth_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack Nova ConsoleAuth (nova-consoleauth) already running" + return $OCF_SUCCESS + fi + + # run the actual nova-consoleauth daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --flagfile=$OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + sleep 1 + while true; do + nova_consoleauth_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack Nova ConsoleAuth (nova-consoleauth) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack Nova ConsoleAuth (nova-consoleauth) started" + return $OCF_SUCCESS +} + +nova_consoleauth_stop() { + local rc + local pid + + nova_consoleauth_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack Nova ConsoleAuth (nova-consoleauth) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack Nova ConsoleAuth (nova-consoleauth) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + nova_consoleauth_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack Nova ConsoleAuth (nova-consoleauth) still hasn't stopped yet. Waiting ..." + done + + nova_consoleauth_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack Nova ConsoleAuth (nova-consoleauth) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack Nova ConsoleAuth (nova-consoleauth) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +nova_consoleauth_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) nova_consoleauth_start;; + stop) nova_consoleauth_stop;; + status) nova_consoleauth_status;; + monitor) nova_consoleauth_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac + diff --git a/ocf/nova-network b/ocf/nova-network new file mode 100644 index 0000000..ac6c622 --- /dev/null +++ b/ocf/nova-network @@ -0,0 +1,305 @@ +#!/bin/sh +# +# +# OpenStack NovaNetwork (nova-network) +# +# Description: Manages an OpenStack NovaNetwork (nova-network) process as an HA resource +# +# Authors: Alessandro Tagliapietra +# Mainly inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLp +# and the other resource agents by Sebastien Han http://sebastien-han.fr +# +# Website: http://www.alexnetwork.it/ +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="nova-network" +OCF_RESKEY_config_default="/etc/nova/nova.conf" +OCF_RESKEY_user_default="nova" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack NovaNetwork (nova-network) +May manage a nova-network instance or a clone set that +creates a distributed nova-network cluster. + +Manages the OpenStack NovaNetwork (nova-network) + + + + +Location of the OpenStack NovaNetwork server binary (nova-network) + +OpenStack NovaNetwork server binary (nova-network) + + + + + +Location of the OpenStack NovaNetwork (nova-network) configuration file + +OpenStack NovaNetwork (nova-network) config file + + + + + +User running OpenStack NovaNetwork (nova-network) + +OpenStack NovaNetwork (nova-network) user + + + + + +The pid file to use for this OpenStack NovaNetwork (nova-network) instance + +OpenStack NovaNetwork (nova-network) pid file + + + + + +Additional parameters to pass on to the OpenStack NovaNetwork (nova-network) + +Additional parameters for nova-network + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +nova_network_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +nova_network_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack NovaNetwork (nova-network) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack NovaNetwork (nova-network) is not running" + return $OCF_NOT_RUNNING + fi +} + +nova_network_monitor() { + local rc + local token + + nova_network_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + ocf_log debug "OpenStack NovaNetwork (nova-network) monitor succeeded" + return $OCF_SUCCESS +} + +nova_network_start() { + local rc + + nova_network_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack NovaNetwork (nova-network) already running" + return $OCF_SUCCESS + fi + + # run the actual nova-network daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --flagfile=$OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + sleep 1 + while true; do + nova_network_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack NovaNetwork (nova-network) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack NovaNetwork (nova-network) started" + return $OCF_SUCCESS +} + +nova_network_stop() { + local rc + local pid + + nova_network_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack NovaNetwork (nova-network) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack NovaNetwork (nova-network) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + nova_network_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack NovaNetwork (nova-network) still hasn't stopped yet. Waiting ..." + done + + nova_network_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack NovaNetwork (nova-network) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack NovaNetwork (nova-network) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +nova_network_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) nova_network_start;; + stop) nova_network_stop;; + status) nova_network_status;; + monitor) nova_network_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac diff --git a/ocf/nova-novnc b/ocf/nova-novnc new file mode 100644 index 0000000..3673134 --- /dev/null +++ b/ocf/nova-novnc @@ -0,0 +1,340 @@ +#!/bin/sh +# +# +# OpenStack Nova VNC Console (nova-novncproxy) +# +# Description: Manages an OpenStack Nova VNC Console (nova-novncproxy) process as an HA resource +# +# Authors: Sébastien Han +# Mainly inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLpr +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_monitor_binary +# OCF_RESKEY_console_port +# OCF_RESKEY_web +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="nova-novncproxy" +OCF_RESKEY_config_default="/etc/nova/nova.conf" +OCF_RESKEY_user_default="nova" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_monitor_binary_default="netstat" +OCF_RESKEY_console_port_default="6080" +OCF_RESKEY_web_default="/usr/share/novnc/" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_monitor_binary=${OCF_RESKEY_monitor_binary_default}} +: ${OCF_RESKEY_console_port=${OCF_RESKEY_console_port_default}} +: ${OCF_RESKEY_web=${OCF_RESKEY_web_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack Nova VNC Console Service (nova-novncproxy) +May manage a nova-novncproxy instance or a clone set that +creates a distributed nova-novncproxy cluster. + +Manages the OpenStack Nova VNC Console (nova-novncproxy) + + + + +Location of the OpenStack Nova VNC Console server binary (nova-novncproxy) + +OpenStack Nova VNC Console server binary (nova-novncproxy) + + + + + +Location of the OpenStack Nova VNC Console (nova-novncproxy) configuration file + +OpenStack Nova VNC Console (nova-novncproxy registry) config file + + + + + +User running OpenStack Nova VNC Console (nova-novncproxy) + +OpenStack Nova VNC Console (nova-novncproxy) user + + + + + +VNC console type running: nova-novnc or nova-xvpvncproxy + +OpenStack Nova VNC Console (nova-novncproxy) console type + + + + + +VNC console web URL + +OpenStack Nova VNC Console (nova-novncproxy) web URL + + + + + +The pid file to use for this OpenStack Nova VNC Console (nova-novncproxy) instance + +OpenStack Nova VNC Console (nova-novncproxy) pid file + + + + + +Additional parameters to pass on to the OpenStack Nova VNC Console (nova-novncproxy) + +Additional parameters for nova-novncproxy + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +nova_vnc_console_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +nova_vnc_console_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack Nova VNC Console (nova-novncproxy) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack Nova VNC Console (nova-novncproxy) is not running" + return $OCF_NOT_RUNNING + fi +} + +nova_vnc_console_monitor() { + local rc + local token + + nova_vnc_console_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into nova-novncproxy + # and do it if that's the case. + if ! check_binary $OCF_RESKEY_monitor_binary; then + ocf_log warn "$OCF_RESKEY_monitor_binary missing, can not monitor!" + else + VNC_LIST_CHECK=`$OCF_RESKEY_monitor_binary -a | grep "$OCF_RESKEY_console_port" | grep -q "LISTEN"` + fi + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "Nova VNC Console doesn't seem to listen on his default port: $rc" + return $OCF_NOT_RUNNING + fi + + ocf_log debug "OpenStack Nova VNC Console (nova-novncproxy) monitor succeeded" + return $OCF_SUCCESS +} + +nova_vnc_console_start() { + local rc + + nova_vnc_console_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack Nova VNC Console (nova-novncproxy) already running" + return $OCF_SUCCESS + fi + + # run the actual nova-novncproxy daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --flagfile=$OCF_RESKEY_config --web /usr/share/novnc/ \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + while true; do + nova_vnc_console_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack Nova VNC Console (nova-novncproxy) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack Nova VNC Console (nova-novncproxy) started" + return $OCF_SUCCESS +} + +nova_vnc_console_stop() { + local rc + local pid + + nova_vnc_console_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack Nova VNC Console (nova-novncproxy) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack Nova VNC Console (nova-novncproxy) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + nova_vnc_console_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack Nova VNC Console (nova-novncproxy) still hasn't stopped yet. Waiting ..." + done + + nova_vnc_console_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack Nova VNC Console (nova-novncproxy) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack Nova VNC Console (nova-novncproxy) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +nova_vnc_console_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) nova_vnc_console_start;; + stop) nova_vnc_console_stop;; + status) nova_vnc_console_status;; + monitor) nova_vnc_console_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac + diff --git a/ocf/nova-objectstore b/ocf/nova-objectstore new file mode 100644 index 0000000..3e2b674 --- /dev/null +++ b/ocf/nova-objectstore @@ -0,0 +1,305 @@ +#!/bin/sh +# +# +# OpenStack NovaObjectstore (nova-objectstore) +# +# Description: Manages an OpenStack NovaObjectstore (nova-objectstore) process as an HA resource +# +# Authors: Alessandro Tagliapietra +# Mainly inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLp +# and the other resource agents by Sebastien Han http://sebastien-han.fr +# +# Website: http://www.alexnetwork.it/ +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="nova-objectstore" +OCF_RESKEY_config_default="/etc/nova/nova.conf" +OCF_RESKEY_user_default="nova" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack NovaObjectstore (nova-objectstore) +May manage a nova-objectstore instance or a clone set that +creates a distributed nova-objectstore cluster. + +Manages the OpenStack NovaObjectstore (nova-objectstore) + + + + +Location of the OpenStack NovaObjectstore server binary (nova-objectstore) + +OpenStack NovaObjectstore server binary (nova-objectstore) + + + + + +Location of the OpenStack NovaObjectstore (nova-objectstore) configuration file + +OpenStack NovaObjectstore (nova-objectstore) config file + + + + + +User running OpenStack NovaObjectstore (nova-objectstore) + +OpenStack NovaObjectstore (nova-objectstore) user + + + + + +The pid file to use for this OpenStack NovaObjectstore (nova-objectstore) instance + +OpenStack NovaObjectstore (nova-objectstore) pid file + + + + + +Additional parameters to pass on to the OpenStack NovaObjectstore (nova-objectstore) + +Additional parameters for nova-objectstore + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +nova_objectstore_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +nova_objectstore_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack NovaObjectstore (nova-objectstore) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack NovaObjectstore (nova-objectstore) is not running" + return $OCF_NOT_RUNNING + fi +} + +nova_objectstore_monitor() { + local rc + local token + + nova_objectstore_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + ocf_log debug "OpenStack NovaObjectstore (nova-objectstore) monitor succeeded" + return $OCF_SUCCESS +} + +nova_objectstore_start() { + local rc + + nova_objectstore_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack NovaObjectstore (nova-objectstore) already running" + return $OCF_SUCCESS + fi + + # run the actual nova-objectstore daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --flagfile=$OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + sleep 1 + while true; do + nova_objectstore_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack NovaObjectstore (nova-objectstore) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack NovaObjectstore (nova-objectstore) started" + return $OCF_SUCCESS +} + +nova_objectstore_stop() { + local rc + local pid + + nova_objectstore_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack NovaObjectstore (nova-objectstore) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack NovaObjectstore (nova-objectstore) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + nova_objectstore_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack NovaObjectstore (nova-objectstore) still hasn't stopped yet. Waiting ..." + done + + nova_objectstore_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack NovaObjectstore (nova-objectstore) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack NovaObjectstore (nova-objectstore) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +nova_objectstore_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) nova_objectstore_start;; + stop) nova_objectstore_stop;; + status) nova_objectstore_status;; + monitor) nova_objectstore_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac \ No newline at end of file diff --git a/ocf/nova-scheduler b/ocf/nova-scheduler new file mode 100644 index 0000000..ae74098 --- /dev/null +++ b/ocf/nova-scheduler @@ -0,0 +1,366 @@ +#!/bin/sh +# +# +# OpenStack Scheduler Service (nova-scheduler) +# +# Description: Manages an OpenStack Scheduler Service (nova-scheduler) process as an HA resource +# +# Authors: Sébastien Han +# Mainly inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLpr +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_monitor_binary +# OCF_RESKEY_database_server_port +# OCF_RESKEY_amqp_server_port +# OCF_RESKEY_zeromq +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="nova-scheduler" +OCF_RESKEY_config_default="/etc/nova/nova.conf" +OCF_RESKEY_user_default="nova" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_monitor_binary_default="netstat" +OCF_RESKEY_database_server_port_default="3306" +OCF_RESKEY_amqp_server_port_default="5672" +OCF_RESKEY_zeromq_default="false" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_monitor_binary=${OCF_RESKEY_monitor_binary_default}} +: ${OCF_RESKEY_database_server_port=${OCF_RESKEY_database_server_port_default}} +: ${OCF_RESKEY_amqp_server_port=${OCF_RESKEY_amqp_server_port_default}} +: ${OCF_RESKEY_zeromq=${OCF_RESKEY_zeromq_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack NovaScheduler Service (nova-scheduler) +May manage a nova-scheduler instance or a clone set that +creates a distributed nova-scheduler cluster. + +Manages the OpenStack SchedulerService (nova-scheduler) + + + + +Location of the OpenStack NovaScheduler server binary (nova-scheduler) + +OpenStack NovaScheduler server binary (nova-scheduler) + + + + + +Location of the OpenStack SchedulerService (nova-scheduler) configuration file + +OpenStack NovaScheduler (nova-scheduler registry) config file + + + + + +User running OpenStack SchedulerService (nova-scheduler) + +OpenStack SchedulerService (nova-scheduler) user + + + + + +The pid file to use for this OpenStack SchedulerService (nova-scheduler) instance + +OpenStack SchedulerService (nova-scheduler) pid file + + + + + +The listening port number of the database server. Mandatory to perform a monitor check + +Database listening port + + + + + +The listening port number of the AMQP server. Mandatory to perform a monitor check + +AMQP listening port + + + + + +If zeromq is used, this will disable the connection test to the AMQP server + +Zero-MQ usage + + + + + +Additional parameters to pass on to the OpenStack SchedulerService (nova-scheduler) + +Additional parameters for nova-scheduler + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +nova_scheduler_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +nova_scheduler_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack NovaScheduler (nova-scheduler) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack NovaScheduler (nova-scheduler) is not running" + return $OCF_NOT_RUNNING + fi +} + +nova_scheduler_monitor() { + local rc + local token + + nova_scheduler_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into nova-scheduler + # and do it if that's the case. + if ! check_binary $OCF_RESKEY_monitor_binary; then + ocf_log warn "$OCF_RESKEY_monitor_binary missing, can not monitor!" + else + if [ $OCF_RESKEY_zeromq = true ]; then + PID=`cat $OCF_RESKEY_pid` + SCHEDULER_DATABASE_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_database_server_port" | grep "$PID" | grep -q "ESTABLISHED"` + rc_database=$? + if [ $rc_database -ne 0 ]; then + ocf_log err "Nova Scheduler is not connected to the database server: $rc_database" + return $OCF_NOT_RUNNING + fi + else + PID=`cat $OCF_RESKEY_pid` + # check the connections according to the PID + SCHEDULER_DATABASE_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_database_server_port" | grep "$PID" | grep -q "ESTABLISHED"` + rc_database=$? + SCHEDULER_AMQP_CO_CHECK=`"$OCF_RESKEY_monitor_binary" -punt | grep "$OCF_RESKEY_amqp_server_port" | grep "$PID" | grep -q "ESTABLISHED"` + rc_amqp=$? + if [ $rc_amqp -ne 0 ] || [ $rc_database -ne 0 ]; then + ocf_log err "Nova Scheduler is not connected to the AMQP server and/or the database server: AMQP connection test returned $rc_amqp and database connection test returned $rc_database" + return $OCF_NOT_RUNNING + fi + fi + fi + + ocf_log debug "OpenStack NovaScheduler (nova-scheduler) monitor succeeded" + return $OCF_SUCCESS +} + +nova_scheduler_start() { + local rc + + nova_scheduler_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack NovaScheduler (nova-scheduler) already running" + return $OCF_SUCCESS + fi + + # run the actual nova-scheduler daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --flagfile=$OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + sleep 1 + while true; do + nova_scheduler_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack NovaScheduler (nova-scheduler) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack NovaScheduler (nova-scheduler) started" + return $OCF_SUCCESS +} + +nova_scheduler_stop() { + local rc + local pid + + nova_scheduler_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack NovaScheduler (nova-scheduler) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack NovaScheduler (nova-scheduler) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + nova_scheduler_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack NovaScheduler (nova-scheduler) still hasn't stopped yet. Waiting ..." + done + + nova_scheduler_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack NovaScheduler (nova-scheduler) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack NovaScheduler (nova-scheduler) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +nova_scheduler_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) nova_scheduler_start;; + stop) nova_scheduler_stop;; + status) nova_scheduler_status;; + monitor) nova_scheduler_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac + diff --git a/ocf/nova-volume b/ocf/nova-volume new file mode 100644 index 0000000..97fa824 --- /dev/null +++ b/ocf/nova-volume @@ -0,0 +1,305 @@ +#!/bin/sh +# +# +# OpenStack NovaVolume (nova-volume) +# +# Description: Manages an OpenStack NovaVolume (nova-volume) process as an HA resource +# +# Authors: Alessandro Tagliapietra +# Mainly inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLp +# and the other resource agents by Sebastien Han http://sebastien-han.fr +# +# Website: http://www.alexnetwork.it/ +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="nova-volume" +OCF_RESKEY_config_default="/etc/nova/nova.conf" +OCF_RESKEY_user_default="nova" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack NovaVolume (nova-volume) +May manage a nova-volume instance or a clone set that +creates a distributed nova-volume cluster. + +Manages the OpenStack NovaVolume (nova-volume) + + + + +Location of the OpenStack NovaVolume server binary (nova-volume) + +OpenStack NovaVolume server binary (nova-volume) + + + + + +Location of the OpenStack NovaVolume (nova-volume) configuration file + +OpenStack NovaVolume (nova-volume) config file + + + + + +User running OpenStack NovaVolume (nova-volume) + +OpenStack NovaVolume (nova-volume) user + + + + + +The pid file to use for this OpenStack NovaVolume (nova-volume) instance + +OpenStack NovaVolume (nova-volume) pid file + + + + + +Additional parameters to pass on to the OpenStack NovaVolume (nova-volume) + +Additional parameters for nova-volume + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +nova_volume_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +nova_volume_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack NovaVolume (nova-volume) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack NovaVolume (nova-volume) is not running" + return $OCF_NOT_RUNNING + fi +} + +nova_volume_monitor() { + local rc + local token + + nova_volume_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + ocf_log debug "OpenStack NovaVolume (nova-volume) monitor succeeded" + return $OCF_SUCCESS +} + +nova_volume_start() { + local rc + + nova_volume_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack NovaVolume (nova-volume) already running" + return $OCF_SUCCESS + fi + + # run the actual nova-volume daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --flagfile=$OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + sleep 1 + while true; do + nova_volume_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack NovaVolume (nova-volume) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack NovaVolume (nova-volume) started" + return $OCF_SUCCESS +} + +nova_volume_stop() { + local rc + local pid + + nova_volume_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack NovaVolume (nova-volume) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack NovaVolume (nova-volume) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + nova_volume_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack NovaVolume (nova-volume) still hasn't stopped yet. Waiting ..." + done + + nova_volume_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack NovaVolume (nova-volume) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack NovaVolume (nova-volume) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +nova_volume_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) nova_volume_start;; + stop) nova_volume_stop;; + status) nova_volume_status;; + monitor) nova_volume_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac \ No newline at end of file diff --git a/ocf/quantum-server b/ocf/quantum-server new file mode 100644 index 0000000..9ef8cf6 --- /dev/null +++ b/ocf/quantum-server @@ -0,0 +1,325 @@ +#!/bin/sh +# +# +# OpenStack Quantum Server (quantum-server) +# +# Description: Manages an OpenStack Quantum Server (quantum-server) process as an HA resource +# +# Authors: Emilien Macchi +# Mainly inspired by the Nova API resource agent written by Sebastien Han : http://goo.gl/s8hOU +# Which is also inspired by the Glance API resource agent written by Martin Gerhard Loschwitz from Hastexo: http://goo.gl/whLpr +# +# Support: openstack@lists.launchpad.net +# License: Apache Software License (ASL) 2.0 +# +# +# See usage() function below for more details ... +# +# OCF instance parameters: +# OCF_RESKEY_binary +# OCF_RESKEY_config +# OCF_RESKEY_user +# OCF_RESKEY_pid +# OCF_RESKEY_monitor_binary +# OCF_RESKEY_api_listened_port +# OCF_RESKEY_additional_parameters +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +# Fill in some defaults if no values are specified + +OCF_RESKEY_binary_default="quantum-server" +OCF_RESKEY_config_default="/etc/quantum/quantum.conf" +OCF_RESKEY_user_default="quantum" +OCF_RESKEY_pid_default="$HA_RSCTMP/$OCF_RESOURCE_INSTANCE.pid" +OCF_RESKEY_monitor_binary_default="netstat" +OCF_RESKEY_api_listened_port_default="9696" + +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} +: ${OCF_RESKEY_monitor_binary=${OCF_RESKEY_monitor_binary_default}} +: ${OCF_RESKEY_api_listened_port=${OCF_RESKEY_api_listened_port_default}} + +####################################################################### + +usage() { + cat < + + +1.0 + + +Resource agent for the OpenStack Quantum Server (quantum-server) +May manage a quantum-server instance or a clone set that +creates a distributed quantum-server cluster. + +Manages the OpenStack Quantum Server (quantum-server) + + + + +Location of the OpenStack Quantum Server server binary (quantum-server) + +OpenStack Quantum Server server binary (quantum-server) + + + + + +Location of the OpenStack Quantum Server (quantum-server) configuration file + +OpenStack Quantum Server (quantum-server) config file + + + + + +User running OpenStack Quantum Server (quantum-server) + +OpenStack Quantum Server (quantum-server) user + + + + + +The pid file to use for this OpenStack Quantum Server (quantum-server) instance + +OpenStack Quantum Server (quantum-server) pid file + + + + + +Additional parameters to pass on to the OpenStack Quantum Server (quantum-server) + +Additional parameters for quantum-server + + + + + + + + + + + + + + +END +} + +####################################################################### +# Functions invoked by resource manager actions + +quantum_server_validate() { + local rc + + check_binary $OCF_RESKEY_binary + + # A config file on shared storage that is not available + # during probes is OK. + if [ ! -f $OCF_RESKEY_config ]; then + if ! ocf_is_probe; then + ocf_log err "Config $OCF_RESKEY_config doesn't exist" + return $OCF_ERR_INSTALLED + fi + ocf_log_warn "Config $OCF_RESKEY_config not available during a probe" + fi + + getent passwd $OCF_RESKEY_user >/dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "User $OCF_RESKEY_user doesn't exist" + return $OCF_ERR_INSTALLED + fi + + true +} + +quantum_server_status() { + local pid + local rc + + if [ ! -f $OCF_RESKEY_pid ]; then + ocf_log info "OpenStack Quantum Server (quantum-server) is not running" + return $OCF_NOT_RUNNING + else + pid=`cat $OCF_RESKEY_pid` + fi + + ocf_run -warn kill -s 0 $pid + rc=$? + if [ $rc -eq 0 ]; then + return $OCF_SUCCESS + else + ocf_log info "Old PID file found, but OpenStack Quantum Server (quantum-server) is not running" + return $OCF_NOT_RUNNING + fi +} + +quantum_server_monitor() { + local rc + local token + + quantum_server_status + rc=$? + + # If status returned anything but success, return that immediately + if [ $rc -ne $OCF_SUCCESS ]; then + return $rc + fi + + # Check whether we are supposed to monitor by logging into quantum-server + # and do it if that's the case. + if ! check_binary $OCF_RESKEY_monitor_binary; then + ocf_log warn "$OCF_RESKEY_monitor_binary missing, can not monitor!" + else + # Check osapi_compute and osapi_volume ports + API_LIST_CHECK=`$OCF_RESKEY_monitor_binary -a | egrep -E $OCF_RESKEY_api_listened_port | egrep -q "LISTEN"` + fi + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "Quantum Server is not connected to the queue message service: $rc" + return $OCF_NOT_RUNNING + fi + + ocf_log debug "OpenStack Quantum Server (quantum-server) monitor succeeded" + return $OCF_SUCCESS +} + +quantum_server_start() { + local rc + + quantum_server_status + rc=$? + if [ $rc -eq $OCF_SUCCESS ]; then + ocf_log info "OpenStack Quantum Server (quantum-server) already running" + return $OCF_SUCCESS + fi + + # run the actual quantum-server daemon. Don't use ocf_run as we're sending the tool's output + # straight to /dev/null anyway and using ocf_run would break stdout-redirection here. + su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} --config-file=$OCF_RESKEY_config \ + $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid + + # Spin waiting for the server to come up. + # Let the CRM/LRM time us out if required + sleep 1 + while true; do + quantum_server_monitor + rc=$? + [ $rc -eq $OCF_SUCCESS ] && break + if [ $rc -ne $OCF_NOT_RUNNING ]; then + ocf_log err "OpenStack Quantum Server (quantum-server) start failed" + exit $OCF_ERR_GENERIC + fi + sleep 1 + done + + ocf_log info "OpenStack Quantum Server (quantum-server) started" + return $OCF_SUCCESS +} + +quantum_server_stop() { + local rc + local pid + + quantum_server_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + ocf_log info "OpenStack Quantum Server (quantum-server) already stopped" + return $OCF_SUCCESS + fi + + # Try SIGTERM + pid=`cat $OCF_RESKEY_pid` + ocf_run kill -s TERM $pid + rc=$? + if [ $rc -ne 0 ]; then + ocf_log err "OpenStack Quantum Server (quantum-server) couldn't be stopped" + exit $OCF_ERR_GENERIC + fi + + # stop waiting + shutdown_timeout=15 + if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then + shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) + fi + count=0 + while [ $count -lt $shutdown_timeout ]; do + quantum_server_status + rc=$? + if [ $rc -eq $OCF_NOT_RUNNING ]; then + break + fi + count=`expr $count + 1` + sleep 1 + ocf_log debug "OpenStack Quantum Server (quantum-server) still hasn't stopped yet. Waiting ..." + done + + quantum_server_status + rc=$? + if [ $rc -ne $OCF_NOT_RUNNING ]; then + # SIGTERM didn't help either, try SIGKILL + ocf_log info "OpenStack Quantum Server (quantum-server) failed to stop after ${shutdown_timeout}s \ + using SIGTERM. Trying SIGKILL ..." + ocf_run kill -s KILL $pid + fi + + ocf_log info "OpenStack Quantum Server (quantum-server) stopped" + + rm -f $OCF_RESKEY_pid + + return $OCF_SUCCESS +} + +####################################################################### + +case "$1" in + meta-data) meta_data + exit $OCF_SUCCESS;; + usage|help) usage + exit $OCF_SUCCESS;; +esac + +# Anything except meta-data and help must pass validation +quantum_server_validate || exit $? + +# What kind of method was invoked? +case "$1" in + start) quantum_server_start;; + stop) quantum_server_stop;; + status) quantum_server_status;; + monitor) quantum_server_monitor;; + validate-all) ;; + *) usage + exit $OCF_ERR_UNIMPLEMENTED;; +esac + +