Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 87 lines (67 sloc) 3.345 kB
ca6ff44 @whitecl Sample production Procfile, add notes about production server setup t…
authored
1 ************ Production Environment - runs Ubuntu 11.10*****
2 Before compiling ruby:
3 sudo apt-get install git-core curl mysql-server mysql-client build-essential zlib1g-dev libmysql-ruby libmysqlclient-dev libopenssl-ruby libssl-dev libopenssl-ruby libreadline-dev libxml2 libxml2-dev libxslt1-dev redis-server
4
5 For other dependencies:
6 sudo apt-get install imagemagick --fix-missing
7
8 ************ Database *******************
9 Copy config/database-example.yml to config/database.yml
10 rake db:create
11 rake db:migrate
12
13 ************ Timezones ******************
14 Time math relies on the timezone set in application.rb matching your system's time zone.
15 40 Days is in US/Eastern
16
17 In Ubuntu Lucid:
18 sudo dpkg-reconfigure tzdata
19
20 ************ Dev Environment Web Server *********************
21 After running bundle install and completing db migrations and seeds:
22 cp Procfile.example-dev
23 bundle exec foreman start
24
25 ************ Production Server Firewall
26 In order to run thin in the user space, we're doing the following to iptables:
27 sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
28 sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
29 sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
30 sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
31 sudo iptables -A INPUT -i lo -j ACCEPT
32 sudo iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
33 sudo iptables -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
34 sudo iptables -A INPUT -j DROP
35 sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000
36
37 Config the system to save and restore iptables rules on startup/shutdown
38 sudo sh -c "iptables-save -c > /etc/iptables.rules"
39
40 sudo vim /etc/network/interfaces
41 At the end of each eth section:
42 pre-up iptables-restore < /etc/iptables.rules
43 post-down iptables-save -c > /etc/iptables.rules
44
45 ************ Staging/Production Web Server ******************
46
47 Configure rbenv, ruby 1.9.2-p290 and 40Days under the fortydays user
48
49 In Ubuntu, make sure the rbenv start scripts (see rbenv docs) are added to .profile
50 - Adding them to .bashrc will cause the exported upstart scripts to not be able to use rbenv.
51
52 Copy Procfile.example to Procfile
53 bundle install
54 bundle exec foreman export upstart /tmp/upstart -a fortydays -u fortydays
55 sudo cp /tmp/upstart/* /etc/init
56
57 sudo vi /etc/init/fortydays.conf
58 Add this to the top to enable start on server reboot:
59 start on runlevel [2345]
60
61 Now you can use magic start/stop commands.
62 sudo start fortydays
63 sudo restart fortydays
64 sudo stop fortydays
65
66 Note: start/restart takes > 60 seconds, so may be a good low-traffic time of day thing to do.
67
68 Articles this method is based on:
69 http://blog.daviddollar.org/2011/05/06/introducing-foreman.html
70 http://michaelvanrooijen.com/articles/2011/06/08-managing-and-monitoring-your-ruby-application-with-foreman-and-upstart/
71
72 ************ Administration in the Staging/Production Environment *********
73 swap 'staging' and 'production' in these commands as needed.
74
75 Start/stop web server & worker process
76 sudo start fortydays
77 sudo stop fortydays
78
79 Updating code & db:
80 Log in as fortydays
8d95da7 @chadburrus fix the readme text
chadburrus authored
81 cd fortydays
ca6ff44 @whitecl Sample production Procfile, add notes about production server setup t…
authored
82 git pull
83 bundle install
b8fe969 @whitecl Add desired week selection and rough description field to contributor…
authored
84 RAILS_ENV=production bundle exec rake db:migrate
85 RAILS_ENV=production bundle exec rake assets:precompile
ca6ff44 @whitecl Sample production Procfile, add notes about production server setup t…
authored
86 sudo restart fortydays
Something went wrong with that request. Please try again.