Last active
October 5, 2015 10:47
-
-
Save swistak/2795920 to your computer and use it in GitHub Desktop.
Configuration for server with ultra fast depoys
This file contains hidden or 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
aptitude install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison git pwgen vim libcurl4-openssl-dev | |
chmod 777 /opt | |
adduser www | |
su www | |
cd ~ | |
curl -L get.rvm.io | bash -s stable | |
echo >> .bashrc | |
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> .bashrc | |
rvm install 1.9.3 | |
rvm 1.9.3 | |
gem install passenger bundler | |
passenger-install-nginx-module | |
exit # Back to root | |
cd /opt | |
mv /opt/nginx/conf/ /etc/nginx | |
ln -s /etc/nginx/ /opt/nginx/conf | |
wget -O init-deb.sh http://library.linode.com/assets/600-init-deb.sh | |
mv init-deb.sh /etc/init.d/nginx | |
chmod +x /etc/init.d/nginx | |
/usr/sbin/update-rc.d -f nginx defaults | |
/etc/init.d/nginx start | |
aptitude install postgresql-9.1 postgresql-client-9.1 libpq-dev |
This file contains hidden or 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 www; | |
worker_processes 5; | |
error_log /var/log/nginx/error.log; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
passenger_root /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12; | |
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.3-p194/ruby; | |
include mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay off; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
# output compression saves bandwidth | |
gzip on; | |
gzip_http_version 1.0; | |
gzip_comp_level 2; | |
gzip_proxied any; | |
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; | |
gzip_disable "MSIE [1-6].(?!.*SV1)"; | |
# Passanger config | |
passenger_pool_idle_time 1800; | |
passenger_max_pool_size 10; | |
passenger_max_instances_per_app 4; | |
server_names_hash_bucket_size 128; | |
server_names_hash_max_size 4096; | |
# SSL config | |
ssl_session_cache shared:SSL:30m; | |
ssl_session_timeout 30m; | |
include sites/*; | |
# A default server to fall back if some domain resolves to our server | |
server { | |
listen 80 default_server; | |
server_name _; | |
server_name_in_redirect off; | |
charset utf-8; | |
root /srv/default; | |
index index.html index.htm; | |
error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
} | |
} |
This file contains hidden or 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 | |
# An example hook script for the "post-receive" event. | |
# | |
# The "post-receive" script is run after receive-pack has accepted a pack | |
# and the repository has been updated. It is passed arguments in through | |
# stdin in the form | |
# <oldrev> <newrev> <refname> | |
# For example: | |
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master | |
# | |
# see contrib/hooks/ for a sample, or uncomment the next line and | |
# rename the file to "post-receive". | |
#. /usr/share/doc/git-core/contrib/hooks/post-receive-email | |
unset GIT_DIR # Reseting git directory so we can pull | |
data=$(cat) | |
# We notifty about commints only in master | |
if [[ $data == *refs/heads/master* ]]; then | |
cd /srv/%domain | |
git pull # Update repository | |
if [ -e config/environment.rb ] | |
then # Its a rails app | |
echo $data | /repo/%domain.git/hooks/pr-update-rails.sh | |
fi | |
fi | |
exec git-update-server-info # We set up GIT_DIR back |
This file contains hidden or 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 | |
# An example hook script for the "post-receive" event. | |
# | |
# The "post-receive" script is run after receive-pack has accepted a pack | |
# and the repository has been updated. It is passed arguments in through | |
# stdin in the form | |
# <oldrev> <newrev> <refname> | |
# For example: | |
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master | |
# | |
# see contrib/hooks/ for a sample, or uncomment the next line and | |
# rename the file to "post-receive". | |
#. /usr/share/doc/git-core/contrib/hooks/post-receive-email | |
echo "Loading rvm 1.9.3@%domain" | |
. /etc/profile.d/rvm.sh # Loading RVM | |
# OR if rvm is installed per user: | |
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" | |
rvm 1.9.3@%domain --create | |
# Or if we're relying on rvmrc in repo: | |
# rvm rvmrc load | |
if [ -e Gemfile ] | |
then | |
echo "Instaling bundle" | |
bundle install | grep -v Using | |
fi | |
if [ -e Rakefile ] | |
then | |
echo "Migrating" | |
rake db:migrate | |
fi | |
if [ -d tmp ] | |
then | |
echo "Restarting server." | |
touch tmp/restart.txt | |
fi |
This file contains hidden or 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 | |
site=$1 | |
if [ -z $site ] | |
then | |
echo "Usage:" | |
echo "site domain.pl" | |
exit -1 | |
fi | |
cd /repo | |
if [ -d $site.git ] | |
then | |
read -p "/repo/$site.git already exists. Override? (y/N) " -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
rm -rf $site.git | |
else | |
exit 1 | |
fi | |
fi | |
mkdir "$site.git" | |
cd $site.git | |
git init . --bare --shared | |
cd hooks | |
rm * | |
for hook in /repo/skel/hooks/*; do | |
dst=`basename "$hook"` | |
cat $hook | sed "s/%domain/$site/" > $dst; | |
done | |
echo "Hooks created" | |
chmod 777 * | |
cd /srv | |
if [ -d $site ] | |
then | |
read -p "/srv/$site already exists. Override? (y/N) " -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
rm -rf $site | |
else | |
exit 1 | |
fi | |
fi | |
git clone /repo/$site.git | |
echo "Cloned application." | |
if [ -e /etc/nginx/sites/$site ] | |
then | |
read -p "/etc/nginx/sites/$site already exists. Override? (y/N) " -r | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
exit 1 | |
fi | |
fi | |
cat /etc/nginx/site.skel | sed "s/%domain/$site/g" > /etc/nginx/sites/$site | |
echo "Created nginx site" | |
pw=`pwgen 16 1` | |
su postgres -c "createuser $site -d -e -S -R" | |
su postgres -c "psql -c \"ALTER USER \\\"$site\\\" WITH PASSWORD '$pw'\" -e" | |
su postgres -c "createdb $site -e -E utf8 -O $site" | |
su postgres -c "createdb test-$site -e -E utf8 -O $site" | |
config=$( | |
cat <<DOC | |
$RAILS_ENV: | |
adapter: postgresql | |
database: "$site" | |
username: "$site" | |
password: "$pw" | |
host: localhost | |
encoding: unicode | |
pool: 5 | |
timeout: 5000 | |
test: | |
adapter: postgresql | |
database: "test-$site" | |
username: "$site" | |
password: "$pw" | |
host: localhost | |
encoding: unicode | |
pool: 5 | |
timeout: 5000 | |
DOC | |
) | |
echo "$config" > $site.database.yml | |
echo "" | |
echo "************************************************************************" | |
echo "" | |
echo "Ok. You're all set up! (I hope), anyway:" | |
echo "git clone ssh://$site/repo/$site.git # For new project" | |
echo "git remote add $site ssh://$site/repo/$site.git # For existing project" | |
echo "" | |
echo "/etc/init/nginx restart # When you're ready" | |
echo "" | |
echo "Your database configuration was written to $site.database.yml" |
This file contains hidden or 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
server { | |
listen 80; | |
listen 443 ssl; | |
server_name %domain *.%domain; | |
# Set the max size for file uploads | |
client_max_body_size 20M; | |
# vhost specific access log | |
access_log /var/log/nginx/%domain.access.log main; | |
charset utf8; | |
passenger_enabled on; | |
passenger_set_cgi_param HTTP_X_FORWARDED_PROTO $scheme; | |
root /srv/%domain/public; | |
rails_env production; | |
# ssl_certificate /srv/ssl/.chained.crt; | |
# ssl_certificate_key /srv/ssl/.key; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment