File: provision.sh

package info (click to toggle)
ruby-influxdb 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 424 kB
  • sloc: ruby: 3,530; sh: 61; makefile: 7
file content (90 lines) | stat: -rwxr-xr-x 2,281 bytes parent folder | download
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
#!/bin/sh -e

if [ -z "$influx_version" ]; then
  echo "== Provisioning InfluxDB: Skipping, influx_version is empty"
  exit 0
else
  echo "== Provisioning InfluxDB ${influx_version}"
fi

package_name="influxdb_${influx_version}_amd64.deb"
[ -z "${channel}" ] && channel="releases"
download_url="https://dl.influxdata.com/influxdb/${channel}/${package_name}"


echo "== Downloading package"

if which curl 2>&1 >/dev/null; then
  curl "${download_url}" > "${HOME}/${package_name}"
else
  echo >&2 "E: Could not find curl"
  exit 1
fi

echo "== Download verification"
sha2_sum=$(sha256sum "${HOME}/${package_name}" | awk '{ print $1 }')

if [ -z "${pkghash}" ]; then
  echo "-- Skipping, pkghash is empty"
elif [ -n "${pkghash}" ] && [ "${sha2_sum}" != "${pkghash}" ]; then
  echo >&2 "E: Hash sum mismatch (got ${sha2_sum}, expected ${pkghash})"
  exit 1
fi
echo "-- Download has SHA256 hash: ${sha2_sum}"


echo "== Installing"

sudo dpkg -i "${HOME}/${package_name}"
sudo service influxdb start || true

echo "-- waiting for daemon to start"
while ! curl --head --fail --silent http://localhost:8086/ping; do
  echo -n "."
  sleep 1
done


echo "== Configuring"

echo "-- create admin user"
/usr/bin/influx -execute "CREATE USER root WITH PASSWORD 'toor' WITH ALL PRIVILEGES"

echo "-- create non-admin user"
/usr/bin/influx -execute "CREATE USER test_user WITH PASSWORD 'resu_tset'"

echo "-- create databases"
/usr/bin/influx -execute "CREATE DATABASE db_one"
/usr/bin/influx -execute "CREATE DATABASE db_two"

echo "-- grant access"
/usr/bin/influx -execute "GRANT ALL ON db_two TO test_user"


echo "== Download and import NOAA sample data"

curl https://s3.amazonaws.com/noaa.water-database/NOAA_data.txt > noaa.txt
/usr/bin/influx -import -path noaa.txt -precision s

echo "-- grant access"
/usr/bin/influx -execute "GRANT ALL ON NOAA_water_database TO test_user"


echo "== Enable authentication"

if [ ! -f /etc/influxdb/influxdb.conf ]; then
  echo >&2 "E: config file not found"
  exit 1
fi

sudo sed -i 's/auth-enabled = false/auth-enabled = true/' /etc/influxdb/influxdb.conf
sudo service influxdb restart || true

echo "-- waiting for daemon to restart"
while ! curl --head --fail --silent http://localhost:8086/ping; do
  echo -n "."
  sleep 1
done


echo "== Done"