104
106
# NOTE(jamespage) install actually happens in config_changed hook
109
def get_local_nodename():
110
'''Resolve local nodename into something that's universally addressable'''
111
ip_addr = get_host_ip(unit_get('private-address'))
112
log('getting local nodename for ip address: %s' % ip_addr, level=INFO)
114
nodename = get_hostname(ip_addr, fqdn=False)
116
log('Cannot resolve hostname for %s using DNS servers' % ip_addr,
118
log('Falling back to use socket.gethostname()',
120
# If the private-address is not resolvable using DNS
121
# then use the current hostname
122
nodename = socket.gethostname()
123
log('local nodename: %s' % nodename, level=INFO)
127
def configure_nodename():
128
'''Set RABBITMQ_NODENAME to something that's resolvable by my peers'''
129
nodename = get_local_nodename()
130
log('configuring nodename', level=INFO)
132
rabbit.get_node_name() != 'rabbit@%s' % nodename):
133
log('forcing nodename=%s' % nodename, level=INFO)
134
# would like to have used the restart_on_change decorator, but
135
# need to stop it under current nodename prior to updating env
136
log('Stopping rabbitmq-server.')
137
service_stop('rabbitmq-server')
138
rabbit.update_rmq_env_conf(hostname='rabbit@%s' % nodename,
139
ipv6=config('prefer-ipv6'))
140
log('Starting rabbitmq-server.')
141
service_restart('rabbitmq-server')
107
144
def configure_amqp(username, vhost, admin=False):
108
145
# get and update service password
109
146
password = rabbit.get_rabbit_password(username)
130
167
host_addr = unit_get('private-address')
132
169
if not is_elected_leader('res_rabbitmq_vip'):
170
# NOTE(jamespage) clear relation to deal with data being
171
# removed from peer storage
172
relation_clear(relation_id)
133
173
# Each unit needs to set the db information otherwise if the unit
134
174
# with the info dies the settings die with it Bug# 1355848
135
175
exc_list = ['hostname', 'private-address']
244
284
'rabbitmq cluster config.')
247
# Set RABBITMQ_NODENAME to something that's resolvable by my peers
248
# get_host_ip() is called to sanitize private-address in case it
249
# doesn't return an IP address
250
ip_addr = get_host_ip(unit_get('private-address'))
252
nodename = get_hostname(ip_addr, fqdn=False)
254
log('Cannot resolve hostname for %s using DNS servers' % ip_addr,
256
log('Falling back to use socket.gethostname()',
258
# If the private-address is not resolvable using DNS
259
# then use the current hostname
260
nodename = socket.gethostname()
262
if nodename and rabbit.get_node_name() != nodename:
263
log('forcing nodename=%s' % nodename)
264
# would like to have used the restart_on_change decorator, but
265
# need to stop it under current nodename prior to updating env
266
service_stop('rabbitmq-server')
267
rabbit.update_rmq_env_conf(hostname='rabbit@%s' % nodename,
268
ipv6=config('prefer-ipv6'))
269
service_restart('rabbitmq-server')
272
log('cluster_joined: Relation greater.')
291
log('Not the leader, deferring cookie propagation to leader')
293
except NotImplementedError:
295
log('cluster_joined: Relation greater.')
275
298
if not os.path.isfile(rabbit.COOKIE_PATH):
276
299
log('erlang cookie missing from %s' % rabbit.COOKIE_PATH,
288
311
@hooks.hook('cluster-relation-changed')
289
312
def cluster_changed():
313
cookie = peer_retrieve('cookie')
315
log('cluster_joined: cookie not yet set.', level=INFO)
290
318
rdata = relation_get()
291
if 'cookie' not in rdata:
292
log('cluster_joined: cookie not yet set.', level=INFO)
295
319
if config('prefer-ipv6') and rdata.get('hostname'):
296
320
private_address = rdata['private-address']
297
321
hostname = rdata['hostname']
317
341
'rabbitmq cluster config.', level=INFO)
322
if rabbit.cluster_with():
323
# resync nrpe user after clustering
347
rabbit.cluster_with()
349
except NotImplementedError:
351
rabbit.cluster_with()
324
352
update_nrpe_checks()
326
354
# If cluster has changed peer db may have changed so run amqp_changed
525
553
current_unit = local_unit().replace('/', '-')
526
554
user = 'nagios-%s' % current_unit
527
555
vhost = 'nagios-%s' % current_unit
528
password = rabbit.get_rabbit_password(user)
556
password = rabbit.get_rabbit_password(user, local=True)
530
558
rabbit.create_vhost(vhost)
531
559
rabbit.create_user(user, password)
569
597
log('upgrade_charm: Migrating stored passwd'
570
598
' from %s to %s.' % (s, d))
571
599
shutil.move(s, d)
572
rabbit.migrate_passwords_to_peer_relation()
600
if is_elected_leader('res_rabbitmq_vip'):
601
rabbit.migrate_passwords_to_peer_relation()
574
603
# explicitly update buggy file name naigos.passwd
575
604
old = os.path.join('var/lib/rabbitmq', 'naigos.passwd')
697
726
chown(RABBIT_DIR, rabbit.RABBIT_USER, rabbit.RABBIT_USER)
698
727
chmod(RABBIT_DIR, 0o775)
700
if config('prefer-ipv6'):
701
rabbit.update_rmq_env_conf(ipv6=config('prefer-ipv6'))
703
731
if config('management_plugin') is True:
704
732
rabbit.enable_plugin(MAN_PLUGIN)
733
761
amqp_changed(relation_id=rid, remote_unit=unit)
764
@hooks.hook('leader-settings-changed')
765
def leader_settings_changed():
766
# If leader has changed and access credentials, ripple these
768
for rid in relation_ids('amqp'):
769
for unit in related_units(rid):
770
amqp_changed(relation_id=rid, remote_unit=unit)
736
773
def pre_install_hooks():
737
774
for f in glob.glob('exec.d/*/charm-pre-install'):
738
775
if os.path.isfile(f) and os.access(f, os.X_OK):