Merge pull request #87 from Supermathie/v1run
[discourse_docker.git] / templates / web.template.yml
index 6b0184ecd3827f17bc6fe9099c56413529b02e34..eeae3bc37bfe159182c44128ba87fb52922d05bf 100644 (file)
@@ -21,6 +21,7 @@ params:
   upload_size: 3m
 
 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/runit/1.d/copy-env
      chmod: "+x"
@@ -30,7 +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
+        /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
 
   - file:
      path: /etc/service/unicorn/run
@@ -42,7 +43,7 @@ run:
         # postgres
         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
@@ -65,17 +66,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:
@@ -116,9 +113,9 @@ 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
+        - 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
@@ -156,3 +153,19 @@ 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
+        }