Skip to content

Commit 34daa34

Browse files
committed
Merge pull request discourse#1042 from Supermathie/sysadmin-docs
Sysadmin docs
2 parents 6989851 + d80b33c commit 34daa34

7 files changed

Lines changed: 192 additions & 20 deletions

File tree

config/clock.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
# These are jobs you should run on a regular basis to make your
66
# forum work properly.
77

8+
def setup_log
9+
Clockwork.configure do |config|
10+
config[:logger].close
11+
config[:logger] = Logger.new(ENV["CLOCK_LOG"])
12+
end if ENV["CLOCK_LOG"]
13+
end
14+
15+
trap('HUP') { setup_log }
16+
setup_log
17+
818
module Clockwork
919
handler do |job|
1020
Jobs.enqueue(job, all_sites: true)

config/discourse.pill.sample

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a
2020
# getting this to work was a nightmare
2121
# bundle exec spawns a process totally messing with the demonize option
2222
# so we suck the environment out and set it up first
23-
app.environment = `env -i BUNDLE_GEMFILE=#{rails_root}/Gemfile /usr/local/rvm/bin/bootup_bundle exec env`.lines.inject({}) do |env_hash,l|
24-
kv = l.chomp.split('=',2)
25-
env_hash[kv[0]] = kv[1]
26-
env_hash
27-
end if File.exist?("/usr/local/rvm/bin/rvm")
23+
bootup_bundle = [ "#{ENV['HOME']}/.rvm/bin/rvm/bootup_bundle",
24+
"/usr/local/rvm/bin/rvm/bootup_bundle",
25+
`which bootup_bundle`.strip,
26+
].each do |location|
27+
if File.exist? location
28+
break location
29+
end
30+
end
31+
# XXX if none match, bootup_bundle is set to the array
32+
33+
if bootup_bundle
34+
app.environment = `env -i BUNDLE_GEMFILE=#{rails_root}/Gemfile #{bootup_bundle} exec env`.lines.inject({}) do |env_hash,l|
35+
kv = l.chomp.split('=',2)
36+
env_hash[kv[0]] = kv[1]
37+
env_hash
38+
end
39+
end
2840

2941
app.environment ||= {}
3042
app.environment['RAILS_ENV'] = rails_env
@@ -37,7 +49,7 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a
3749
File.directory? sockdir or Dir.mkdir sockdir
3850
num_webs.times do |i|
3951
app.process("thin-#{i}") do |process|
40-
process.start_command = "bundle exec thin start -e production -t 0 --socket #{sockdir}/thin.#{i}.sock -P #{rails_root}/tmp/pids/thin#{i}.pid -d"
52+
process.start_command = "bundle exec thin start -e production -t 0 --socket #{sockdir}/thin.#{i}.sock --pid #{rails_root}/tmp/pids/thin#{i}.pid --log #{rails_root}/log/thin-#{i}.log --daemonize"
4153

4254
# Alternatively, you can start with a port number instead of a socket. If you do that, then you MUST update
4355
# the upstream section in the nginx config to match.
@@ -58,7 +70,7 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a
5870

5971
#debug instance
6072
# app.process("thin-debug") do |process|
61-
# process.start_command = "bundle exec thin start -e development -t 0 -p 10040 -P #{rails_root}/tmp/pids/thin-debug.pid -d"
73+
# process.start_command = "bundle exec thin start -e development -t 0 -p 10040 -P #{rails_root}/tmp/pids/thin-debug.pid -l #{rails_root}/log/thin-debug.log" -d"
6274
# process.pid_file = "#{rails_root}/tmp/pids/thin-debug.pid"
6375
# process.start_grace_time = 30.seconds
6476
# process.stop_grace_time = 10.seconds
@@ -73,7 +85,7 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a
7385
app.process("sidekiq-worker") do |process|
7486
pidfile = "#{rails_root}/tmp/pids/sidekiq-worker.pid"
7587

76-
process.start_command = "/usr/bin/env PIDFILE=#{pidfile} RAILS_ENV=#{rails_env} bundle exec sidekiq"
88+
process.start_command = "/usr/bin/env PIDFILE=#{pidfile} RAILS_ENV=#{rails_env} bundle exec sidekiq -L #{rails_root}/log/sidekiq.log"
7789
process.pid_file = pidfile
7890
process.start_grace_time = 30.seconds
7991
process.stop_grace_time = 10.seconds
@@ -83,11 +95,14 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a
8395
process.daemonize = true
8496
end
8597

86-
if `hostname`.strip == "host to run on"
98+
# Perhaps you want to run `hostname -f` here? It depends on your environment
99+
# In any case, ensure the output is what you expect it to be on the system
100+
# running clockwork!
101+
if `hostname -s`.strip == "host to run on"
87102
app.process("clockwork") do |process|
88103
pidfile = "#{rails_root}/tmp/pids/clockwork.pid"
89104

90-
process.start_command = "/usr/bin/env RAILS_ENV=#{rails_env} bundle exec clockwork config/clock.rb"
105+
process.start_command = "/usr/bin/env CLOCK_LOG=#{rails_root}/log/clockwork.log RAILS_ENV=#{rails_env} bundle exec clockwork config/clock.rb"
91106
process.pid_file = pidfile
92107
process.start_grace_time = 30.seconds
93108
process.stop_grace_time = 10.seconds

config/locales/server.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ en:
448448
ninja_edit_window: "Number of seconds after posting where edits do not create a new version"
449449
max_image_width: "Maximum allowed width of images in a post"
450450
category_featured_topics: "Number of topics displayed per category in the /categories page"
451-
add_rel_nofollow_to_user_content: "Add rel nofollow to all submitted user content, except for internal links (including parent domains) changing this requires you update all your baked markdown (<code>rake posts:rebake</code>)"
451+
add_rel_nofollow_to_user_content: "Add rel nofollow to all submitted user content, except for internal links (including parent domains) changing this requires you update all your baked markdown with: \"rake posts:rebake\""
452452
exclude_rel_nofollow_domains: "A comma delimited list of domains where nofollow is not added (tld.com will automatically allow sub.tld.com as well)"
453453

454454
post_excerpt_maxlength: "Maximum length in chars of a post's excerpt"

config/logrotate.conf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# rotate log files daily, keep 32 days
2+
daily
3+
rotate 32
4+
5+
# create new (empty) log files after rotating old ones
6+
create
7+
8+
compress
9+
missingok
10+
create 0644
11+
12+
13+
/home/discourse/discourse/log/clockwork.log
14+
{
15+
postrotate
16+
pkill -HUP -f clockwork
17+
endscript
18+
}
19+
/home/discourse/discourse/log/sidekiq.log
20+
{
21+
# Should we just kill sidekiq?
22+
# https://github.com/mperham/sidekiq/issues/1008
23+
postrotate
24+
pkill -USR2 -f sidekiq
25+
endscript
26+
}
27+
/home/discourse/discourse/log/production.log
28+
{
29+
# ????
30+
}
31+
/home/discourse/discourse/log/production_errors.log
32+
{
33+
# production_errors is opened on demand, no need to reopen
34+
}
35+
/home/discourse/discourse/log/thin*.log
36+
{
37+
postrotate
38+
pkill -USR1 -f 'thin server'
39+
endscript
40+
}

config/nginx.sample.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ server {
2121
location / {
2222
root /home/discourse/discourse/public;
2323

24+
location ~ \.(jpe?g|png|gif)$ {
25+
valid_referers none blocked mysite.com *.mysite.com;
26+
if ($invalid_referer) {
27+
return 403;
28+
}
29+
}
30+
2431
location ~ ^/t\/[0-9]+\/[0-9]+\/avatar {
2532
expires 1d;
2633
add_header Cache-Control public;

docs/INSTALL-ubuntu.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,42 +204,54 @@ Configure Discourse:
204204
cp discourse.pill.sample discourse.pill
205205
cp environments/production.rb.sample environments/production.rb
206206

207-
Edit discourse/config/database.yml
207+
Edit ~/discourse/config/database.yml
208208

209209
- change production db name if appropriate
210210
- change username/password if appropriate
211-
- set db_id if using multisite
211+
- set `db_id` if using multisite
212212
- change `host_names` to the name you'll use to access the discourse site
213213

214-
Edit discourse/config/redis.yml
214+
Edit ~/discourse/config/redis.yml
215215

216216
- no changes if this is the only application using redis, but have a look
217217

218-
Edit discourse/config/discourse.pill
218+
Edit ~/discourse/config/discourse.pill
219219

220220
- change application name from 'discourse' if necessary
221221
- Ensure appropriate Bluepill.application line is uncommented
222222
- search for "host to run on" and change to current hostname
223223
- note: clockwork should run on only one host
224224

225-
Edit discourse/config/initializers/secret_token.rb
225+
Edit ~/discourse/config/initializers/secret_token.rb
226226

227227
- uncomment secret_token line
228-
- replace SET_SECRET_HERE with secret output from 'rake secret' command in discourse directory
228+
- replace SET_SECRET_HERE with secret output from 'RAILS_ENV=production rake secret' command in discourse directory
229229
- delete the lines below as per instructions in the file
230230

231-
Edit discourse/config/environments/production.rb
231+
Edit ~/discourse/config/environments/production.rb
232232
- check settings, modify smtp settings if necessary
233233
- See http://meta.discourse.org/t/all-of-my-internal-users-show-as-coming-from-127-0-0-1/6607 if this will serve "internal" users
234234

235235
Initialize the database:
236236

237237
# Run these commands as the discourse user
238238
# The database name here should match the production one in database.yml
239+
cd ~/discourse
239240
createdb discourse_prod
240241
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production rake db:migrate
241242
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production rake assets:precompile
242243

244+
Not english? Set the default language as appropriate:
245+
246+
# Run these commands as the discourse user
247+
cd ~/discourse
248+
RAILS_ENV=production bundle exec rails c
249+
SiteSetting.default_locale = 'fr'
250+
251+
# Not sure if your locale is supported? Check at the rails console:
252+
LocaleSiteSetting.all_values
253+
=> ["cs", "da", "de", "en", "es", "fr", "id", "it", "nb_NO", "nl", "pseudo", "pt", "ru", "sv", "zh_CN", "zh_TW"]
254+
243255
## nginx setup
244256

245257
# Run these commands as your normal login (e.g. "michael")
@@ -248,7 +260,12 @@ Initialize the database:
248260
Edit /etc/nginx/nginx.conf:
249261

250262
- add: `server_names_hash_bucket_size 64;` to the `http` section
251-
- uncomment: `gzip on;`
263+
264+
If discourse will be the only site served by nginx, disable the nginx default
265+
site:
266+
267+
- `sudo mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disabled`
268+
- Otherwise, only `server_name`s configured below in `discourse.conf` will be passed to Discourse.
252269

253270
Edit /etc/nginx/conf.d/discourse.conf
254271

@@ -281,12 +298,18 @@ Add the Bluepill startup to crontab.
281298
# Run these commands as the discourse user
282299
crontab -e
283300

284-
Add the following line:
301+
Add the following lines:
285302

286303
@reboot RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ROOT=~/discourse RAILS_ENV=production NUM_WEBS=4 /home/discourse/.rvm/bin/bootup_bluepill --no-privileged -c ~/.bluepill load ~/discourse/config/discourse.pill
287304

305+
288306
Note: in case of RVM system-wide installation RVM will be located in `/usr/local/rvm` directory instead of `/home/discourse/.rvm`, so update the line above respectively.
289307

308+
## Log rotation setup
309+
310+
# Disabled for now - log rotation isn't *quite* complete
311+
#0 0 * * * /usr/sbin/logrotate ~/discourse/config/logrotate.conf
312+
290313
Congratulations! You've got Discourse installed and running!
291314

292315
Now make yourself an administrator account. Browse to your discourse instance

docs/TROUBLESHOOTING-prod.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
## Troubleshooting issues with Discourse environments
2+
3+
Are you having trouble setting up Discourse? Here are some basic things to
4+
check before reaching out to the community for help:
5+
6+
7+
1. Are you running Ruby 1.9.3 or later?
8+
9+
Discourse is designed for Ruby 1.9.3 or later. You can check your version by
10+
typing `ruby -v` and checking the response.
11+
12+
13+
2. Are you on Postgres 9.1 or later with HSTORE enabled?
14+
15+
You can check your postgres version by typing `psql --version`. To see if hstore is
16+
installed, open a session to postgres and type `\dx` and see if hstore is listed.
17+
18+
19+
3. Have you run `bundle install`?
20+
21+
We frequently update our dependencies to newer versions. It is a good idea to run
22+
`bundle install` every time you check out Discourse, especially if it's been a while.
23+
24+
4. Did you run `bundle update`?
25+
26+
Don't. Running `bundle update` will download gem versions that we haven't tested with.
27+
The Gemfile.lock has the gem versions that Discourse currently uses, so `bundle install`
28+
will work. If you ran update, then you should uninstall the gems, run
29+
`git checkout -- Gemfile.lock` and then run `bundle install`.
30+
31+
5. Have you migrated your database?
32+
33+
Our schema changes fairly frequently. After checking out the source code, you should
34+
run `rake db:migrate`
35+
36+
37+
6. Have you added the seed data?
38+
39+
We depend on some basic seed data being present in the database. You should run
40+
`rake db:seed_fu` to keep your database in sync.
41+
42+
43+
7. Do the tests pass?
44+
45+
If you are having other problems, it's useful to know if the test suite passes. You
46+
can run it by first using `rake db:test:prepare` and then `rake spec`. If you
47+
experience any failures, that's a bad sign! Our master branch should *always* pass
48+
every test.
49+
50+
8. Have you updated host_names in your database.yml?
51+
52+
If links in emails have localhost in them, then you are still using the default host_names
53+
value in database.yml. Update it to use your site's host name(s).
54+
55+
9. Are you having problems bundling:
56+
57+
```
58+
ArgumentError: invalid byte sequence in US-ASCII
59+
An error occurred while installing active_model_serializers (0.7.0), and Bundler cannot continue.
60+
Make sure that `gem install active_model_serializers -v '0.7.0'` succeeds before bundling.
61+
```
62+
63+
Try this in console:
64+
65+
```
66+
$ export LANG="en_US.UTF-8"
67+
$ export LC_ALL="en_US.UTF-8"
68+
```
69+
70+
And/or this in top of `Gemfile`:
71+
72+
```
73+
if RUBY_VERSION =~ /1.9/
74+
Encoding.default_external = Encoding::UTF_8
75+
Encoding.default_internal = Encoding::UTF_8
76+
end
77+
```

0 commit comments

Comments
 (0)