redash/setup/ubuntu/bootstrap.sh

110 lines
3.6 KiB
Bash
Raw Normal View History

#!/bin/bash
2017-04-03 07:30:06 +00:00
#
# This script setups Redash along with supervisor, nginx, PostgreSQL and Redis. It was written to be used on
# Ubuntu 16.04. Technically it can work with other Ubuntu versions, but you might get non compatible versions
# of PostgreSQL, Redis and maybe some other dependencies.
#
# This script is not idempotent and if it stops in the middle, you can't just run it again. You should either
# understand what parts of it to exclude or just start over on a new VM (assuming you're using a VM).
set -eu
REDASH_BASE_PATH=/opt/redash
2017-04-03 07:30:06 +00:00
REDASH_BRANCH="${REDASH_BRANCH:-master}" # Default branch/version to master if not specified in REDASH_BRANCH env var
REDASH_VERSION=${REDASH_VERSION-1.0.1.b2833} # Install latest version if not specified in REDASH_VERSION env var
LATEST_URL="https://s3.amazonaws.com/redash-releases/redash.${REDASH_VERSION}.tar.gz"
VERSION_DIR="/opt/redash/redash.${REDASH_VERSION}"
REDASH_TARBALL=/tmp/redash.tar.gz
2017-04-03 07:30:06 +00:00
FILES_BASE_URL=https://raw.githubusercontent.com/getredash/redash/${REDASH_BRANCH}/setup/ubuntu/files
2017-04-03 09:54:17 +00:00
cd /tmp/
2017-04-03 07:30:06 +00:00
verify_root() {
# Verify running as root:
if [ "$(id -u)" != "0" ]; then
if [ $# -ne 0 ]; then
echo "Failed running with sudo. Exiting." 1>&2
exit 1
fi
echo "This script must be run as root. Trying to run with sudo."
sudo bash "$0" --with-sudo
exit 0
fi
2017-04-03 07:30:06 +00:00
}
2017-04-03 07:30:06 +00:00
create_redash_user() {
adduser --system --no-create-home --disabled-login --gecos "" redash
}
2017-04-03 07:30:06 +00:00
install_system_packages() {
apt-get -y update
# Base packages
apt install -y python-pip python-dev nginx curl build-essential pwgen
# Data sources dependencies:
apt install -y libffi-dev libssl-dev libmysqlclient-dev libpq-dev freetds-dev libsasl2-dev
# SAML dependency
apt install -y xmlsec1
# Storage servers
2017-04-03 09:54:17 +00:00
apt install -y postgresql redis-server
apt install -y supervisor
2017-04-03 07:30:06 +00:00
}
2017-04-03 07:30:06 +00:00
create_directories() {
mkdir /opt/redash
chown redash /opt/redash
# Default config file
if [ ! -f "/opt/redash/.env" ]; then
sudo -u redash wget "$FILES_BASE_URL/env" -O /opt/redash/.env
fi
2017-04-03 07:30:06 +00:00
COOKIE_SECRET=$(pwgen -1s 32)
2017-04-03 09:54:17 +00:00
echo "export REDASH_COOKIE_SECRET=$COOKIE_SECRET" >> /opt/redash/.env
}
2017-04-03 07:30:06 +00:00
extract_redash_sources() {
sudo -u redash wget "$LATEST_URL" -O "$REDASH_TARBALL"
sudo -u redash mkdir "$VERSION_DIR"
sudo -u redash tar -C "$VERSION_DIR" -xvf "$REDASH_TARBALL"
ln -nfs "$VERSION_DIR" /opt/redash/current
ln -nfs /opt/redash/.env /opt/redash/current/.env
2017-04-03 07:30:06 +00:00
}
2017-04-03 07:30:06 +00:00
install_python_packages() {
pip install --upgrade pip
# TODO: venv?
2017-04-03 09:54:17 +00:00
pip install setproctitle # setproctitle is used by Celery for "pretty" process titles
2017-04-03 07:30:06 +00:00
pip install -r /opt/redash/current/requirements.txt
pip install -r /opt/redash/current/requirements_all_ds.txt
}
2017-04-03 07:30:06 +00:00
create_database() {
# Create user and database
sudo -u postgres createuser redash --no-superuser --no-createdb --no-createrole
sudo -u postgres createdb redash --owner=redash
cd /opt/redash/current
sudo -u redash bin/run ./manage.py database create_tables
2017-04-03 07:30:06 +00:00
}
2017-04-03 07:30:06 +00:00
setup_supervisor() {
wget -O /etc/supervisor/conf.d/redash.conf "$FILES_BASE_URL/supervisord.conf"
service supervisor restart
}
2017-04-03 07:30:06 +00:00
setup_nginx() {
rm /etc/nginx/sites-enabled/default
wget -O /etc/nginx/sites-available/redash "$FILES_BASE_URL/nginx_redash_site"
ln -nfs /etc/nginx/sites-available/redash /etc/nginx/sites-enabled/redash
service nginx restart
}
2017-04-03 07:30:06 +00:00
verify_root
install_system_packages
create_redash_user
create_directories
extract_redash_sources
install_python_packages
create_database
setup_supervisor
setup_nginx