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