[bradm] Fixed rsync to use /etc/rsync-juju.d, check if host_context is defined before using it
This commit is contained in:
32
hooks/charmhelpers/contrib/charmsupport/rsync.py
Normal file
32
hooks/charmhelpers/contrib/charmsupport/rsync.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
"""
|
||||||
|
Support for rsyncd.conf and using fragments dropped inside /etc/rsync-juju.d
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
|
||||||
|
from charmhelpers.core.host import (
|
||||||
|
mkdir,
|
||||||
|
)
|
||||||
|
|
||||||
|
def setup_rsync():
|
||||||
|
'''
|
||||||
|
Ensure all directories required for rsync exist with correct permissions.
|
||||||
|
'''
|
||||||
|
root_dirs = [
|
||||||
|
'/etc/rsync-juju.d',
|
||||||
|
]
|
||||||
|
[mkdir(d, owner='root', group='root') for d in root_dirs
|
||||||
|
if not os.path.isdir(d)]
|
||||||
|
|
||||||
|
rsyncd_base = """uid = nobody
|
||||||
|
gid = nogroup
|
||||||
|
pid file = /var/run/rsyncd.pid
|
||||||
|
syslog facility = daemon
|
||||||
|
socket options = SO_KEEPALIVE
|
||||||
|
|
||||||
|
&include /etc/rsync-juju.d
|
||||||
|
"""
|
||||||
|
|
||||||
|
f = open('/etc/rsyncd.conf','w')
|
||||||
|
f.write(rsyncd_base)
|
||||||
|
f.close()
|
||||||
|
|
@@ -56,6 +56,10 @@ from swift_storage_utils import (
|
|||||||
)
|
)
|
||||||
from charmhelpers.contrib.charmsupport.nrpe import NRPE
|
from charmhelpers.contrib.charmsupport.nrpe import NRPE
|
||||||
|
|
||||||
|
from charmhelpers.contrib.charmsupport.rsync import setup_rsync
|
||||||
|
|
||||||
|
from distutils.dir_util import mkpath
|
||||||
|
|
||||||
hooks = Hooks()
|
hooks = Hooks()
|
||||||
CONFIGS = register_configs()
|
CONFIGS = register_configs()
|
||||||
NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
|
NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
|
||||||
@@ -79,23 +83,12 @@ def config_changed():
|
|||||||
assert_charm_supports_ipv6()
|
assert_charm_supports_ipv6()
|
||||||
|
|
||||||
ensure_swift_directories()
|
ensure_swift_directories()
|
||||||
|
setup_rsync()
|
||||||
|
|
||||||
if openstack_upgrade_available('swift'):
|
if openstack_upgrade_available('swift'):
|
||||||
do_openstack_upgrade(configs=CONFIGS)
|
do_openstack_upgrade(configs=CONFIGS)
|
||||||
CONFIGS.write_all()
|
CONFIGS.write_all()
|
||||||
|
|
||||||
# If basenode is not installed and managing rsyncd.conf, replicate
|
|
||||||
# its core functionality. Otherwise concat files
|
|
||||||
if not os.path.exists('/etc/rsyncd.d/001-baseconfig'):
|
|
||||||
with open('/etc/rsyncd.d/001-baseconfig') as _in:
|
|
||||||
rsync_header = _in.read()
|
|
||||||
with open('/etc/rsyncd.d/050-swift-storage') as _in:
|
|
||||||
rsync_fragment = _in.read()
|
|
||||||
with open('/etc/rsyncd.conf', 'w') as out:
|
|
||||||
out.write(rsync_header + rsync_fragment)
|
|
||||||
else:
|
|
||||||
concat_rsync_fragments()
|
|
||||||
|
|
||||||
save_script_rc()
|
save_script_rc()
|
||||||
if relations_of_type('nrpe-external-master'):
|
if relations_of_type('nrpe-external-master'):
|
||||||
update_nrpe_config()
|
update_nrpe_config()
|
||||||
@@ -140,6 +133,8 @@ def swift_storage_relation_changed():
|
|||||||
@hooks.hook('nrpe-external-master-relation-changed')
|
@hooks.hook('nrpe-external-master-relation-changed')
|
||||||
def update_nrpe_config():
|
def update_nrpe_config():
|
||||||
log('Refreshing nrpe checks')
|
log('Refreshing nrpe checks')
|
||||||
|
if not os.path.exists(NAGIOS_PLUGINS):
|
||||||
|
mkpath(NAGIOS_PLUGINS)
|
||||||
rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nrpe-external-master',
|
rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nrpe-external-master',
|
||||||
'check_swift_storage.py'),
|
'check_swift_storage.py'),
|
||||||
os.path.join(NAGIOS_PLUGINS, 'check_swift_storage.py'))
|
os.path.join(NAGIOS_PLUGINS, 'check_swift_storage.py'))
|
||||||
@@ -151,6 +146,7 @@ def update_nrpe_config():
|
|||||||
os.path.join(SUDOERS_D, 'swift-storage'))
|
os.path.join(SUDOERS_D, 'swift-storage'))
|
||||||
# Find out if nrpe set nagios_hostname
|
# Find out if nrpe set nagios_hostname
|
||||||
hostname = None
|
hostname = None
|
||||||
|
host_context = None
|
||||||
for rel in relations_of_type('nrpe-external-master'):
|
for rel in relations_of_type('nrpe-external-master'):
|
||||||
if 'nagios_hostname' in rel:
|
if 'nagios_hostname' in rel:
|
||||||
hostname = rel['nagios_hostname']
|
hostname = rel['nagios_hostname']
|
||||||
@@ -158,7 +154,10 @@ def update_nrpe_config():
|
|||||||
break
|
break
|
||||||
nrpe = NRPE(hostname=hostname)
|
nrpe = NRPE(hostname=hostname)
|
||||||
|
|
||||||
current_unit = "%s:%s" % (host_context, local_unit())
|
if host_context:
|
||||||
|
current_unit = "%s:%s" % (host_context, local_unit())
|
||||||
|
else:
|
||||||
|
current_unit = local_unit()
|
||||||
|
|
||||||
# check the rings and replication
|
# check the rings and replication
|
||||||
nrpe.add_check(
|
nrpe.add_check(
|
||||||
|
@@ -92,8 +92,7 @@ SWIFT_SVCS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
RESTART_MAP = {
|
RESTART_MAP = {
|
||||||
'/etc/rsyncd.d/001-baseconfig': ['rsync'],
|
'/etc/rsync-juju.d/050-swift-storage.conf': ['rsync'],
|
||||||
'/etc/rsyncd.d/050-swift-storage': ['rsync'],
|
|
||||||
'/etc/swift/account-server.conf': ACCOUNT_SVCS,
|
'/etc/swift/account-server.conf': ACCOUNT_SVCS,
|
||||||
'/etc/swift/container-server.conf': CONTAINER_SVCS,
|
'/etc/swift/container-server.conf': CONTAINER_SVCS,
|
||||||
'/etc/swift/object-server.conf': OBJECT_SVCS,
|
'/etc/swift/object-server.conf': OBJECT_SVCS,
|
||||||
@@ -113,11 +112,6 @@ def ensure_swift_directories():
|
|||||||
]
|
]
|
||||||
[mkdir(d, owner='swift', group='swift') for d in dirs
|
[mkdir(d, owner='swift', group='swift') for d in dirs
|
||||||
if not os.path.isdir(d)]
|
if not os.path.isdir(d)]
|
||||||
root_dirs = [
|
|
||||||
'/etc/rsyncd.d',
|
|
||||||
]
|
|
||||||
[mkdir(d, owner='root', group='root') for d in root_dirs
|
|
||||||
if not os.path.isdir(d)]
|
|
||||||
|
|
||||||
|
|
||||||
def register_configs():
|
def register_configs():
|
||||||
@@ -126,9 +120,7 @@ def register_configs():
|
|||||||
openstack_release=release)
|
openstack_release=release)
|
||||||
configs.register('/etc/swift/swift.conf',
|
configs.register('/etc/swift/swift.conf',
|
||||||
[SwiftStorageContext()])
|
[SwiftStorageContext()])
|
||||||
configs.register('/etc/rsyncd.d/001-baseconfig',
|
configs.register('/etc/rsync-juju.d/050-swift-storage.conf',
|
||||||
[RsyncContext(), SwiftStorageServerContext()])
|
|
||||||
configs.register('/etc/rsyncd.d/050-swift-storage',
|
|
||||||
[RsyncContext(), SwiftStorageServerContext()])
|
[RsyncContext(), SwiftStorageServerContext()])
|
||||||
for server in ['account', 'object', 'container']:
|
for server in ['account', 'object', 'container']:
|
||||||
configs.register('/etc/swift/%s-server.conf' % server,
|
configs.register('/etc/swift/%s-server.conf' % server,
|
||||||
|
Reference in New Issue
Block a user