Improve ntp and it's ocf script
* Add check if ntp is running in a correct namespace * Refactor ntp task to use pacemaker_wrapper Change-Id: Id831f909caeb3a8cf588fa9de5d2b0e346d58b9a Closes-Bug: 1481618
This commit is contained in:
parent
347d51f391
commit
ee555e095a
@ -2,57 +2,55 @@
|
||||
#
|
||||
# Configure OCF service for NTP managed by corosync/pacemaker
|
||||
#
|
||||
class cluster::ntp_ocf ( ) {
|
||||
include ntp::params
|
||||
class cluster::ntp_ocf inherits ntp::params {
|
||||
$primitive_type = 'ns_ntp'
|
||||
$complex_type = 'clone'
|
||||
|
||||
$basic_service_name = $ntp::params::service_name
|
||||
$service_name = "p_${basic_service_name}"
|
||||
$ms_metadata = {
|
||||
'interleave' => 'true',
|
||||
}
|
||||
|
||||
cs_resource { $service_name:
|
||||
ensure => present,
|
||||
primitive_class => 'ocf',
|
||||
provided_by => 'fuel',
|
||||
primitive_type => 'ns_ntp',
|
||||
complex_type => 'clone',
|
||||
ms_metadata => {
|
||||
'interleave' => 'true',
|
||||
},
|
||||
metadata => {
|
||||
'migration-threshold' => '3',
|
||||
'failure-timeout' => '120',
|
||||
},
|
||||
parameters => {
|
||||
'ns' => 'vrouter',
|
||||
},
|
||||
operations => {
|
||||
'monitor' => {
|
||||
'interval' => '20',
|
||||
'timeout' => '10'
|
||||
},
|
||||
'start' => {
|
||||
'timeout' => '30'
|
||||
},
|
||||
'stop' => {
|
||||
'timeout' => '30'
|
||||
},
|
||||
},
|
||||
} ->
|
||||
$metadata = {
|
||||
'migration-threshold' => '3',
|
||||
'failure-timeout' => '120',
|
||||
}
|
||||
|
||||
cs_rsc_colocation { 'ntpd-with-vrouter-ns':
|
||||
ensure => present,
|
||||
$parameters = {
|
||||
'ns' => 'vrouter',
|
||||
}
|
||||
|
||||
$operations = {
|
||||
'monitor' => {
|
||||
'interval' => '20',
|
||||
'timeout' => '10'
|
||||
},
|
||||
'start' => {
|
||||
'timeout' => '30'
|
||||
},
|
||||
'stop' => {
|
||||
'timeout' => '30'
|
||||
},
|
||||
}
|
||||
|
||||
cs_rsc_colocation { 'ntp-with-vrouter-ns' :
|
||||
ensure => 'present',
|
||||
score => 'INFINITY',
|
||||
primitives => [
|
||||
"clone_${service_name}",
|
||||
"clone_p_vrouter"
|
||||
"clone_p_$service_name",
|
||||
"clone_p_vrouter",
|
||||
],
|
||||
}
|
||||
|
||||
Cs_resource[$service_name] ~> Service[$service_name]
|
||||
|
||||
service { $service_name:
|
||||
name => $service_name,
|
||||
enable => true,
|
||||
ensure => 'running',
|
||||
provider => 'pacemaker',
|
||||
pacemaker_wrappers::service { $service_name :
|
||||
primitive_type => $primitive_type,
|
||||
parameters => $parameters,
|
||||
metadata => $metadata,
|
||||
operations => $operations,
|
||||
ms_metadata => $ms_metadata,
|
||||
complex_type => $complex_type,
|
||||
prefix => true,
|
||||
}
|
||||
|
||||
Cs_rsc_colocation['ntp-with-vrouter-ns'] -> Service['ntp']
|
||||
|
||||
}
|
||||
|
@ -4,14 +4,14 @@ $ntp_servers = hiera('external_ntp')
|
||||
|
||||
class { 'ntp':
|
||||
servers => strip(split($ntp_servers['ntp_list'], ',')),
|
||||
service_enable => false,
|
||||
service_ensure => 'stopped',
|
||||
service_enable => true,
|
||||
service_ensure => 'running',
|
||||
iburst_enable => true,
|
||||
tinker => true,
|
||||
panic => '0',
|
||||
stepout => '5',
|
||||
minpoll => '3',
|
||||
} ->
|
||||
}
|
||||
|
||||
class { 'cluster::ntp_ocf': }
|
||||
|
||||
|
@ -47,11 +47,10 @@ OCF_RESKEY_extraconf_default=""
|
||||
|
||||
USAGE="Usage: $0 {start|stop|restart|status|monitor|validate-all|meta-data}";
|
||||
|
||||
RUN_IN_NS="ip netns exec $OCF_RESKEY_ns "
|
||||
if [[ -z $OCF_RESKEY_ns ]] ; then
|
||||
RUN=''
|
||||
if [ -n "${OCF_RESKEY_ns}" ]; then
|
||||
RUN="ip netns exec ${OCF_RESKEY_ns} "
|
||||
else
|
||||
RUN="$RUN_IN_NS "
|
||||
RUN=''
|
||||
fi
|
||||
|
||||
##########################################################################
|
||||
@ -136,7 +135,7 @@ exit $OCF_SUCCESS
|
||||
|
||||
get_variables() {
|
||||
CONF_FILE="${OCF_RESKEY_conffile}"
|
||||
COMMAND="$RUN ${OCF_RESKEY_binpath}"
|
||||
COMMAND="${RUN} ${OCF_RESKEY_binpath}"
|
||||
PIDFILE="${OCF_RESKEY_pidfile}"
|
||||
}
|
||||
|
||||
@ -148,21 +147,30 @@ ntp_status() {
|
||||
PID="`cat ${PIDFILE}`"
|
||||
if [ -n "${PID}" ]; then
|
||||
# check if process exists
|
||||
if $RUN ps -p "${PID}" | grep -q ntp; then
|
||||
if ps -p "${PID}" | grep -q ntp; then
|
||||
if [ -n "${OCF_RESKEY_ns}" ]; then
|
||||
NS=`ip netns identify "${PID}"`
|
||||
if [ "${NS}" != "${OCF_RESKEY_ns}" ]; then
|
||||
# ntp is running with the correct pid
|
||||
# but not in the right network namespace
|
||||
ocf_log info "ntp daemon is running in a wrong namespace."
|
||||
return "${OCF_ERR_GENERIC}"
|
||||
fi
|
||||
fi
|
||||
ocf_log info "ntp daemon running"
|
||||
return $OCF_SUCCESS
|
||||
return "${OCF_SUCCESS}"
|
||||
else
|
||||
ocf_log info "ntp daemon is not running but pid file exists"
|
||||
return $OCF_NOT_RUNNING
|
||||
return "${OCF_NOT_RUNNING}"
|
||||
fi
|
||||
else
|
||||
ocf_log err "PID file empty!"
|
||||
return $OCF_ERR_GENERIC
|
||||
return "${OCF_ERR_GENERIC}"
|
||||
fi
|
||||
fi
|
||||
# ntp is not running
|
||||
ocf_log info "ntp daemon is not running"
|
||||
return $OCF_NOT_RUNNING
|
||||
return "${OCF_NOT_RUNNING}"
|
||||
}
|
||||
|
||||
ntp_start()
|
||||
@ -170,44 +178,46 @@ ntp_start()
|
||||
get_variables
|
||||
# if ntp is running return success
|
||||
ntp_status
|
||||
retVal=$?
|
||||
if [ $retVal -eq $OCF_SUCCESS ]; then
|
||||
return $OCF_SUCCESS
|
||||
elif [ $retVal -ne $OCF_NOT_RUNNING ]; then
|
||||
rc="${?}"
|
||||
if [ "${rc}" -eq "${OCF_SUCCESS}" ]; then
|
||||
return "${OCF_SUCCESS}"
|
||||
elif [ "${rc}" -ne "${OCF_NOT_RUNNING}" ]; then
|
||||
ocf_log err "Error. Unknown status."
|
||||
return $OCF_ERR_GENERIC
|
||||
return "${OCF_ERR_GENERIC}"
|
||||
fi
|
||||
|
||||
# run the ntp binary
|
||||
ocf_run ${COMMAND} ${OCF_RESKEY_extraconf} -u ntp:ntp -p "${PIDFILE}" -4 -g -c ${CONF_FILE}
|
||||
if [ $? -ne 0 ]; then
|
||||
ocf_run ${COMMAND} ${OCF_RESKEY_extraconf} -u ntp:ntp -p "${PIDFILE}" -4 -g -c "${CONF_FILE}"
|
||||
if [ "${?}" -ne "0" ]; then
|
||||
ocf_log err "Error. ntp daemon returned error $?."
|
||||
return $OCF_ERR_GENERIC
|
||||
return "${OCF_ERR_GENERIC}"
|
||||
fi
|
||||
|
||||
ocf_log info "Started ntp daemon."
|
||||
return $OCF_SUCCESS
|
||||
return "${OCF_SUCCESS}"
|
||||
}
|
||||
|
||||
ntp_stop()
|
||||
{
|
||||
get_variables
|
||||
if ntp_status ; then
|
||||
PID="`${RUN} cat ${PIDFILE}`"
|
||||
ntp_status
|
||||
rc="${?}"
|
||||
if [ "${rc}" -eq "${OCF_SUCCESS}" -o "${rc}" -eq "${OCF_ERR_GENERIC}" ]; then
|
||||
PID="`cat ${PIDFILE}`"
|
||||
if [ -n "${PID}" ] ; then
|
||||
kill "${PID}"
|
||||
if [ $? -ne 0 ]; then
|
||||
if [ "${?}" -ne "0" ]; then
|
||||
kill -SIGKILL "${PID}"
|
||||
if [ $? -ne 0 ]; then
|
||||
if [ "${?}" -ne "0" ]; then
|
||||
ocf_log err "Error. Could not stop ntp daemon."
|
||||
return $OCF_ERR_GENERIC
|
||||
return "${OCF_ERR_GENERIC}"
|
||||
fi
|
||||
fi
|
||||
rm -f "${PIDFILE}"
|
||||
fi
|
||||
fi
|
||||
ocf_log info "Stopped ntp daemon."
|
||||
return $OCF_SUCCESS
|
||||
return "${OCF_SUCCESS}"
|
||||
}
|
||||
|
||||
ntp_monitor()
|
||||
@ -218,23 +228,23 @@ ntp_monitor()
|
||||
ntp_validate_all()
|
||||
{
|
||||
get_variables
|
||||
if [ -n "$OCF_RESKEY_binpath" -a ! -x "$OCF_RESKEY_binpath" ]; then
|
||||
if [ -n "${OCF_RESKEY_binpath}" -a ! -x "${OCF_RESKEY_binpath}" ]; then
|
||||
ocf_log err "Binary path $OCF_RESKEY_binpath does not exist."
|
||||
return $OCF_ERR_ARGS
|
||||
return "${OCF_ERR_ARGS}"
|
||||
fi
|
||||
if [ -n "$OCF_RESKEY_conffile" -a ! -f "$OCF_RESKEY_conffile" ]; then
|
||||
if [ -n "${OCF_RESKEY_conffile}" -a ! -f "${OCF_RESKEY_conffile}" ]; then
|
||||
ocf_log err "Config file $OCF_RESKEY_conffile does not exist."
|
||||
return $OCF_ERR_ARGS
|
||||
return "${OCF_ERR_ARGS}"
|
||||
fi
|
||||
|
||||
if grep -v "^#" "$CONF_FILE" | grep "pidfile" > /dev/null ; then
|
||||
if grep -v '^#' "${CONF_FILE}" | grep 'pidfile' > /dev/null ; then
|
||||
:
|
||||
else
|
||||
ocf_log err "Error. \"pidfile\" entry required in the ntp config file by ntp OCF RA."
|
||||
return $OCF_ERR_GENERIC
|
||||
ocf_log err "Error. 'pidfile' entry required in the ntp config file by ntp OCF RA."
|
||||
return "${OCF_ERR_GENERIC}"
|
||||
fi
|
||||
|
||||
return $OCF_SUCCESS
|
||||
return "${OCF_SUCCESS}"
|
||||
}
|
||||
|
||||
ntp_restart()
|
||||
@ -249,7 +259,7 @@ ntp_restart()
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
usage
|
||||
exit $OCF_ERR_ARGS
|
||||
exit "${OCF_ERR_ARGS}"
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
@ -274,9 +284,9 @@ case $1 in
|
||||
meta-data) meta_data
|
||||
;;
|
||||
|
||||
usage) usage; exit $OCF_SUCCESS
|
||||
usage) usage; exit "${OCF_SUCCESS}"
|
||||
;;
|
||||
|
||||
*) usage; exit $OCF_ERR_UNIMPLEMENTED
|
||||
*) usage; exit "${OCF_ERR_UNIMPLEMENTED}"
|
||||
;;
|
||||
esac
|
||||
|
Loading…
Reference in New Issue
Block a user