Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: modules/discourse/files/init-discourse

Issue 9377123: Set up proper FastCGI environment for Discourse and use nginx (Closed)
Patch Set: Converted init_discourse script to Python Created Feb. 18, 2013, 2:03 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/bin/bash 1 #!/usr/bin/env python
2 2
3 scm_url="https://hg.adblockplus.org/discourse" 3 import sys, os, pwd, subprocess
4 tmp_dir="/tmp/discourse-$$"
5 config_dir="/etc/discourse"
6 app_dir="/opt/discourse"
7 4
8 hg clone "$scm_url" "$tmp_dir" 5 app_dir = '/opt/discourse'
9 ln -s "$config_dir/database.yml" "$tmp_dir/config/database.yml" 6 secret = '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
10 ln -s "$config_dir/redis.yml" "$tmp_dir/config/redis.yml"
11 pushd "$tmp_dir"
12 bundle install
13 rake assets:precompile RAILS_ENV="production"
14 popd
15 7
16 # TODO: Stop Thin 8 # HOME environment variable isn't reliable when called via sudo
9 home_dir = os.path.expanduser('~' + pwd.getpwuid(os.getuid()).pw_name)
17 10
18 [[ -d $app_dir ]] && rm -rf "$app_dir" 11 env = dict(os.environ)
19 mv "$tmp_dir" "$app_dir" 12 env['GEM_HOME'] = os.path.join(home_dir, '.gems')
20 13
21 pushd "$app_dir" 14 def preprocessFiles():
22 rake db:migrate RAILS_ENV="production" 15 gemfile_path = os.path.join(app_dir, 'Gemfile')
23 popd 16 handle = open(gemfile_path, 'rb')
17 if "gem 'fcgi'" not in map(str.strip, handle.readlines()):
18 handle.close()
19 handle = open(gemfile_path, 'ab')
20 print >>handle, "gem 'fcgi'"
21 print >>sys.stderr, 'Added fcgi gem to Gemfile'
22 handle.close()
24 23
25 # TODO: Start Thin 24 secret_path = os.path.join(app_dir, 'config', 'initializers', 'secret_token.rb ')
25 handle = open(secret_path, 'rb')
26 if handle.read().find('SET_SECRET_HERE') >= 0:
27 handle.close()
28 handle = open(secret_path, 'wb')
29 print >>handle, 'Discourse::Application.config.secret_token = "%s"' % secret
30 print >>sys.stderr, 'Defined our secret in config/initializers/secret_token. rb'
31 handle.close()
32
33 def callRailsCommand(command):
34 subprocess.call(command, env=env, cwd=app_dir)
35
36 def runInitCommands():
37 rake_path = os.path.join(env['GEM_HOME'], 'bin', 'rake')
38 spawn_path = '/etc/init.d/spawn-fcgi'
39
40 callRailsCommand(['bundle', 'install'])
41 callRailsCommand([rake_path, 'assets:precompile', 'RAILS_ENV=production'])
42
43 if os.path.exists(spawn_path):
44 subprocess.call(['sudo', spawn_path, 'stop'])
45
46 callRailsCommand([rake_path, 'db:migrate', 'RAILS_ENV=production'])
47
48 if os.path.exists(spawn_path):
49 subprocess.call(['sudo', spawn_path, 'start'])
50
51 if __name__ == '__main__':
52 preprocessFiles()
53 runInitCommands()
OLDNEW

Powered by Google App Engine
This is Rietveld