Skip to content

Instantly share code, notes, and snippets.

@ndbroadbent
Created May 13, 2011 20:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ndbroadbent/971255 to your computer and use it in GitHub Desktop.
Save ndbroadbent/971255 to your computer and use it in GitHub Desktop.
Deploy Fat Free CRM (rails3 branch) to a freshly installed Ubuntu machine.
#!/bin/bash
#
# => $ sudo apt-get install -y --force-yes curl; sudo su - -c "bash < <(curl -sL http://is.gd/..........)"
#
# Deploy Fat Free CRM (rails3 branch) to a freshly installed Ubuntu machine.
# --------------------------------------------------------------------------
#
# Steps:
#
# *) Install required packages (git, postgresql, etc.)
# *) Configure PostgreSQL
# *) Install RVM & Ruby
# *) Install Passenger
# *) Install Fat Free CRM
# *) Configure Fat Free CRM database settings
# *) Install Fat Free CRM production gems to vendor/gems
# *) Create & migrate Fat Free CRM database & load settings
# *) Create default admin user
# *) Configure machine hostname
# *) Configure passenger standalone service (runs on startup)
# *) Set permissions
# *) Start passenger service, which:
# *) Downloads and compiles Nginx
# *) Installs Phusion Passenger Standalone
# *) Starts the web server on port :80
#
# After this process has finished, you should be able to load http://localhost in your browser.
# 'http://fat_free_crm' and http://xx.xx.xx.xx (IP address) should be accessible from other machines.
# (type 'ifconfig' in terminal to find your IP address)
# Variables
# ----------------------------------------------------------
app_name="fat_free_crm"
app_repo="https://github.com/michaeldv/fat_free_crm.git"
app_path="/opt/rails/$app_name"
ruby_version=ruby-1.9.2-p136
# *) Install required packages
# ----------------------------------------------------------
apt-get update
apt-get install -y --force-yes curl git-core postgresql libpq-dev build-essential libcurl4-openssl-dev zlib1g-dev
# *) Configure PostgreSQL
# ----------------------------------------------------------
sed -e "s|local *all *postgres .*|local all postgres trust|g" \
-e "s|local *all *all .*|local all all trust|g" \
-e "s|host *all *all *127.0.0.1/32 .*|host all all 127.0.0.1/32 trust|g" \
-e "s|host *all *all *::1/128 .*|host all all ::1/128 trust|g" \
-i /etc/postgresql/8.*/main/pg_hba.conf
/etc/init.d/postgresql restart
# *) Install RVM & Ruby
# ----------------------------------------------------------
if ! (which rvm) then
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
fi
# Loads RVM into the current shell session
. "/usr/local/rvm/scripts/rvm"
# Install the configured ruby version
if ! (rvm list | grep -q $ruby_version); then
rvm install $ruby_version
fi
# Use the installed ruby environment
rvm use "$ruby_version"
# Configure .gemrc to ignore ri and rdoc
echo "gem: --no-ri --no-rdoc" > $HOME/.gemrc
# Install bundler and passenger
if ! (gem list | grep -q "bundler"); then gem install bundler; fi
if ! (gem list | grep -q "passenger"); then gem install passenger; fi
# *) Install Fat Free CRM
# ----------------------------------------------------------
mkdir -p /opt/rails
git clone $app_repo $app_path
cd $app_path
git checkout -t origin/rails3
# *) Configure Fat Free CRM database settings
# ----------------------------------------------------------
cat << EOF > $app_path/config/database.yml
production:
adapter: postgresql
database: fat_free_crm_production
username: postgres
password:
host: localhost
port: 5432
schema_search_path: public
EOF
# *) Install Fat Free CRM production gems
# ----------------------------------------------------------
# Make passenger look in the right place for gems
mkdir -p $app_path/.bundle
cat << EOF > $app_path/.bundle/config
---
BUNDLE_WITHOUT: development:test
BUNDLE_PATH: /usr/local/rvm/gems/$ruby_version/bundler
EOF
cd $app_path
bundle install --without development test
# *) Create & migrate Fat Free CRM database & load settings
# ----------------------------------------------------------
RAILS_ENV=production rake db:create db:migrate crm:settings:load
# *) Create default admin user
# ----------------------------------------------------------
RAILS_ENV=production rake crm:setup:admin USERNAME=admin PASSWORD=admin EMAIL=admin@example.com
# *) Configure machine hostname
# ----------------------------------------------------------
echo "fat_free_crm" > /etc/hostname
restart hostname
# *) Configure passenger standalone init script
# (Uses https://github.com/ndbroadbent/passenger-initscript)
# --------------------------------------------------------------
groupadd passenger
useradd passenger -g passenger
cd /etc/init.d
curl https://github.com/ndbroadbent/passenger-initscript/raw/master/passenger -o passenger
chmod +x passenger
# Setup 'passenger-initscripts'
/etc/init.d/passenger setup
# Configure Fat Free CRM passenger config
cat << EOF > /etc/passenger.d/$app_name.yml
rvm: $ruby_version
cwd: $app_path
user: passenger
port: 80
environment: production
max-pool-size: 4
min-instances: 1
pid-file: $app_path/tmp/pids/passenger.pid
log-file: $app_path/log/passenger.log
EOF
# Make directory for passenger pids
mkdir -p $app_path/tmp/pids
mkdir -p $app_path/log
# *) Set permissions
# ----------------------------------------------------------
chown -R passenger:passenger $app_path
# *) Start passenger service
# ----------------------------------------------------------
/etc/init.d/passenger start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment