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

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

Issue 6221863587938304: Issue 212 - Update Discourse (Closed)
Patch Set: Created March 27, 2014, 3:37 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import sys, os, pwd, subprocess 3 import sys, os, pwd, subprocess
4 4
5 app_dir = '/opt/discourse' 5 app_dir = '/opt/discourse'
6 secret = os.environ.get('DISCOURSE_SECRET', None)
7 airbrake_key = os.environ.get('AIRBRAKE_KEY', None) 6 airbrake_key = os.environ.get('AIRBRAKE_KEY', None)
8 7
9 # HOME environment variable isn't reliable when called via sudo 8 # HOME environment variable isn't reliable when called via sudo
10 home_dir = os.path.expanduser('~' + pwd.getpwuid(os.getuid()).pw_name) 9 home_dir = os.path.expanduser('~' + pwd.getpwuid(os.getuid()).pw_name)
11 10
12 env = dict(os.environ) 11 env = dict(os.environ)
13 env['GEM_HOME'] = os.path.join(home_dir, '.gems')
14 env['RAILS_ENV'] = 'production' 12 env['RAILS_ENV'] = 'production'
15 13
16 # See http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126 14 # See http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126
17 env['RUBY_GC_MALLOC_LIMIT'] = '90000000' 15 env['RUBY_GC_MALLOC_LIMIT'] = '90000000'
18 16
19 def preprocessFiles():
20 secret_path = os.path.join(app_dir, 'config', 'initializers', 'secret_token.rb ')
21 handle = open(secret_path, 'rb')
22 if handle.read().find('SET_SECRET_HERE') >= 0:
23 if secret != None:
24 handle.close()
25 handle = open(secret_path, 'wb')
26 print >>handle, 'Discourse::Application.config.secret_token = "%s"' % secr et
27 print >>sys.stderr, 'Defined our secret in config/initializers/secret_toke n.rb'
28 else:
29 print >>sys.stderr, 'Skipping defining secret in config/initializers/secre t_token.rb, please set DISCOURSE_SECRET environment variable'
30 handle.close()
31
32 def callRailsCommand(command): 17 def callRailsCommand(command):
33 subprocess.call(command, env=env, cwd=app_dir) 18 subprocess.check_call(command, env=env, cwd=app_dir)
34 19
35 def initAirBrake(): 20 def initAirBrake():
36 if airbrake_key == None: 21 if airbrake_key == None:
37 return 22 return
38 23
39 path = os.path.join(app_dir, 'config', 'initializers', 'airbrake.rb') 24 path = os.path.join(app_dir, 'config', 'initializers', 'airbrake.rb')
40 if os.path.exists(path): 25 if os.path.exists(path):
41 handle = open(path, 'rb') 26 with open(path, 'rb') as handle:
42 data = handle.read() 27 data = handle.read()
43 handle.close()
44 28
45 if data.find(airbrake_key) >= 0: 29 if data.find(airbrake_key) >= 0:
46 return 30 return
47 else: 31 else:
48 os.remove(path) 32 os.remove(path)
49 callRailsCommand([os.path.join(app_dir, 'script', 'rails'), 'generate', 'airbr ake', '--api-key', airbrake_key]) 33 callRailsCommand([os.path.join(app_dir, 'script', 'rails'), 'generate', 'airbr ake', '--api-key', airbrake_key])
50 34
35 with open(path, 'rb+') as handle:
36 # Prepend file with require 'airbrake', won't happen by default
37 data = handle.read()
38 handle.seek(0)
39 print >>handle, "require 'airbrake'"
40 handle.write(data)
41
51 def runInitCommands(): 42 def runInitCommands():
52 rake_path = os.path.join(env['GEM_HOME'], 'bin', 'rake')
53 service_path = '/etc/init.d/discourse-thin' 43 service_path = '/etc/init.d/discourse-thin'
54 44
55 callRailsCommand(['bundle', 'install']) 45 callRailsCommand(['bundle', 'install', '--deployment', '--without', 'test', '- -without', 'development'])
56 initAirBrake() 46 initAirBrake()
57 callRailsCommand([rake_path, 'assets:precompile']) 47 callRailsCommand(['bundle', 'exec', 'rake', 'assets:precompile'])
58 48
59 if os.path.exists(service_path): 49 if os.path.exists(service_path):
60 subprocess.call(['sudo', service_path, 'stop']) 50 subprocess.check_call(['sudo', service_path, 'stop'])
61 51
62 callRailsCommand([rake_path, 'db:migrate']) 52 callRailsCommand(['bundle', 'exec', 'rake', 'db:migrate'])
63 53
64 if os.path.exists(service_path): 54 if os.path.exists(service_path):
65 subprocess.call(['sudo', service_path, 'start']) 55 subprocess.check_call(['sudo', service_path, 'start'])
66 56
67 if __name__ == '__main__': 57 if __name__ == '__main__':
68 preprocessFiles()
69 runInitCommands() 58 runInitCommands()
OLDNEW

Powered by Google App Engine
This is Rietveld