Goals of this tutorial:
- deploy a new Rails app with capistrano
- make it fast (total process takes less than 5 minutes)
- make it simple (no unecessary config)
- manual ssh to the server not required
Rails application stack:
- nginx
- unicorn
- postgresql
Goals of this tutorial:
Rails application stack:
This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.
http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL
| #!/bin/sh | |
| ### BEGIN INIT INFO | |
| # Provides: unicorn | |
| # Required-Start: $local_fs $remote_fs mysql | |
| # Required-Stop: $local_fs $remote_fs | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: unicorn initscript | |
| # Description: Unicorn is an HTTP server for Rack application | |
| ### END INIT INFO |
| #!/bin/sh | |
| set -u | |
| set -e | |
| # Example init script, this can be used with nginx, too, | |
| # since nginx and unicorn accept the same signals | |
| # Feel free to change any of the following variables for your app: | |
| APP_ROOT=/home/deploy/public_html/rm/current | |
| PID=$APP_ROOT/tmp/pids/unicorn.pid | |
| ENV=production |
| FFmpeg has been removed from Ubuntu 14.04 and was replaced by Libav. This decision has been reversed so that FFmpeg is available now in Ubuntu 15.04 again, but there is still no official package for 14.04. In this tutorial, I will show you how to install FFmpeg from mc3man ppa. Add the mc3man ppa: | |
| sudo add-apt-repository ppa:mc3man/trusty-media | |
| And confirm the following message by pressing <enter>: | |
| Also note that with apt-get a sudo apt-get dist-upgrade is needed for initial setup & with some package upgrades | |
| More info: https://launchpad.net/~mc3man/+archive/ubuntu/trusty-media | |
| Press [ENTER] to continue or ctrl-c to cancel adding it | |
| Update the package list. |
| # MySQL. Versions 4.1 and 5.0 are recommended. | |
| # | |
| # Install the MySQL driver: | |
| # gem install mysql2 | |
| # | |
| # And be sure to use new-style password hashing: | |
| # http://dev.mysql.com/doc/refman/5.0/en/old-client.html | |
| development: | |
| adapter: mysql2 | |
| encoding: utf8 |
| #!/usr/bin/env ruby | |
| # This is a basic deploy script for Heroku apps. | |
| # It provides a structure you can use to expand on | |
| # and add your own prereqs and deploy tasks. | |
| # | |
| # It basically ensures that: | |
| # 1. There are no uncommited files | |
| # 2. You can ssh to github | |
| # 3. You can connect to heroku |
| # Ways to execute a shell script in Ruby | |
| # Example Script - Joseph Pecoraro | |
| cmd = "echo 'hi'" # Sample string that can be used | |
| # 1. Kernel#` - commonly called backticks - `cmd` | |
| # This is like many other languages, including bash, PHP, and Perl | |
| # Returns the result of the shell command | |
| # Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111 |
| #!/usr/bin/env bash | |
| # obtains all data tables from database | |
| TS=`sqlite3 $1 "SELECT tbl_name FROM sqlite_master WHERE type='table' and tbl_name not like 'sqlite_%';"` | |
| # exports each table to csv | |
| for T in $TS; do | |
| sqlite3 $1 <<! | |
| .headers on |
| ############################################################################# | |
| # to use this in jruby: | |
| # | |
| # jgem install sequel | |
| # jgem install jdbc-sqlite3 | |
| # | |
| # for more info on the sequel library, go to http://sequel.rubyforge.org/ | |
| ############################################################################# | |
| require 'rubygems' |