-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdex-init
executable file
·37 lines (29 loc) · 998 Bytes
/
dex-init
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
#!/bin/dash
# Copyright (c) 2014 - 2016 Luigi Tarenga <[email protected]>
# Distributed under the terms of a MIT license.
# parameters: [ lock_name [ timeout [ timeout2 ] ] ]
cd ${0%/*}
lname=${1:-default}
timeout=${2:-30}
timeout2=${3:-0}
hostname=$(hostname)
hostname=${hostname%%.*}
read lock_servers < conf/lock_servers
i=0; for h in $lock_servers ; do i=$((i+1)); done
majority=$((i/2+1))
echo $hostname $majority > temp/${lname}_params
echo $((timeout+timeout2)) > temp/${lname}_counter
echo "-invalid-" 0 0 "-invalid-" > temp/${lname}_htsp
if [ $i -eq 0 ] ; then
echo "$(date) Error: you cannot use dex-lock without lock servers configured."
exit 1
fi
if [ $i -eq 1 ] ; then
echo "$(date) Warning: with one not fault tolerant lock server you introduce a single point of failure."
exit 0
fi
if [ $((i%2)) -eq 0 ] ; then
echo "$(date) Warning: an even number of lock servers can bear to a split brain event."
else
echo "$(date) Lock initialization done."
fi