2014-09-02 17:29:04 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-09-02 22:07:14 +03:00
|
|
|
# Provision script created for Ubuntu 14.04
|
2014-09-09 00:05:23 +03:00
|
|
|
|
2014-09-04 06:25:48 +03:00
|
|
|
APP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2014-09-08 20:49:37 +03:00
|
|
|
APP_USER="$( stat -c '%U' ${APP_DIR} )"
|
2014-09-02 17:29:04 +03:00
|
|
|
|
2014-09-09 00:05:23 +03:00
|
|
|
if [ -d "/vagrant" ]; then
|
|
|
|
# Control will enter here if $DIRECTORY exists.
|
|
|
|
APP_DIR="/vagrant"
|
|
|
|
APP_USER="vagrant"
|
|
|
|
fi
|
|
|
|
|
2014-09-18 18:13:33 +03:00
|
|
|
if [ "${APP_USER}" == "root" ]; then
|
|
|
|
echo "Installing app as root is not recommended"
|
|
|
|
echo "Username is determined by owner of application directory."
|
|
|
|
fi
|
2014-09-09 00:05:23 +03:00
|
|
|
|
2014-09-02 17:29:04 +03:00
|
|
|
echo "Provisioning..."
|
2014-09-18 18:13:33 +03:00
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y software-properties-common python-software-properties
|
2014-09-09 00:05:23 +03:00
|
|
|
sudo add-apt-repository -y ppa:chris-lea/node.js
|
|
|
|
sudo apt-get update
|
2014-10-07 00:07:20 +03:00
|
|
|
sudo apt-get install -y python build-essential pkg-config git \
|
|
|
|
python-pip python-virtualenv python-dev libxml2-dev libxslt1-dev zlib1g-dev \
|
|
|
|
libffi-dev libyaml-dev libssl-dev nodejs
|
2014-09-02 17:29:04 +03:00
|
|
|
|
|
|
|
# Default cache is memoization
|
|
|
|
|
|
|
|
# Redis
|
|
|
|
# add-apt-repository -y chris-lea/redis-server
|
|
|
|
# add-apt-repository -y chris-lea/python-redis
|
|
|
|
# apt-get update
|
|
|
|
# apt-get install -y redis-server
|
|
|
|
|
|
|
|
# Default DB is sqlite
|
|
|
|
|
|
|
|
# Mysql
|
|
|
|
# apt-get install -y mysql-server mysql-client
|
|
|
|
|
|
|
|
# MariaDB
|
|
|
|
# apt-get install -y mariadb-server mariadb-client
|
|
|
|
|
|
|
|
# Postgres
|
|
|
|
# apt-get install -y postgresql postgresql-contrib
|
|
|
|
|
|
|
|
# Install frontend assets
|
2014-09-09 00:05:23 +03:00
|
|
|
sudo npm install -g bower
|
2014-09-18 08:46:13 +03:00
|
|
|
sudo -iu ${APP_USER} bower --allow-root --config.cwd=${APP_DIR} --config.directory=realms/static/vendor --config.interactive=false install
|
2014-09-02 17:29:04 +03:00
|
|
|
|
2014-09-09 00:05:23 +03:00
|
|
|
sudo -iu ${APP_USER} virtualenv ${APP_DIR}/.venv
|
2014-09-02 17:29:04 +03:00
|
|
|
|
2014-10-17 00:54:45 +03:00
|
|
|
cd ${APP_DIR} && sudo -iu ${APP_USER} ${APP_DIR}/.venv/bin/pip install -r ${APP_DIR}/requirements-dev.txt
|
2014-09-02 17:29:04 +03:00
|
|
|
|
2014-09-08 20:49:37 +03:00
|
|
|
echo "Installing start scripts"
|
2014-09-19 07:12:57 +03:00
|
|
|
cat << EOF > /usr/local/bin/realms-wiki
|
|
|
|
#!/bin/bash
|
2014-10-17 00:54:45 +03:00
|
|
|
${APP_DIR}/realms-wiki "\$@"
|
2014-09-19 07:12:57 +03:00
|
|
|
EOF
|
|
|
|
|
2014-09-09 00:05:23 +03:00
|
|
|
sudo chmod +x /usr/local/bin/realms-wiki
|
2014-09-02 22:07:14 +03:00
|
|
|
|
|
|
|
cat << EOF > /etc/init/realms-wiki.conf
|
2014-10-17 00:54:45 +03:00
|
|
|
limit nofile 65335 65335
|
|
|
|
|
|
|
|
respawn
|
|
|
|
|
2014-09-02 22:07:14 +03:00
|
|
|
description "Realms Wiki"
|
|
|
|
author "scragg@gmail.com"
|
2014-10-17 00:54:45 +03:00
|
|
|
|
|
|
|
chdir ${APP_DIR}
|
|
|
|
|
|
|
|
env PATH=${APP_DIR}/.venv/bin:/usr/local/bin:/usr/bin:/bin:$PATH
|
|
|
|
env LC_ALL=en_US.UTF-8
|
|
|
|
env GEVENT_RESOLVER=ares
|
|
|
|
|
|
|
|
export PATH
|
|
|
|
export LC_ALL
|
|
|
|
export GEVENT_RESOLVER
|
|
|
|
|
2014-09-18 18:13:33 +03:00
|
|
|
setuid ${APP_USER}
|
|
|
|
setgid ${APP_USER}
|
2014-10-17 00:54:45 +03:00
|
|
|
|
2014-09-02 22:07:14 +03:00
|
|
|
start on runlevel [2345]
|
|
|
|
stop on runlevel [!2345]
|
2014-10-17 00:54:45 +03:00
|
|
|
|
2014-09-02 22:07:14 +03:00
|
|
|
respawn
|
2014-10-17 00:54:45 +03:00
|
|
|
|
|
|
|
exec gunicorn \
|
|
|
|
--name realms-wiki \
|
|
|
|
--access-logfile - \
|
|
|
|
--error-logfile - \
|
|
|
|
--worker-class gevent \
|
|
|
|
--workers 2 \
|
|
|
|
--bind 0.0.0.0:5000 \
|
|
|
|
--user ${APP_USER} \
|
|
|
|
--group ${APP_USER} \
|
|
|
|
--chdir ${APP_DIR} \
|
|
|
|
wsgi:app
|
2014-09-18 08:46:13 +03:00
|
|
|
EOF
|