fix odl patches
[ccsdk/distribution.git] / opendaylight / neon / neon-alpine / src / main / odlscripts / set_persistence.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
4 #
5 # This program and the accompanying materials are made available under the
6 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 # and is available at http://www.eclipse.org/legal/epl-v10.html
8 #
9
10
11 function usage()
12 {
13     # Print any error messages
14     test "$1" != "" && echo " ERROR: $1"
15
16     # Print standard usage help
17     cat << EOF
18  This script is used to enable or disable the config datastore
19  persistence. The default state is enabled. The user should
20  restart controller to apply changes. The script can be used
21  before starting controller for the first time.
22
23  Usage: $0 <on/off>
24
25 EOF
26
27     exit 1
28 }
29
30
31 function end_banner
32 {
33 cat <<EOF
34 ################################################
35 ##   NOTE: Manually restart controller to     ##
36 ##         apply configuration.               ##
37 ################################################
38 EOF
39 }
40
41
42 function get_cli_params
43 {
44     # Check if params have been supplied
45     test $# -eq 0 && usage
46
47     # First param is on/off
48     SWITCH="$1"
49
50     # Verify we only have 1 param
51     test $# -ne 1 && usage "Too many parameters"
52 }
53
54
55 function modify_conf_file
56 {
57     if [ "${SWITCH}" == "off"  ]; then
58         echo "disabling config datastore persistence"
59         sed -i -e "s/^#persistent=true/persistent=false/" ${CLUSTERCONF}
60     elif [ "${SWITCH}" == "on"  ]; then
61         echo "enabling config datastore persistence"
62         sed -i -e "s/^persistent=false/#persistent=true/" ${CLUSTERCONF}
63     else
64         usage "Allowed values are on/off"
65     fi
66 }
67
68
69 function verify_configuration_file
70 {
71     # Constants
72     BIN_DIR=`dirname $0`
73     test ${BIN_DIR} == '.' && BIN_DIR=${PWD}
74     CONTROLLER_DIR=`dirname ${BIN_DIR}`
75     CONF_DIR=${CONTROLLER_DIR}/etc
76     CLUSTERCONF=${CONF_DIR}/org.opendaylight.controller.cluster.datastore.cfg
77
78     # Verify configuration files are present in expected location.
79     if [ ! -f ${CLUSTERCONF} ]; then
80         # Check if the configuration files exist in the system
81         # directory, then copy them over.
82         ORIG_CONF_DIR=${CONTROLLER_DIR}/system/org/opendaylight/controller/sal-clustering-config
83         version=$(sed -n -e 's/.*<version>\(.*\)<\/version>/\1/p' ${ORIG_CONF_DIR}/maven-metadata-local.xml)
84         ORIG_CONF_DIR=${ORIG_CONF_DIR}/${version}
85         ORIG_CLUSTER_CONF=sal-clustering-config-${version}-datastore.cfg
86
87         if [ -f ${ORIG_CONF_DIR}/${ORIG_CLUSTER_CONF} ]; then
88             cat <<EOF
89  NOTE: Cluster configuration file not found. Copying from
90  ${ORIG_CONF_DIR}
91 EOF
92             cp ${ORIG_CONF_DIR}/${ORIG_CLUSTER_CONF} ${CLUSTERCONF}
93
94         else
95             usage "Cluster configuration file not found"
96         fi
97     fi
98 }
99
100 function main
101 {
102     get_cli_params "$@"
103     verify_configuration_file
104     modify_conf_file
105     end_banner
106 }
107
108 main "$@"
109
110 # vim: ts=4 sw=4 sts=4 et ft=sh :
111