#!/bin/bash # install_puma_and_nginx.sh #set -x # or set -v is used for debugging this script set -e # Any subsequent commands which fail will cause the shell script to exit immediately # For the sake of simplicity, project folder is /vagrant # server config are in /vagrant/config/server echo STEP: install puma sudo -i -u deployer /bin/bash -c 'cd /vagrant && gem install puma' cp /vagrant/config/server/puma.conf /vagrant/config/server/puma-manager.conf /etc/init echo "/vagrant" > /etc/puma-project-list.conf mkdir /puma_shared chown deployer:deployer /puma_shared sudo -u deployer mkdir /puma_shared/pids /puma_shared/sockets /puma_shared/log if [[ -f /vagrant/tmp/pids/server.pid ]]; then echo STEP: stop current rails server kill -9 `cat /vagrant/tmp/pids/server.pid` || rm /vagrant/tmp/pids/server.pid fi echo STEP: start puma start puma-manager echo STEP: install and configure nginx apt-get -y install nginx ln -s /vagrant/config/server/nginx.conf /etc/nginx/sites-enabled/default -f service nginx restart echo STEP: Visit your site on http://localhost:3000 or http://`ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'` echo STEP: tail -f /var/log/syslog echo STEP: tail -f tail -f /var/log/nginx/error.log echo STEP: tail -f /puma_shared/log/puma.stderr.log echo STEP: tail -f /vagrant/log/production.log # create password for deployer, run as root: # $ passwd deployer # add your public key for easier login # $ ssh-copy-id deployer@121... # disable root login in /etc/ssh/sshd_config # PermitRootLogin no # service ssh restart # https://www.digitalocean.com/community/tutorials/additional-recommended-steps-for-new-ubuntu-14-04-servers # enable firewall for ssh and 80 # sudo ufw allow ssh # ssh 22 # sudo ufw allow 80/tcp # http # sudo ufw allow 443/tcp # https # sduo ufw allow 3306 # mysql # sudo ufw show added # sudo ufw enable