forked from ceph/ceph-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·46 lines (37 loc) · 959 Bytes
/
entrypoint.sh
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
#!/bin/bash
set -e
IMAGENAME=${1:-${IMAGENAME}}
LOCKNAME=${2:-${HOSTNAME}}
LOCKID=${3:-${LOCKID}}
# ETCDCTL_PEERS - a comma-delimited list of machine addresses in the cluster (default: "127.0.0.1:4001")
: ${ETCDCTL_PEERS:=127.0.0.1:4001}
function usage() {
echo "$0 <pool/image> [lockName [lockId]]"
exit 255
}
# Make sure the image name is set
if [ ! -n "$IMAGENAME" ]; then
usage
fi
# Make sure the lock name is set
if [ ! -n "$LOCKNAME" ]; then
usage
fi
# If we were given an ETCD_LOCKID_KEY, use that to find
# the lock id
if [ -n "$ETCD_LOCKID_KEY" ]; then
LOCKID=$(etcdctl -C ${ETCDCTL_PEERS} --no-sync get $ETCD_LOCKID_KEY)
etcdctl -C ${ETCDCTL_PEERS} --no-sync rm $ETCD_LOCKID_KEY
fi
# If we do not have a LOCKID, die
if [ ! -n "$LOCKID" ]; then
echo "No LOCKID found"
exit 2
fi
# Release the lock
rbd lock remove $IMAGENAME $LOCKNAME $LOCKID
if [ $? -ne 0 ]; then
echo "Failed to release lock"
exit 1
fi
exit 0