X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=templates%2Fweb.template.yml;h=c094b7acf98ec849d7ea9a5b95048e9955e61aca;hb=44c59d379e3a2424514eae01fa691d3cb6311de5;hp=5fad8d1c9a4af96f0ebd94f4c186511592eb8d64;hpb=d4eb147c9058235c9a44bc3e6ff82dd581eef620;p=discourse_docker.git diff --git a/templates/web.template.yml b/templates/web.template.yml index 5fad8d1..c094b7a 100644 --- a/templates/web.template.yml +++ b/templates/web.template.yml @@ -18,11 +18,12 @@ params: version: tests-passed home: /var/www/discourse - upload_size: 3m + upload_size: 10m run: + - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end' - file: - path: /etc/service/copy_env/run + path: /etc/runit/1.d/copy-env chmod: "+x" contents: | #!/bin/bash @@ -30,10 +31,7 @@ run: conf=/var/www/discourse/config/discourse.conf # find DISCOURSE_ env vars, strip the leader, lowercase the key - env | /usr/bin/awk -F= -vOFS== '$1 ~ /^DISCOURSE_/ {print substr(tolower($1),11),$2}' > $conf - - # tell runsv to not restart this when it exits - sv once copy_env + /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf - file: path: /etc/service/unicorn/run @@ -43,10 +41,9 @@ run: exec 2>&1 # redis # postgres - sv check copy_env || exit 1 cd $home chown -R discourse:www-data /shared/log/rails - exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb + LD_PRELOAD=/usr/lib/libjemalloc.so.1 HOME=/home/discourse USER=discourse exec chpst -u discourse:www-data -U discourse:www-data bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb - file: path: /etc/service/nginx/run @@ -57,6 +54,20 @@ run: mkdir -p /var/log/nginx exec /usr/sbin/nginx + - file: + path: /etc/runit/3.d/01-nginx + chmod: "+x" + contents: | + #!/bin/bash + sv stop nginx + + - file: + path: /etc/runit/3.d/02-unicorn + chmod: "+x" + contents: | + #!/bin/bash + sv stop unicorn + - exec: cd: $home hook: code @@ -69,17 +80,13 @@ run: - git checkout $version - mkdir -p tmp/pids - mkdir -p tmp/sockets - - mkdir -p /shared/log/rails - - mkdir -p /shared/uploads - - mkdir -p /shared/backups - touch tmp/.gitkeep - - rm -r log - - ln -s /shared/log/rails $home/log - - ln -s /shared/uploads $home/public/uploads - - ln -s /shared/backups $home/public/backups - - chown -R discourse:www-data /shared/log/rails - - chown -R discourse:www-data /shared/uploads - - chown -R discourse:www-data /shared/backups + - mkdir -p /shared/log/rails + - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log" + - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log" + - bash -c "mkdir -p /shared/{uploads,backups}" + - bash -c "ln -s /shared/{uploads,backups} $home/public" + - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups - exec: cmd: @@ -120,16 +127,21 @@ run: # ensure we are on latest bundler - gem update bundler - chown -R discourse $home - - sudo -E -u discourse bundle install --deployment --verbose --without test --without development - - sudo -E -u discourse bundle exec rake db:migrate - - sudo -E -u discourse bundle exec rake assets:precompile + + - exec: + cd: $home + hook: bundle_exec + cmd: + - su discourse -c 'bundle install --deployment --verbose --without test --without development' + - su discourse -c 'bundle exec rake db:migrate' + - su discourse -c 'bundle exec rake assets:precompile' - file: path: /usr/local/bin/discourse chmod: +x contents: | #!/bin/bash - (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/discourse "$@") + (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@") - file: path: /usr/local/bin/rails @@ -139,9 +151,9 @@ run: # If they requested a console, load pry instead if [ "$@" == "c" -o "$@" == "console" ] then - (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec pry -r ./config/environment) + (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment) else - (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/rails "$@") + (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@") fi - file: @@ -149,7 +161,7 @@ run: chmod: +x contents: | #!/bin/bash - (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec bin/rake "$@") + (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@") - file: path: /etc/update-motd.d/10-web @@ -160,3 +172,62 @@ run: echo Use: rails, rake or discourse to execute commands in production echo + - file: + path: /etc/logrotate.d/rails + contents: | + /shared/log/rails/*.log + { + rotate 14 + dateext + daily + missingok + notifempty + delaycompress + compress + postrotate + sv 1 unicorn + endscript + } + + - replace: + filename: "/etc/logrotate.d/nginx" + from: "weekly" + to: "daily" + + - replace: + filename: "/etc/logrotate.d/nginx" + from: "52" + to: "14" + + # move state out of the container this fancy is done to support rapid rebuilds of containers, + # we store anacron and logrotate state outside the container to ensure its maintained across builds + # later move this snipped into an intialization script + # we also ensure all the symlinks we need to /shared are in place in the correct structure + # this allows us to bootstrap on one machine and then run on another + - file: + path: /etc/runit/1.d/00-ensure-links + chmod: +x + contents: | + #!/bin/bash + if [[ ! -L /var/lib/logrotate ]]; then + rm -fr /var/lib/logrotate + mkdir -p /shared/state/logrotate + ln -s /shared/state/logrotate /var/lib/logrotate + fi + if [[ ! -L /var/spool/anacron ]]; then + rm -fr /var/spool/anacron + mkdir -p /shared/state/anacron-spool + ln -s /shared/state/anacron-spool /var/spool/anacron + fi + if [[ ! -d /shared/log/rails ]]; then + mkdir -p /shared/log/rails + chown -R discourse:www-data /shared/log/rails + fi + if [[ ! -d /shared/uploads ]]; then + mkdir -p /shared/uploads + chown -R discourse:www-data /shared/uploads + fi + if [[ ! -d /shared/backups ]]; then + mkdir -p /shared/backups + chown -R discourse:www-data /shared/backups + fi