| Sean Dague | 5cad4d3 | 2015-11-10 14:39:07 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | # | 
|  | 3 | # lib/dlm | 
|  | 4 | # | 
|  | 5 | # Functions to control the installation and configuration of software | 
|  | 6 | # that provides a dlm (and possibly other functions). The default is | 
|  | 7 | # **zookeeper**, and is going to be the only backend supported in the | 
|  | 8 | # devstack tree. | 
|  | 9 |  | 
|  | 10 | # Dependencies: | 
|  | 11 | # | 
|  | 12 | # - ``functions`` file | 
|  | 13 |  | 
|  | 14 | # ``stack.sh`` calls the entry points in this order: | 
|  | 15 | # | 
|  | 16 | # - is_dlm_enabled | 
|  | 17 | # - install_dlm | 
|  | 18 | # - configure_dlm | 
|  | 19 | # - cleanup_dlm | 
|  | 20 |  | 
|  | 21 | # Save trace setting | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 22 | _XTRACE_DLM=$(set +o | grep xtrace) | 
| Sean Dague | 5cad4d3 | 2015-11-10 14:39:07 -0500 | [diff] [blame] | 23 | set +o xtrace | 
|  | 24 |  | 
|  | 25 |  | 
|  | 26 | # Defaults | 
|  | 27 | # -------- | 
|  | 28 |  | 
|  | 29 | # <define global variables here that belong to this project> | 
|  | 30 |  | 
|  | 31 | # Set up default directories | 
|  | 32 | ZOOKEEPER_DATA_DIR=$DEST/data/zookeeper | 
|  | 33 | ZOOKEEPER_CONF_DIR=/etc/zookeeper | 
|  | 34 |  | 
|  | 35 |  | 
|  | 36 | # Entry Points | 
|  | 37 | # ------------ | 
|  | 38 | # | 
|  | 39 | # NOTE(sdague): it is expected that when someone wants to implement | 
|  | 40 | # another one of these out of tree, they'll implement the following | 
|  | 41 | # functions: | 
|  | 42 | # | 
|  | 43 | # - dlm_backend | 
|  | 44 | # - install_dlm | 
|  | 45 | # - configure_dlm | 
|  | 46 | # - cleanup_dlm | 
|  | 47 |  | 
|  | 48 | # This should be declared in the settings file of any plugin or | 
| Swapnil Kulkarni (coolsvap) | 7f0be4f | 2015-11-20 10:52:59 +0530 | [diff] [blame] | 49 | # service that needs to have a dlm in their environment. | 
| Sean Dague | 5cad4d3 | 2015-11-10 14:39:07 -0500 | [diff] [blame] | 50 | function use_dlm { | 
|  | 51 | enable_service $(dlm_backend) | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | # A function to return the name of the backend in question, some users | 
|  | 55 | # are going to need to know this. | 
|  | 56 | function dlm_backend { | 
|  | 57 | echo "zookeeper" | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | # Test if a dlm is enabled (defaults to a zookeeper specific check) | 
|  | 61 | function is_dlm_enabled { | 
|  | 62 | [[ ,${ENABLED_SERVICES}, =~ ,"$(dlm_backend)", ]] && return 0 | 
|  | 63 | return 1 | 
|  | 64 | } | 
|  | 65 |  | 
|  | 66 | # cleanup_dlm() - Remove residual data files, anything left over from previous | 
|  | 67 | # runs that a clean run would need to clean up | 
|  | 68 | function cleanup_dlm { | 
|  | 69 | # NOTE(sdague): we don't check for is_enabled here because we | 
|  | 70 | # should just delete this regardless. Some times users updated | 
|  | 71 | # their service list before they run cleanup. | 
|  | 72 | sudo rm -rf $ZOOKEEPER_DATA_DIR | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | # configure_dlm() - Set config files, create data dirs, etc | 
|  | 76 | function configure_dlm { | 
|  | 77 | if is_dlm_enabled; then | 
|  | 78 | sudo cp $FILES/zookeeper/* $ZOOKEEPER_CONF_DIR | 
|  | 79 | sudo sed -i -e 's|.*dataDir.*|dataDir='$ZOOKEEPER_DATA_DIR'|' $ZOOKEEPER_CONF_DIR/zoo.cfg | 
|  | 80 | # clean up from previous (possibly aborted) runs | 
|  | 81 | # create required data files | 
|  | 82 | sudo rm -rf $ZOOKEEPER_DATA_DIR | 
|  | 83 | sudo mkdir -p $ZOOKEEPER_DATA_DIR | 
|  | 84 | # restart after configuration, there is no reason to make this | 
|  | 85 | # another step, because having data files that don't match the | 
|  | 86 | # zookeeper running is just going to cause tears. | 
|  | 87 | restart_service zookeeper | 
|  | 88 | fi | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | # install_dlm() - Collect source and prepare | 
|  | 92 | function install_dlm { | 
|  | 93 | if is_dlm_enabled; then | 
|  | 94 | if is_ubuntu; then | 
|  | 95 | install_package zookeeperd | 
|  | 96 | else | 
|  | 97 | die $LINENO "Don't know how to install zookeeper on this platform" | 
|  | 98 | fi | 
|  | 99 | fi | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | # Restore xtrace | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 103 | $_XTRACE_DLM | 
| Sean Dague | 5cad4d3 | 2015-11-10 14:39:07 -0500 | [diff] [blame] | 104 |  | 
|  | 105 | # Tell emacs to use shell-script-mode | 
|  | 106 | ## Local variables: | 
|  | 107 | ## mode: shell-script | 
|  | 108 | ## End: |