2 # You can have redis on a different box
3 RAILS_ENV: 'production'
6 # this gives us very good cache coverage, 96 -> 99
7 # in practice it is 1-2% perf improvement
8 RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072
9 # stop heap doubling in size so aggressively, this conserves memory
10 RUBY_GC_HEAP_GROWTH_MAX_SLOTS: 40000
11 RUBY_GC_HEAP_INIT_SLOTS: 400000
12 RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR: 1.5
14 DISCOURSE_DB_SOCKET: /var/run/postgresql
22 home: /var/www/discourse
26 - exec: thpoff echo "thpoff is installed!"
27 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
28 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end'
29 - exec: /usr/local/bin/ruby -e 'if (ENV["DISCOURSE_CDN_URL"] || "")[0..1] == "//"; puts "Aborting! CDN must have a protocol specified. Once fixed you should rebake your posts now to correct all posts."; exit 1; end'
30 - exec: chown -R discourse /home/discourse
31 # TODO: move to base image (anacron can not be fired up using rc.d)
32 - exec: rm -f /etc/cron.d/anacron
34 path: /etc/cron.d/anacron
37 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
39 30 7 * * * root /usr/sbin/anacron -s >/dev/null
41 path: /etc/runit/1.d/copy-env
46 conf=/var/www/discourse/config/discourse.conf
48 # find DISCOURSE_ env vars, strip the leader, lowercase the key
49 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = '\''#{v}'\''" if k =~ /^DISCOURSE_(.*)/}' > $conf
52 path: /etc/service/unicorn/run
60 chown -R discourse:www-data /shared/log/rails
61 LD_PRELOAD=$RUBY_ALLOCATOR HOME=/home/discourse USER=discourse exec thpoff chpst -u discourse:www-data -U discourse:www-data bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb
64 path: /etc/service/nginx/run
72 path: /etc/runit/3.d/01-nginx
79 path: /etc/runit/3.d/02-unicorn
91 - git remote set-branches --add origin master
93 - git fetch origin $version
94 - git checkout $version
96 - mkdir -p tmp/sockets
98 - mkdir -p /shared/log/rails
99 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr,sidekiq}.log"
100 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr,sidekiq}.log $home/log"
101 - bash -c "mkdir -p /shared/{uploads,backups}"
102 - bash -c "ln -s /shared/{uploads,backups} $home/public"
103 - bash -c "mkdir -p /shared/tmp/{backups,restores}"
104 - bash -c "ln -s /shared/tmp/{backups,restores} $home/tmp"
105 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups /shared/tmp
109 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
110 - "rm /etc/nginx/sites-enabled/default"
111 - "mkdir -p /var/nginx/cache"
114 filename: /etc/nginx/nginx.conf
115 from: pid /run/nginx.pid;
119 filename: "/etc/nginx/conf.d/discourse.conf"
120 from: /upstream[^\}]+\}/m
121 to: "upstream discourse {
122 server 127.0.0.1:3000;
126 filename: "/etc/nginx/conf.d/discourse.conf"
127 from: /server_name.+$/
131 filename: "/etc/nginx/conf.d/discourse.conf"
132 from: /client_max_body_size.+$/
133 to: client_max_body_size $upload_size ;
136 cmd: echo "done configuring web"
143 # ensure we are on latest bundler
145 - find $home ! -user discourse -exec chown discourse {} \+
151 - su discourse -c 'bundle install --deployment --retry 3 --jobs 4 --verbose --without test development'
156 - su discourse -c 'bundle exec rake db:migrate'
159 hook: assets_precompile
161 - su discourse -c 'bundle exec rake assets:precompile'
163 path: /usr/local/bin/discourse
167 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
170 path: /usr/local/bin/rails
174 # If they requested a console, load pry instead
175 if [ "$*" == "c" -o "$*" == "console" ]
177 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
179 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
183 path: /usr/local/bin/rake
187 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
190 path: /usr/local/bin/rbtrace
194 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec rbtrace "$@")
197 path: /usr/local/bin/stackprof
201 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec stackprof "$@")
204 path: /etc/update-motd.d/10-web
209 echo Use: rails, rake or discourse to execute commands in production
213 path: /etc/logrotate.d/rails
215 /shared/log/rails/*.log
229 path: /etc/logrotate.d/nginx
231 /var/log/nginx/*.log {
237 create 0644 www-data www-data
244 # move state out of the container this fancy is done to support rapid rebuilds of containers,
245 # we store anacron and logrotate state outside the container to ensure its maintained across builds
246 # later move this snipped into an intialization script
247 # we also ensure all the symlinks we need to /shared are in place in the correct structure
248 # this allows us to bootstrap on one machine and then run on another
250 path: /etc/runit/1.d/00-ensure-links
254 if [[ ! -L /var/lib/logrotate ]]; then
255 rm -fr /var/lib/logrotate
256 mkdir -p /shared/state/logrotate
257 ln -s /shared/state/logrotate /var/lib/logrotate
259 if [[ ! -L /var/spool/anacron ]]; then
260 rm -fr /var/spool/anacron
261 mkdir -p /shared/state/anacron-spool
262 ln -s /shared/state/anacron-spool /var/spool/anacron
264 if [[ ! -d /shared/log/rails ]]; then
265 mkdir -p /shared/log/rails
266 chown -R discourse:www-data /shared/log/rails
268 if [[ ! -d /shared/uploads ]]; then
269 mkdir -p /shared/uploads
270 chown -R discourse:www-data /shared/uploads
272 if [[ ! -d /shared/backups ]]; then
273 mkdir -p /shared/backups
274 chown -R discourse:www-data /shared/backups
277 rm -rf /shared/tmp/{backups,restores}
278 mkdir -p /shared/tmp/{backups,restores}
279 chown -R discourse:www-data /shared/tmp/{backups,restores}
281 # change login directory to Discourse home
283 path: /root/.bash_profile