-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.sh
executable file
·48 lines (36 loc) · 1.31 KB
/
install.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
47
48
#!/bin/bash
# Exit if there is an error
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# If script is executed as an unprivileged user
# Execute it as superuser, preserving environment variables
if [ $EUID != 0 ]; then
sudo -E "$0" "$@"
exit $?
fi
# If there is an .env file use it
# to set the variables
if [ -f $SCRIPT_DIR/.env ]; then
source $SCRIPT_DIR/.env
fi
# Check all required variables are set
: "${CACHE_LOGS_DIRECTORY:?must be set}"
: "${LOGSTASH_HOST:?must be set}"
# Install apt-transport-https
/usr/bin/apt update -y
/usr/bin/apt install -y apt-transport-https
# Add elastic apt repo if it does not already exist
if [[ ! -f /etc/apt/sources.list.d/elastic-6.x.list ]]; then
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
fi
# Install the key for the elastic repo
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
# Install filebeat
/usr/bin/apt update -y
/usr/bin/apt install -y filebeat
# Install the filebeat config file
/usr/bin/envsubst '$LOGSTASH_HOST $CACHE_LOGS_DIRECTORY' < "$SCRIPT_DIR/configs/filebeat.yml.templ" > "/etc/filebeat/filebeat.yml"
# Set filebeat to run at boot
/bin/systemctl enable filebeat
# Start filebeat
/bin/systemctl start filebeat