summaryrefslogtreecommitdiffstats
path: root/extras/thin-arbiter/setup-thin-arbiter.sh
blob: 1c77cf07c573ebfe2a4d01c3b0193bf252b0eeb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
#  Copyright (c) 2018-2019 Red Hat, Inc. <http://www.redhat.com>
#  This file is part of GlusterFS.
#
#  This file is licensed to you under your choice of the GNU Lesser
#  General Public License, version 3 or any later version (LGPLv3 or
#  later), or the GNU General Public License, version 2 (GPLv2), in all
#  cases as published by the Free Software Foundation.


#  This tool has been developed to setup thin-arbiter process on a node.
#  Seting up a thin arbiter process involves following files -
#  1 - thin-arbiter.vol
#  Thin-arbiter (TA) process will use the graph in this file to load the
#  required translators.
#  2 - gluster-ta-volume.service (generated by gluster-ta-volume.service.in)
#  TA process would be running as systemd service.
#
#  TA process uses a location to save TA id files for every subvolume.
#  This location can be taken as input from user. Once provided and the
#  TA process is started on a node, it can not be changed using this
#  script or by any other mean. The same location should be used in
#  the gluster CLI when creating thin-arbiter volumes.


volloc="/var/lib/glusterd/thin-arbiter"
mkdir -p $volloc

if [ -f /etc/glusterfs/thin-arbiter.vol ]; then
    volfile=/etc/glusterfs/thin-arbiter.vol
else
    volfile=extras/thin-arbiter/thin-arbiter.vol
fi

tafile="$volloc/thin-arbiter.vol"


help () {
    echo " "
    echo '  This tool helps to setup thin-arbiter (TA) process on a node.
  TA process uses a location to save TA id files for every subvolume.
  This location can be taken as input from user. Once provided and the
  TA process is started on a node, it can not be changed using this script
  or by any other mean. The same location should be used in gluster CLI
  when creating thin-arbiter volumes.

  usage: setup-thin-arbiter.sh [-s] [-h]
    options:
    -s - Setup thin-arbiter file path and start process
    -h - Show this help message and exit
'
}

volfile_set_brick_path () {
    while read -r line
    do
        dir=`echo "$line" | cut -d' ' -f 2`
        if [ "$dir" = "directory" ]; then
            bpath=`echo "$line" | cut -d' ' -f 3`
            sed -i -- 's?'$bpath'?'$1'?g' $tafile
            return
        fi
    done < $tafile
}

check_ta_proc () {
    pro=`ps aux | grep thin-arbiter.vol | grep "volfile-id"`
    if [ "${pro}" = '' ]; then
            echo ""
    else
        curr_loc=`cat $volloc/thin-arbiter.vol | grep option | grep directory`
        loc=`echo "${curr_loc##* }"`
        echo "******************************************************"
        echo "Error:"
        echo "Thin-arbiter process is running with thin-arbiter path = $loc"
        echo "Can not change TA path on this host now."
        echo "$pro"
        echo "******************************************************"
        exit 1
    fi
}

getpath () {
    check_ta_proc
    echo "******************************************************"
    echo "User will be required to enter a path/folder for arbiter volume."
    echo "Please note that this path will be used for ALL VOLUMES using this"
    echo "node to host thin-arbiter. After setting, if a volume"
    echo "has been created using this host and path then path for"
    echo "thin-arbiter can not be changed "
    echo "******************************************************"
    echo " "
    while true;
    do
        echo -n "Enter brick path for thin arbiter volumes: "
        echo " "
        read tapath
        if [ "${tapath}" = '' ]; then
            echo "Please enter valid path"
            continue
        else
            echo "Entered brick path : $tapath "
            echo "Please note that this brick path will be used for ALL"
            echo "VOLUMES using this node to host thin-arbiter brick"
            echo -n "Want to continue? (y/N): "
            echo " "
            read cont

            if [ "${cont}" = 'N' ] || [ "${cont}" = 'n' ]; then
                exit 0
            else
                break
            fi
        fi
    done
}

setup () {
    getpath
    mkdir -p $tapath/.glusterfs/indices
    if [ -d $tapath/.glusterfs/indices ]; then
        echo " "
    else
        echo "Could not create $tapath/.glusterfs/indices directory, check provided ta path."
        exit 1
    fi

    cp -f --backup --suffix=_old $volfile $volloc/thin-arbiter.vol
    volfile_set_brick_path "$tapath"

    echo "Directory path to be used for thin-arbiter volume is: $tapath"
    echo " "
    echo "========================================================"

    if [ -f /usr/lib/systemd/system/gluster-ta-volume.service ]; then
        echo "Starting thin-arbiter process"
    else
        cp ../systemd/gluster-ta-volume.service /etc/systemd/system/
        echo "Starting thin-arbiter process"
        chmod 0644 /etc/systemd/system/gluster-ta-volume.service
    fi

    systemctl daemon-reload
    systemctl enable gluster-ta-volume
    systemctl stop gluster-ta-volume
    systemctl start gluster-ta-volume

    if [ $? == 0 ]; then
        echo "thin-arbiter process has been setup and running"
    else
        echo "Failed to setup thin arbiter"
        exit 1
    fi

}

main()
{

    if [ "$#" -ne 1 ]; then
        help
        exit 0
    fi

    while getopts "sh" opt; do
        case $opt in
            h)
                help
                exit 0
                ;;
            s)
                setup
                exit 0
                ;;
            *)
                help
                exit 0
                ;;
        esac
    done
}

main "$@"