summaryrefslogtreecommitdiff
path: root/hooks
diff options
Diffstat (limited to 'hooks')
-rw-r--r--hooks/charmhelpers/payload/__init__.py1
-rw-r--r--hooks/charmhelpers/payload/execd.py50
-rwxr-xr-xhooks/hooks.py29
3 files changed, 76 insertions, 4 deletions
diff --git a/hooks/charmhelpers/payload/__init__.py b/hooks/charmhelpers/payload/__init__.py
new file mode 100644
index 0000000..fc9fbc0
--- /dev/null
+++ b/hooks/charmhelpers/payload/__init__.py
@@ -0,0 +1 @@
+"Tools for working with files injected into a charm just before deployment."
diff --git a/hooks/charmhelpers/payload/execd.py b/hooks/charmhelpers/payload/execd.py
new file mode 100644
index 0000000..6476a75
--- /dev/null
+++ b/hooks/charmhelpers/payload/execd.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import subprocess
+from charmhelpers.core import hookenv
+
+
+def default_execd_dir():
+ return os.path.join(os.environ['CHARM_DIR'], 'exec.d')
+
+
+def execd_module_paths(execd_dir=None):
+ """Generate a list of full paths to modules within execd_dir."""
+ if not execd_dir:
+ execd_dir = default_execd_dir()
+
+ if not os.path.exists(execd_dir):
+ return
+
+ for subpath in os.listdir(execd_dir):
+ module = os.path.join(execd_dir, subpath)
+ if os.path.isdir(module):
+ yield module
+
+
+def execd_submodule_paths(command, execd_dir=None):
+ """Generate a list of full paths to the specified command within exec_dir.
+ """
+ for module_path in execd_module_paths(execd_dir):
+ path = os.path.join(module_path, command)
+ if os.access(path, os.X_OK) and os.path.isfile(path):
+ yield path
+
+
+def execd_run(command, execd_dir=None, die_on_error=False, stderr=None):
+ """Run command for each module within execd_dir which defines it."""
+ for submodule_path in execd_submodule_paths(command, execd_dir):
+ try:
+ subprocess.check_call(submodule_path, shell=True, stderr=stderr)
+ except subprocess.CalledProcessError as e:
+ hookenv.log("Error ({}) running {}. Output: {}".format(
+ e.returncode, e.cmd, e.output))
+ if die_on_error:
+ sys.exit(e.returncode)
+
+
+def execd_preinstall(execd_dir=None):
+ """Run charm-pre-install for each module within execd_dir."""
+ execd_run('charm-pre-install', execd_dir=execd_dir)
diff --git a/hooks/hooks.py b/hooks/hooks.py
index ddb34ed..e224c04 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -61,8 +61,11 @@ from charmhelpers.core.hookenv import (
from charmhelpers.core.hookenv import log as juju_log
+from charmhelpers.payload.execd import execd_preinstall
+
from charmhelpers.core.host import (
service,
+ lsb_release,
)
from charmhelpers.contrib.hahelpers.cluster import (
@@ -890,13 +893,33 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
""" % (cron_runtime, script_filename))
+# We can remove this quirk when charm no longer supports trusty
+def arm64_trusty_quirk():
+ arch = subprocess.check_output(['dpkg', '--print-architecture']).strip()
+ if arch != 'arm64':
+ return
+ if lsb_release()['DISTRIB_CODENAME'] != 'trusty':
+ return
+ ppa = 'ppa:mongodb-arm64/ppa'
+ juju_log("*** Detected trusty/arm64. Archive version contains incomplete "
+ "mongodb port, enabling installs from %s ***" % (ppa))
+ add_source(ppa)
+
+
###############################################################################
# Hook functions
###############################################################################
@hooks.hook('install')
def install_hook():
+ juju_log('Begin install hook.')
+ execd_preinstall()
juju_log("Installing mongodb")
add_source(config('source'), config('key'))
+
+ # Allow users to bypass arm64/trusty workaround by adding their own source
+ if config('source') == 'None':
+ arm64_trusty_quirk()
+
apt_update(fatal=True)
apt_install(packages=INSTALL_PACKAGES, fatal=True)
@@ -1193,10 +1216,8 @@ def replica_set_relation_departed():
def data_relation_joined():
juju_log("data_relation_joined")
- return(relation_set(
- {
- 'mountpoint': '/srv/juju/mongodb-data'
- }))
+ return relation_set(relation_id(),
+ {'mountpoint': '/srv/juju/mongodb-data'})
@hooks.hook('data-relation-changed')