Created
July 17, 2014 04:02
-
-
Save bengolder/9fde4768eaf0509d6206 to your computer and use it in GitHub Desktop.
A series of steps to setup a bare Ubuntu server with nginx, supervisor, Gunicorn, and an existing Django app
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
############################################################################# | |
## ## | |
## LT-VIZ INITIAL SERVER SETUP ------------------------------------------ ## | |
## ## | |
## This is a list of bash commands that are used to setup a Ubuntu ## | |
## 14.04 server with nginx, gunicorn, and a Django app. ## | |
## ## | |
############################################################################# | |
############################################################################# | |
###### SSH SETTINGS ####################################################### | |
############################################################################# | |
# NOTE: if this is a new viztest server | |
# You will need to delete the viztest public key in local ~/.ssh/known_hosts | |
# setup ssh settings for the server | |
ssh viztest mkdir -p .ssh | |
cat ~/.ssh/id_rsa.pub | ssh viztest 'cat >> .ssh/authorized_keys' | |
# enter the server for the first time | |
# ssh settings should already be set in ~/.ssh/config | |
ssh viztest | |
############################################################################# | |
###### SYSTEM SOFTWARE INSTALLS ########################################### | |
############################################################################# | |
# make updates to packages | |
sudo aptitude update | |
sudo aptitude upgrade -y | |
sudo reboot | |
ssh viztest | |
# install server dependencies | |
sudo aptitude install \ | |
git \ | |
python-virtualenv \ | |
libpq-dev \ | |
python-dev \ | |
nginx \ | |
tree \ | |
unzip \ | |
supervisor \ | |
-y | |
############################################################################# | |
###### USERS, PERMISSIONS, AND THE VIRTUALENV ############################# | |
############################################################################# | |
# make webapps user group | |
sudo groupadd --system webapps | |
# add a user group for regular users | |
sudo groupadd webadmins | |
# make the user for the webapp | |
sudo useradd --system --gid webapps --shell /bin/bash --home /webapps/viz viz | |
# add ones self to the user group | |
sudo usermod -a -G webadmins `whoami` | |
# create the directory for the application and assign it to the user | |
sudo mkdir -p /webapps/viz/ | |
# does this cause problems for pip down the road? | |
sudo virtualenv /webapps/viz | |
sudo chown viz /webapps/viz/ | |
# add the group and give them ownership of the folder | |
# give read and write permissions | |
sudo chown -R viz:webadmins /webapps/viz | |
sudo chmod -R g+w /webapps/viz | |
# restart so software and permissions can all take effect | |
sudo reboot | |
############################################################################# | |
###### INITIAL APP DEPLOYMENT ############################################# | |
############################################################################# | |
# copy private config files over to server | |
scp ./viz/viz/private_settings.py viztest:/webapps/viz/private_settings.py | |
scp ./viz/viz/shared_private.py viztest:/webapps/viz/shared_private.py | |
scp ./viz/viz/gunicorn_start viztest:/webapps/viz/bin/gunicorn_start | |
scp ./viz/viz/viz.conf viztest:/webapps/viz/viz.conf | |
scp ./viz/viz/viz.nginxconf viztest:/webapps/viz/viz.nginxconf | |
# copy the code repository to the server | |
make deploy-test | |
############################################################################# | |
###### INITIAL SERVER CONFIGURATION DEPLOYMENT ############################ | |
############################################################################# | |
ssh viztest | |
# copy private configuration files for the server | |
sudo cp /webapps/viz/viz.conf /etc/supervisor/conf.d/viz.conf #supervisor | |
# nginx config settings | |
sudo cp /webapps/viz/viz.nginxconf /etc/nginx/sites-available/viz | |
sudo ln -s /etc/nginx/sites-available/viz /etc/nginx/sites-enabled/viz | |
sudo rm -rf /etc/nginx/sites-available/default | |
# refresh permissions | |
sudo chown -R viz:webadmins /webapps/viz | |
sudo chmod -R g+w /webapps/viz | |
sudo chmod +x /webapps/viz/bin/gunicorn_start | |
# make the log file | |
mkdir -p /webapps/viz/logs | |
touch /webapps/viz/logs/gunicorn_supervisor.log | |
############################################################################# | |
###### APP DEPENDENCY INSTALLS ############################################ | |
############################################################################# | |
source /webapps/viz/bin/activate | |
cd /webapps/viz/viz | |
# install python requirements | |
# these CANNOT be sudo commands, otherwise they won't install in virtualenv | |
make install-server | |
############################################################################# | |
###### START SERVICES ##################################################### | |
############################################################################# | |
# refresh supervisor settings | |
sudo supervisorctl reread | |
sudo supervisorctl update | |
# start the services | |
make run-nginx | |
make run-gunicorn | |
logout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment