-
-
Save jacques/cac1845efd16bafed93887d2feaa1fbf to your computer and use it in GitHub Desktop.
Install re:dash on smartOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script is an attempt to rewrite the Ubuntu setup script for Redash along with supervisor, nginx, | |
# PostgreSQL and Redis. | |
# | |
# 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). | |
# This sets to immediately exit on a non-zero return status and also | |
# any unset Environment Variables are flagged as an error | |
set -eu | |
# Set Environment Variables | |
REDASH_BASE_PATH=/opt/redash | |
REDASH_BRANCH="${REDASH_BRANCH:-master}" # Default branch/version to master if not specified in REDASH_BRANCH env var | |
REDASH_VERSION=${REDASH_VERSION-1.0.3.b2850} # 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 | |
FILES_BASE_URL=https://raw.githubusercontent.com/getredash/redash/${REDASH_BRANCH}/setup/ubuntu/files | |
cd /tmp/ | |
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 | |
} | |
create_redash_user() { | |
#adduser --system --no-create-home --disabled-login --gecos "" redash | |
useradd redash | |
} | |
install_system_packages() { | |
pkgin -y update | |
# Base packages | |
pkgin install -y py27-pip | |
pkgin install -y nginx | |
#pkgin install -y curl | |
pkgin install -y build-essential | |
pkgin install -y pwgen | |
pkgin install subversion | |
# Data sources dependencies: | |
pkgin install -y py27-sqlite3 | |
pkgin install -y libffi | |
#pkgin install -y libssl-dev | |
pkgin install -y mysql-server | |
#pkgin install -y mysql-client # this one should be put in by -server | |
pkgin install -y libpqxx | |
pkgin install -y freetds | |
#pkgin install -y libsasl2-dev | |
pkgin install -y gsasl | |
# SAML dependency | |
pkgin install -y xmlsec1 | |
# Storage servers | |
pkgin install -y postgresql96 | |
pkgin install -y redis | |
#pkgin install -y supervisor | |
} | |
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 | |
COOKIE_SECRET=$(pwgen -1s 32) | |
echo "export REDASH_COOKIE_SECRET=$COOKIE_SECRET" >> /opt/redash/.env | |
} | |
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 | |
} | |
install_python_packages() { | |
pip install --upgrade pip | |
# TODO: venv? | |
pip install supervisor | |
pip install setproctitle # setproctitle is used by Celery for "pretty" process titles | |
pip install -r /opt/redash/current/requirements.txt | |
pip install -r /opt/redash/current/requirements_all_ds.txt | |
# there are some packages that are not available on pip (?!) | |
svn co http://svn.effbot.org/public/elementtree-1.3/ | |
python elementtree-1.3/setup.py install | |
} | |
create_database() { | |
svcadm enable pkgsrc/redis | |
# Start postgres server | |
mkdir /home/redash/postgres/ | |
chown postgres:postgres /home/redash/postgres | |
sudo -u postgres initdb /home/redash/postgres/ | |
sudo -u postgres postgres -D /home/redash/postgres >/home/redash/.logfile & | |
sleep 5 | |
# 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 | |
} | |
setup_supervisor() { | |
if [ ! -d "/etc/supervisor" ]; then | |
mkdir /etc/supervisor | |
fi | |
if [ ! -d "/etc/supervisor/conf" ]; then | |
mkdir /etc/supervisor/conf | |
fi | |
wget -O /etc/supervisor/conf/redash.conf "$FILES_BASE_URL/supervisord.conf" | |
supervisord -c /etc/supervisor/conf/redash.conf | |
} | |
setup_nginx() { | |
svcadm enable pkgsrc/nginx | |
if [ -d "/etc/nginx" ]; then | |
if [ -d "/etc/nginx/sites-enabled" ]; then | |
if [ -f "/etc/nginx/sites-enabled/default" ]; then | |
rm /etc/nginx/sites-enabled/default | |
fi | |
else | |
mkdir /etc/nginx/sites-enabled | |
fi | |
if [ ! -d "/etc/nginx/sites-available" ]; then | |
mkdir /etc/nginx/sites-available | |
fi | |
else | |
mkdir /etc/nginx | |
mkdir /etc/nginx/sites-enabled | |
mkdir /etc/nginx/sites-available | |
fi | |
wget -O /etc/nginx/sites-available/redash.conf "$FILES_BASE_URL/nginx_redash_site" | |
ln -nfs /etc/nginx/sites-available/redash.conf /etc/nginx/sites-enabled/redash.conf | |
svcadm restart pkgsrc/nginx | |
} | |
verify_root | |
install_system_packages | |
create_redash_user | |
create_directories | |
extract_redash_sources | |
install_python_packages | |
create_database | |
setup_supervisor | |
setup_nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment