-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge
92 lines (84 loc) · 1.95 KB
/
challenge
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
#!/bin/bash
# ------------------------------------------------------------------
# [Jimenez] devops challenge
# ------------------------------------------------------------------
VERSION=0.1.0
SUBJECT=jimenez-devops-challenge
read -r -d '' USAGE << EOM
challenge: Operates the DevOps challenge Vagrantfile.
usage: challenge [options]
-d (D)estroy the cluster (with confirmation)
-u Start (u)p the cluster
-p (P)rovision the cluster
-s (S)top the cluster
-e Susp(e)nd the cluster
-r (R)esume the cluster
-v Print script (v)ersion
-h Print this (h)elp
EOM
# --- Options processing -------------------------------------------
if [ $# == 0 ] ; then
echo -e "$USAGE"
exit 1;
fi
while getopts ":duspervh" optname
do
case "$optname" in
"d")
echo -e "Destroying the cluster CANNOT be undone.\nYou WILL lose persistent storage! Are you sure?"
select yn in "Yes" "No"; do
case $yn in
Yes ) vagrant destroy -f; break;;
No ) exit;;
esac
done
;;
"u")
vagrant up;
;;
"p")
vagrant provision;
;;
"s")
vagrant halt;
;;
"e")
vagrant suspend;
;;
"r")
vagrant resume;
;;
"v")
echo "challenge Version $VERSION"
exit 0;
;;
"h")
echo -e "$USAGE"
exit 0;
;;
"?")
echo "Unknown option $OPTARG"
exit 0;
;;
*)
echo "Unknown error while processing options"
exit 0;
;;
esac
done
shift $(($OPTIND - 1))
param1=$1
param2=$2
# --- Locks -------------------------------------------------------
LOCK_FILE=/tmp/$SUBJECT.lock
if [ -f "$LOCK_FILE" ]; then
echo "Script is already running"
exit
fi
trap "rm -f $LOCK_FILE" EXIT
touch $LOCK_FILE
# --- Body --------------------------------------------------------
# SCRIPT LOGIC GOES HERE
echo $param1
echo $param2
# -----------------------------------------------------------------