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

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

Issue 9351210: Define Discourse admins and site settings in Puppet, separate private data from other settings (Closed)
Patch Set: Created Feb. 19, 2013, 3:08 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 = '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08' 6 secret = os.environ.get('DISCOURSE_SECRET', None)
7 7
8 # HOME environment variable isn't reliable when called via sudo 8 # HOME environment variable isn't reliable when called via sudo
9 home_dir = os.path.expanduser('~' + pwd.getpwuid(os.getuid()).pw_name) 9 home_dir = os.path.expanduser('~' + pwd.getpwuid(os.getuid()).pw_name)
10 10
11 env = dict(os.environ) 11 env = dict(os.environ)
12 env['GEM_HOME'] = os.path.join(home_dir, '.gems') 12 env['GEM_HOME'] = os.path.join(home_dir, '.gems')
13 13
14 def preprocessFiles(): 14 def preprocessFiles():
15 gemfile_path = os.path.join(app_dir, 'Gemfile') 15 gemfile_path = os.path.join(app_dir, 'Gemfile')
16 handle = open(gemfile_path, 'rb') 16 handle = open(gemfile_path, 'rb')
17 if "gem 'fcgi'" not in map(str.strip, handle.readlines()): 17 if "gem 'fcgi'" not in map(str.strip, handle.readlines()):
18 handle.close() 18 handle.close()
19 handle = open(gemfile_path, 'ab') 19 handle = open(gemfile_path, 'ab')
20 print >>handle, "gem 'fcgi'" 20 print >>handle, "gem 'fcgi'"
21 print >>sys.stderr, 'Added fcgi gem to Gemfile' 21 print >>sys.stderr, 'Added fcgi gem to Gemfile'
22 handle.close() 22 handle.close()
23 23
24 secret_path = os.path.join(app_dir, 'config', 'initializers', 'secret_token.rb ') 24 secret_path = os.path.join(app_dir, 'config', 'initializers', 'secret_token.rb ')
25 handle = open(secret_path, 'rb') 25 handle = open(secret_path, 'rb')
26 if handle.read().find('SET_SECRET_HERE') >= 0: 26 if handle.read().find('SET_SECRET_HERE') >= 0:
27 handle.close() 27 if secret != None:
28 handle = open(secret_path, 'wb') 28 handle.close()
29 print >>handle, 'Discourse::Application.config.secret_token = "%s"' % secret 29 handle = open(secret_path, 'wb')
30 print >>sys.stderr, 'Defined our secret in config/initializers/secret_token. rb' 30 print >>handle, 'Discourse::Application.config.secret_token = "%s"' % secr et
31 print >>sys.stderr, 'Defined our secret in config/initializers/secret_toke n.rb'
32 else:
33 print >>sys.stderr, 'Skipping defining secret in config/initializers/secre t_token.rb, please set DISCOURSE_SECRET environment variable'
31 handle.close() 34 handle.close()
32 35
33 def callRailsCommand(command): 36 def callRailsCommand(command):
34 subprocess.call(command, env=env, cwd=app_dir) 37 subprocess.call(command, env=env, cwd=app_dir)
35 38
36 def runInitCommands(): 39 def runInitCommands():
37 rake_path = os.path.join(env['GEM_HOME'], 'bin', 'rake') 40 rake_path = os.path.join(env['GEM_HOME'], 'bin', 'rake')
38 spawn_path = '/etc/init.d/spawn-fcgi' 41 spawn_path = '/etc/init.d/spawn-fcgi'
39 42
40 callRailsCommand(['bundle', 'install']) 43 callRailsCommand(['bundle', 'install'])
41 callRailsCommand([rake_path, 'assets:precompile', 'RAILS_ENV=production']) 44 callRailsCommand([rake_path, 'assets:precompile', 'RAILS_ENV=production'])
42 45
43 if os.path.exists(spawn_path): 46 if os.path.exists(spawn_path):
44 subprocess.call(['sudo', spawn_path, 'stop']) 47 subprocess.call(['sudo', spawn_path, 'stop'])
45 48
46 callRailsCommand([rake_path, 'db:migrate', 'RAILS_ENV=production']) 49 callRailsCommand([rake_path, 'db:migrate', 'RAILS_ENV=production'])
47 50
48 if os.path.exists(spawn_path): 51 if os.path.exists(spawn_path):
49 subprocess.call(['sudo', spawn_path, 'start']) 52 subprocess.call(['sudo', spawn_path, 'start'])
50 53
51 if __name__ == '__main__': 54 if __name__ == '__main__':
52 preprocessFiles() 55 preprocessFiles()
53 runInitCommands() 56 runInitCommands()
OLDNEW

Powered by Google App Engine
This is Rietveld