diff --git a/readme.md b/readme.md index 5d4257d..69ccc6b 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,16 @@ # CLONES FOR EVERYBODY + +## Setup + +This has been tested with Ubuntu 14.04 on a Digital Ocean server. + +Run: +```bash +$ ./setup/setup.sh +``` + +If you're having issues: +* nginx logs: `/var/log/nginx/` +* supervisor logs: `/var/log/supervisor/` +* celery logs: `/var/log/celery/` +* application logs: `/var/log/ustwo.log` diff --git a/setup/nginx/ustwo.hyper.pub.conf b/setup/nginx/ustwo.hyper.pub.conf new file mode 100644 index 0000000..926f469 --- /dev/null +++ b/setup/nginx/ustwo.hyper.pub.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name ustwo.hyper.pub; + + location /static { + alias /srv/ustwo/app/static; + } + + location / { + include uwsgi_params; + uwsgi_pass unix:/tmp/uwsgi.sock; + uwsgi_param UWSGI_PYHOME /env/ustwo; + uwsgi_param UWSGI_CHDIR /srv/ustwo; + uwsgi_param UWSGI_MODULE application; + uwsgi_param UWSGI_CALLABLE app; + } + + error_page 404 /404.html; + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/setup/setup.sh b/setup/setup.sh new file mode 100755 index 0000000..9895c97 --- /dev/null +++ b/setup/setup.sh @@ -0,0 +1,46 @@ +# Get ready +sudo apt-get update && sudo apt-get upgrade + +# Packages +sudo apt-get install nginx python3-pip git uwsgi supervisor uwsgi-plugin-python uwsgi-plugin-python3 ruby npm rabbitmq-server + +# NPM/Bower +sudo ln -s /usr/bin/nodejs /usr/bin/node +sudo npm install -g bower + +# MongoDB +sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 +echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee -a /etc/apt/sources.list +sudo apt-get update && sudo apt-get upgrade +sudo apt-get install mongodb-10gen +sudo service mongodb start + +# Virtualenv +pip3 install virtualenv +virtualenv -p python3 /env/ustwo --no-site-packages + +# Sass +gem install sass + +# Setup app +cd /srv +git clone https://github.com/publicscience/ustwo.git +cd /srv/ustwo +source /env/ustwo/bin/activate +pip install -r requirements.txt +bower install + +# Celery +sudo mkdir /var/log/celery +sudo adduser --system celery --group + +# Supervisor +sudo cp /srv/ustwo/setup/supervisor/*.conf /etc/supervisor/conf.d/ + +# Nginx +sudo sed -i '' 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/g' /etc/nginx/nginx.conf +sudo cp /srv/ustwo/setup/nginx/*.conf /etc/nginx/conf.d/ + +# Restart +sudo service nginx restart +sudo service supervisor restart \ No newline at end of file diff --git a/setup/supervisor/celery.conf b/setup/supervisor/celery.conf new file mode 100644 index 0000000..8c6a7f4 --- /dev/null +++ b/setup/supervisor/celery.conf @@ -0,0 +1,26 @@ +[program:celery] +; Set full path to celery program if using virtualenv +command=/env/ustwo/bin/celery worker --loglevel=INFO --config=config + +directory=/srv/ustwo +stdout_logfile=/var/log/celery/worker.log +stderr_logfile=/var/log/celery/worker.log +autostart=true +autorestart=true +startsecs=10 + +user=celery +group=celery + +; Need to wait for currently executing tasks to finish at shutdown. +; Increase this if you have very long running tasks. +stopwaitsecs = 600 + +; When resorting to send SIGKILL to the program to terminate it +; send SIGKILL to its whole process group instead, +; taking care of its children as well. +killasgroup=true + +; if rabbitmq is supervised, set its priority higher +; so it starts first +priority=998 diff --git a/setup/supervisor/ustwo.conf b/setup/supervisor/ustwo.conf new file mode 100644 index 0000000..ae3ad35 --- /dev/null +++ b/setup/supervisor/ustwo.conf @@ -0,0 +1,8 @@ +[program:ustwo] +command=/usr/bin/uwsgi --plugin python3 -s /tmp/uwsgi.sock -w application:app -H /env/ustwo --chmod-socket=666 +directory=/srv/ustwo +autostart=true +autorestart=true +stdout_logfile=/var/log/ustwo.log +redirect_stderr=true +stopsignal=QUIT