Last active
August 29, 2015 13:56
-
-
Save willbarrett/9280373 to your computer and use it in GitHub Desktop.
Provisioning Script for Starter School
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/sh | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the nginx web server | |
# Description: starts nginx using start-stop-daemon | |
### END INIT INFO | |
PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/opt/nginx/sbin/nginx | |
NAME=nginx | |
DESC=nginx | |
test -x $DAEMON || exit 0 | |
# Include nginx defaults if available | |
if [ -f /etc/default/nginx ] ; then | |
. /etc/default/nginx | |
fi | |
set -e | |
case "$1" in | |
start) | |
echo -n "Starting $DESC: " | |
start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \ | |
--exec $DAEMON -- $DAEMON_OPTS | |
echo "$NAME." | |
;; | |
stop) | |
echo -n "Stopping $DESC: " | |
start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \ | |
--exec $DAEMON | |
echo "$NAME." | |
;; | |
restart|force-reload) | |
echo -n "Restarting $DESC: " | |
start-stop-daemon --stop --quiet --pidfile \ | |
/opt/nginx/logs/$NAME.pid --exec $DAEMON | |
sleep 1 | |
start-stop-daemon --start --quiet --pidfile \ | |
/opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS | |
echo "$NAME." | |
;; | |
reload) | |
echo -n "Reloading $DESC configuration: " | |
start-stop-daemon --stop --signal HUP --quiet --pidfile /opt/nginx/logs/$NAME.pid \ | |
--exec $DAEMON | |
echo "$NAME." | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
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
user deploy sudo; | |
worker_processes 4; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
tcp_nodelay on; | |
tcp_nopush on; | |
client_max_body_size 10M; | |
keepalive_timeout 75; | |
passenger_max_pool_size 10; | |
passenger_root /home/deploy/.rvm/gems/ruby-2.1.0/gems/passenger-4.0.37; | |
passenger_ruby /home/deploy/.rvm/gems/ruby-2.1.0/wrappers/ruby; | |
passenger_log_level 0; | |
gzip on; | |
gzip_http_version 1.0; | |
gzip_comp_level 2; | |
gzip_proxied any; | |
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; | |
server { | |
listen 80; | |
passenger_enabled on; | |
if (-f $request_filename/index.html) { | |
rewrite (.*) $1/index.html break; | |
} | |
if (-f $request_filename.html) { | |
rewrite (.*) $1.html break; | |
} | |
root /home/deploy/apps/jeffs-store/current/public; | |
rails_env production; | |
location / { | |
passenger_enabled on; | |
} | |
} | |
} |
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 | |
# Security | |
sudo /usr/sbin/useradd -m -p -g sudo $(openssl passwd -1 'deploy') deploy | |
# Exit immediately upon error | |
set -e | |
set -x | |
# Pre-install | |
sudo apt-get update && sudo env DEBIAN_FRONTEND=noninteractive apt-get upgrade --force-yes -qyu | |
# install dependencies | |
sudo apt-get install curl build-essential libyaml-dev libxml2-dev libxslt1-dev autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev libcurl4-openssl-dev git-core nodejs postgresql libpq-dev tree -y | |
# compile ruby 2.1.0p0 from source | |
wget ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.0.tar.gz | |
tar xzvf ruby-2.1.0.tar.gz | |
cd ruby-2.1.0 && ./configure --prefix=/usr/local && make && sudo make install | |
# Bundler/Passenger | |
echo 'gem: --no-ri --no-rdoc' > ~/.gemrc | |
sudo gem install bundler | |
sudo gem install passenger | |
sudo passenger-install-nginx-module --auto --auto-download --prefix=/opt/nginx | |
sudo su postgres | |
psql <<OMG | |
CREATE USER deploy WITH CREATEDB; | |
CREATE DATABASE jeffs OWNER deploy; | |
OMG | |
exit | |
wget https://gist.githubusercontent.com/willbarrett/9280373/raw/c8825bf2e9c9243201e4e0e974626501592ce81e/nginx | |
wget https://gist.githubusercontent.com/willbarrett/9280373/raw/c502a3d071f72f4fe9fbb2a1910a798ad3d1818c/nginx.conf | |
sudo mv nginx /etc/init.d/ | |
chmod +x /etc/init.d/nginx | |
sudo mv nginx.conf /opt/nginx/conf/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment