diff --git a/hooks/hooks.py b/hooks/hooks.py index 400b0d0..415331f 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -197,6 +197,13 @@ def configure_cluster(): 'Related to {} ha services'.format(len(relids))) return + if True in [ra.startswith('ocf:openstack') + for ra in resources.itervalues()]: + utils.install('openstack-resource-agents') + if True in [ra.startswith('ocf:ceph') + for ra in resources.itervalues()]: + utils.install('ceph-resource-agents') + utils.juju_log('INFO', 'Configuring and restarting corosync') emit_corosync_conf() restart_corosync() @@ -215,13 +222,6 @@ def configure_cluster(): utils.juju_log('INFO', 'Configuring Resources') utils.juju_log('INFO', str(resources)) - if True in [ra.startswith('ocf:openstack') - for ra in resources.itervalues()]: - utils.install('openstack-resource-agents') - if True in [ra.startswith('ocf:ceph') - for ra in resources.itervalues()]: - utils.install('ceph-resource-agents') - for res_name, res_type in resources.iteritems(): # disable the service we are going to put in HA if res_type.split(':')[0] == "lsb": @@ -288,17 +288,18 @@ def configure_cluster(): utils.juju_log('INFO', '%s' % cmd) for res_name, res_type in resources.iteritems(): - # TODO: This should first check that the resources is running if len(init_services) != 0 and res_name in init_services: - # If the resource is in HA already, and it is a service, restart - # the pcmk resource as the config file might have changed by the - # principal charm - cmd = 'crm resource restart %s' % res_name - pcmk.commit(cmd) - # Just in case, cleanup the resources to ensure they get started - # in case they failed for some unrelated reason. - cmd = 'crm resource cleanup %s' % res_name - pcmk.commit(cmd) + # Checks that the resources are running and started. + if not pcmk.crm_res_running(res_name): + # If the resource is in HA already, and it is a service, restart + # the pcmk resource as the config file might have changed by the + # principal charm + #cmd = 'crm resource restart %s' % res_name + #pcmk.commit(cmd) + # Just in case, cleanup the resources to ensure they get started + # in case they failed for some unrelated reason. + cmd = 'crm resource cleanup %s' % res_name + pcmk.commit(cmd) for rel_id in utils.relation_ids('ha'): utils.relation_set(rid=rel_id, diff --git a/hooks/pcmk.py b/hooks/pcmk.py index 7cdc5e3..074c463 100644 --- a/hooks/pcmk.py +++ b/hooks/pcmk.py @@ -53,6 +53,13 @@ def crm_opt_exists(opt_name): return True return False +def crm_res_running(opt_name): + (status, output) = commands.getstatusoutput("crm resource status %s" % opt_name) + show_re = re.compile('NOT running') + opt = show_re.search(output) + if opt: + return False + return True def list_nodes(): cmd = ['crm', 'node', 'list'] diff --git a/revision b/revision index 04f9fe4..b1e7d26 100644 --- a/revision +++ b/revision @@ -1 +1 @@ -59 +61