-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathsetup
executable file
·263 lines (225 loc) · 7.94 KB
/
setup
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#! /usr/bin/env bash
# If we have an error, bail out!
set -e
# If we're debugging, be really loudly verbose
[[ ! -z $DEBUG ]] && set -x
# Attempt to load up the /etc/lsb-release file to determine our OS. If none is
# found, we default our settings to RHEL/Amazon Linux as the original behavior
# of this script intended.
if [[ -f /etc/lsb-release ]]; then
dist=Ubuntu
elif [[ -f /etc/debian_version ]]; then
dist=Debian
else
dist=RedHat
fi
# Tell the user what OS we detected
echo "Detected OS Distro: ${dist}"
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" >&2
exit 1
fi
# Based on the OS, determine which commands we'll be calling to install/manage
# certain things
case "$dist" in
Ubuntu)
install_package="apt-get install -y"
init_dir=/etc/init.d
sysconfig_dir=/etc/default ;;
Debian)
install_package="apt-get install -y"
init_dir=/etc/init.d
sysconfig_dir=/etc/default ;;
*)
install_package="yum install -y"
init_dir=/etc/rc.d/init.d
sysconfig_dir=/etc/sysconfig ;;
esac
daemon_name=aws-kinesis-agent
agent_user_name=aws-kinesis-agent-user
bin_dir=/usr/bin
cron_dir=/etc/cron.d
config_dir=/etc/aws-kinesis
config_flow_dir=${config_dir}/agent.d
jar_dir=/usr/share/${daemon_name}/lib
dependencies_dir=./dependencies
log_dir=/var/log/${daemon_name}
state_dir=/var/run/${daemon_name}
agent_service=${init_dir}/${daemon_name}
usage() {
echo "Usage:"
echo "To install Kinesis Agent, type:"
echo " sudo <script-path>/setup --install"
echo "To uninstall Kinesis Agent, type:"
echo " sudo <script-path>/setup --uninstall"
}
fail() {
echo $1 >&2
exit 1
}
download_jar() {
group_id=$1
artifact_id=$2
version=$3
prefix="http://search.maven.org/remotecontent?filepath="
path=${group_id//.//}
jar_name=$artifact_id-$version.jar
tmp_dest=$(mktemp -u)
jar_dest=$dependencies_dir/$jar_name
url=${prefix}${path}/${artifact_id}/${version}/${jar_name}
# file exists? then don't download it!
[[ -f ${jar_dest} ]] && return
# download the file to a temp location, then if move it here if successful
echo "Downloading $jar_name ($url)..."
wget -q -P ${dependencies_dir} $url -O ${tmp_dest} && \
mv ${tmp_dest} ${jar_dest}
# Purge our temp file regardless of the status here
rm -f ${tmp_dest}
}
download_dependencies() {
which ant > /dev/null || $install_package ant
which wget > /dev/null || $install_package wget
install -d ${dependencies_dir}
echo "Downloading dependencies ..."
aws_java_sdk_version="1.12.390"
remote_mvn_pkg="com.amazonaws:aws-java-sdk-core:${aws_java_sdk_version} \
com.amazonaws:aws-java-sdk-kinesis:${aws_java_sdk_version} \
com.amazonaws:aws-java-sdk-cloudwatch:${aws_java_sdk_version} \
com.amazonaws:aws-java-sdk-sts:${aws_java_sdk_version} \
com.amazonaws:aws-java-sdk-ec2:${aws_java_sdk_version} \
com.fasterxml.jackson.core:jackson-annotations:2.17.2\
com.fasterxml.jackson.core:jackson-core:2.17.2 \
com.fasterxml.jackson.core:jackson-databind:2.17.2 \
com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.17.2 \
com.google.code.findbugs:jsr305:3.0.1 \
com.google.guava:guava:29.0-jre \
org.apache.httpcomponents:httpclient:4.5.13 \
org.apache.httpcomponents:httpclient-cache:4.5.1 \
org.apache.httpcomponents:httpmime:4.5.1 \
org.apache.httpcomponents:httpcore:4.4.3 \
org.apache.httpcomponents:httpcore-ab:4.4.3 \
org.apache.httpcomponents:httpcore-nio:4.4.3 \
commons-cli:commons-cli:1.2 \
commons-codec:commons-codec:1.6 \
commons-logging:commons-logging-adapters:1.1 \
commons-logging:commons-logging-api:1.1 \
org.apache.commons:commons-lang3:3.4 \
org.apache.logging.log4j:log4j-1.2-api:2.17.1 \
org.apache.logging.log4j:log4j-api:2.17.1 \
org.apache.logging.log4j:log4j-core:2.17.1 \
org.apache.logging.log4j:log4j-slf4j-impl:2.17.1 \
org.slf4j:slf4j-api:1.7.12 \
com.beust:jcommander:1.48 \
org.xerial:sqlite-jdbc:3.20.1 \
joda-time:joda-time:2.8.2 \
org.projectlombok:lombok:1.18.22"
for package in ${remote_mvn_pkg}
do
download_jar $(echo $package | tr : " ")
done
}
do_uninstall () {
echo "Uninstalling $daemon_name ..."
# stop the service if it's running
if [ -f $agent_service ]; then
echo "Stopping $daemon_name..."
$agent_service stop
fi
# remove the service from system services
echo "Removing $daemon_name from system services..."
case "$dist" in
Ubuntu) update-rc.d -f $daemon_name remove > /dev/null 2>&1 || true ;;
Debian) update-rc.d -f $daemon_name remove > /dev/null 2>&1 || true ;;
*) chkconfig --del $daemon_name > /dev/null 2>&1 || true ;;
esac
# remove the jars and config files
rm -rf ${state_dir}
rm -rf ${log_dir}
rm -rf ${jar_dir}
rm -f ${agent_service}
rm -f ${bin_dir}/start-${daemon_name}
# remove the user for starting the agent
userdel $agent_user_name > /dev/null || true
groupdel $agent_user_name > /dev/null || true
# remove sysconfig
rm -f ${sysconfig_dir}/${daemon_name}
# remove cron job
rm -f ${bin_dir}/${daemon_name}-babysit
rm -f ${cron_dir}/${daemon_name}
return 0
}
do_build () {
download_dependencies
ant || fail "Failed to build the Java project"
}
do_install () {
do_uninstall
echo "Installing Kinesis Agent ..."
do_build
install -d ${config_dir}
install -d ${config_flow_dir}
install -d ${jar_dir}
install -d ${init_dir}
install -d ${cron_dir}
install -d ${sysconfig_dir}
install -d ${log_dir}
install -d ${state_dir}
install -m755 ./bin/start-${daemon_name} ${bin_dir}
install -m755 ./bin/${daemon_name}-babysit ${bin_dir}
install -m644 ./${dependencies_dir}/* ${jar_dir}
install -m644 ./ant_build/lib/* ${jar_dir}
install -m755 ./bin/${daemon_name}.${dist} ${init_dir}/${daemon_name}
install -m644 ./support/${daemon_name}.cron ${cron_dir}/${daemon_name}
install -m644 ./support/${daemon_name}.sysconfig ${sysconfig_dir}/${daemon_name}
install -m644 ./support/log4j.xml ${config_dir}
# add a user for starting the agent
id -u $agent_user_name > /dev/null 2>&1 || \
useradd -c "Streaming Data Agent" -r $agent_user_name
usermod -L $agent_user_name
# change the owner of log files and checkpoint files to the user
chown -R $agent_user_name $state_dir
chown -R $agent_user_name $log_dir
config_file=${config_dir}/agent.json
[[ -f ${config_file} ]] || install -m644 ./configuration/release/${daemon_name}.json ${config_file}
echo "Configuration file installed at: ${config_file}"
echo "Configuration details:"
cat "${config_file}"
case "$dist" in
Ubuntu) update-rc.d $daemon_name defaults ;;
Debian) update-rc.d $daemon_name defaults ;;
*) chkconfig --add $daemon_name ;;
esac
echo "Amazon Kinesis Agent is installed successfully."
echo "To start the $daemon_name service, run:"
echo " sudo service $daemon_name start"
echo "To stop the $daemon_name service, run:"
echo " sudo service $daemon_name stop"
echo "To check the status of the $daemon_name service, run:"
echo " sudo service $daemon_name status"
echo ""
echo "$daemon_name log file will be found at: $log_dir"
echo "To make the agent automatically start at system startup, type:"
echo " sudo chkconfig $daemon_name on"
echo ""
echo "Your installation has completed!"
}
COMMAND=$1
case "$COMMAND" in
--build)
shift
do_build "$@"
;;
--install)
shift
do_install "$@"
;;
--uninstall)
shift
do_uninstall "$@"
echo "Kinesis Agent has been uninstalled"
;;
*)
usage
;;
esac