-
Notifications
You must be signed in to change notification settings - Fork 0
/
daacs
executable file
·222 lines (167 loc) · 5.99 KB
/
daacs
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
current_dir="$(dirname $0)"
if [ "$current_dir" = "." ]; then
current_dir=`pwd`
fi
source "$current_dir/instance_helpers/colors.sh"
main(){
step1_option=$(pretty_read "
Type ${Color_Off}${Red}ctrl+c${Color_Off} or type ${Red}quit${Color_Off} to exit\n
1 - Install system dependencies\n
2 - Install daacs command in path\n
3 - Create system users\n
4 - Create/Update/Refresh instance\n
5 - Reset service\n
6 - Reset all services in folder\n
7 - Recreate service\n\n
Select an option: ")
if [ "$step1_option" = "" ]; then
echo "must select an option"
fi
if [ "$step1_option" = "quit" ]; then
echo "Good bye"
exit 1
fi
case "$step1_option" in
"1")
clear
source "$current_dir/DAACS-system-install.sh"
;;
"2")
source "$current_dir/instance_helpers/basic.sh"
home_directory=""
if [ -z "${HOME}" ];
then
home_directory="/home/$USER"
sed -i "1s/^/export HOME=${home_directory}\n/" "$home_directory/.bashrc"
else
home_directory="$HOME"
fi
if grep -wq "$current_dir" "$home_directory/.bashrc"
then
$(pretty_print "${Color_Off}${Red}daacs${Color_Off} command already installed...")
else
command="PATH=$(escape_backslash "$current_dir:${PATH}")"
sed -i -e "1s/^/$command\n/" "$home_directory/.bashrc"
pretty_print "${Color_Off}${Red}daacs${Color_Off} command installed now..."
fi
;;
"3")
clear
source "$current_dir/create_system_instance_users.sh"
;;
"4")
clear
source "$current_dir/create_daacs_instance.sh"
;;
"5")
clear
source "$current_dir/instance_helpers/basic.sh"
service_name=$(ask_read_question_or_try_again "Service name?: " true)
stagger_amount=$(ask_read_question_or_try_again "How many services to restart at once?: " true)
if [[ ! $stagger_amount =~ ^[0-9]+$ ]] ; then
printf "Stagger amount must be a number\n"
else
restart_services_with_stagger_by_service_name "$service_name" "$stagger_amount"
fi
;;
"6")
install_root=""
source "$current_dir/instance_helpers/basic.sh"
install_env_path=$(ask_read_question_or_try_again "Enter base path for install of DAACS env files (Leave blank to use default path): " false)
if [ "$install_env_path" = "" ]; then
install_root=$current_dir
install_env_path="$install_root/DAACS-Install-Defaults"
fi
install_folder_destination=$(ask_read_question_or_try_again "Enter folder to restart all services for install of DAACS: " true)
stagger_count=$(ask_read_question_or_try_again "stagger count: " false)
quiet_mode=$(ask_read_question_or_try_again "Output?: " false)
refresh_all_services_in_service_helper "$install_root" "$install_folder_destination" "" "$stagger_count" "$quiet_mode"
;;
"7")
source "$current_dir/instance_helpers/basic.sh"
# 1 - DAACS-Website
# 2 - DAACS-Qserver
# 3 - DAACS-Nginx
# 4 - DAACS-Backup
# 5 - DAACS-Memcached
base_path_folder_destination=$(ask_read_question_or_try_again "Enter absolute path destination for install of DAACS: " true)
install_folder_destination=$(ask_read_question_or_try_again "Enter folder destination for install of DAACS: " true)
read -p "
1 - DAACS-Website
2 - DAACS-Qserver
3 - DAACS-Nginx
4 - DAACS-Backup
5 - DAACS-Memcached
Select instance type to create: " instance_type
environment_type=$(ask_read_question_or_try_again "Environment type (dev, qa, prod, etc, etc): " true)
service_name=$(ask_read_question_or_try_again "Service name? : " true)
recreate_service "$service_name" "$base_path_folder_destination" "$install_folder_destination" "$instance_type" "$environment_type"
;;
*)
echo "Invalid option"
main
;;
esac
main
}
helpFunction()
{
echo ""
echo "Usage: $0 -f refresh -s service_name -a 2 -q true "
echo -e "\t-f Function to run (refresh)"
echo -e "\t-s Service name to run function on"
echo -e "\t-a The amount of times to sequence function"
echo -e "\t-q Quite mode: (Output or no output )"
exit 1 # Exit script after printing help
}
while getopts "f:s:a:q:b:d:t:i:e:" opt
do
case "$opt" in
f ) parameterF="$OPTARG" ;;
s ) parameterS="$OPTARG" ;;
a ) parameterA="$OPTARG" ;;
q ) parameterQ="$OPTARG" ;;
b ) parameterB="$OPTARG" ;;
d ) parameterD="$OPTARG" ;;
t ) parameterT="$OPTARG" ;;
i ) parameterI="$OPTARG" ;;
e ) parameterE="$OPTARG" ;;
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac
done
#example
#daacs -f refresh -s testweb -a 2
#daacs -f recreate -s devweb -b /home/vagrant -d daacsdev -t 1 -e dev
if [[ -z "$parameterF" ]] && [[ -z "$parameterS" ]];
then
main
else
if [[ "$parameterA" == "" ]]; then
parameterA=1
fi
if [[ "$parameterQ" == "true" ]]; then
parameterQ=true
elif [[ "$parameterQ" == "false" ]]; then
parameterQ=false
else
parameterQ=false
fi
# Begin script in case all parameters are correct
if [[ "$parameterS" == "help" ]] ; then
helpFunction
else
case "$parameterF" in
"refresh")
printf "Running refresh on ${parameterS} \n"
source "$current_dir/instance_helpers/basic.sh"
restart_services_with_stagger_by_service_name "$parameterS" "$parameterA" $parameterQ
;;
"recreate")
printf "Running recreate on ${parameterS} \n"
source "$current_dir/instance_helpers/basic.sh"
recreate_service "$parameterS" "$parameterB" "$parameterD" "$parameterT" "$parameterE"
;;
esac
fi
fi