Editing Moebooru

From Bibliotheca Anonoma

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 62: Line 62:
{{ic|libpqxx}} is required for libpq-ruby to build.
{{ic|libpqxx}} is required for libpq-ruby to build.


Then, initialize and start the database.
Now log in and create the moebooru database and user: (make sure to create a very good password!)
 
{{bc|
# /usr/pgsql-9.6/bin/postgresql96-setup initdb
# systemctl start postgresql-9.6
}}
 
Now log in and create the moebooru database and user with createdb permissions: (make sure to give it a very good password!)


{{bc|$ sudo su    # becoming the postgres user doesn't really work with sudo for some reason
{{bc|$ sudo su    # becoming the postgres user doesn't really work with sudo for some reason
# su - postgres
# su - postgres
$ psql
$ psql
postgres # CREATE USER moebooru_user WITH PASSWORD 'your_password' CREATEDB;
postgres # create user moebooru_user with password 'your_password' createdb;}}
}}
Finally, edit {{ic|pg_hba.conf}} from {{ic|ident}} to {{ic|md5}} (except for the UNIX socket line) to allow users to log in using a password (required by moebooru's config), it should look like the following:
Finally, edit {{ic|pg_hba.conf}} from {{ic|ident}} to {{ic|md5}} (except for the UNIX socket line) to allow users to log in using a password (required by moebooru's config), it should look like the following:


Line 108: Line 100:
''For most small sites'', Ruby 2.3 and higher with the Unicorn server is sufficient.  
''For most small sites'', Ruby 2.3 and higher with the Unicorn server is sufficient.  


''A site with heavier traffic'' may find it helpful to use Rubinius with the Puma server [https://blog.engineyard.com/2014/ruby-app-server-arena-pt1to make better use of concurrent multithreading,] but this may require compilation, which can be fiendishly difficult.
''A site with heavier traffic'' may find it helpful to use Rubinius with the Puma server [https://blog.engineyard.com/2014/ruby-app-server-arena-pt1to make better use of concurrent multithreading,] but this may require compilation.
 
{{Warning|If you can't get Rubinius to work or to compile your gems, don't waste your time on it anymore. Just use standard Ruby 2.3.}}


=== Method 1: Set up Normal Ruby 2.3 or newer ===
=== Method 1: Set up Normal Ruby 2.3 or newer ===
Line 121: Line 111:
=== Method 2: Installing Rubinius Binaries with chruby ===
=== Method 2: Installing Rubinius Binaries with chruby ===


{{hc|Debian/Ubuntu|
https://github.com/postmodern/chruby
sudo apt-get install openssl libreadline6 libreadline6-dev \
curl zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 \
libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev libtool  \
pkg-config libgdbm-dev ncurses-dev libffi-dev
}}
 
{{hc|Red Hat/CentOS|
sudo yum install ruby
sudo yum install -y patch autoconf libtool sqlite-devel
}}


Rubinius is particularly tough to compile, and as of 2017-01-28 we have not been able to compile it with Debian Jessie. Instead, [https://rubinius.com/install/ Rubinius provides Ubuntu 14.04 binaries designed for use with Travis-Cl.]
Download the latest rubinius binaries and extract them to {{ic|/home/moe/}}.


First, download and install [https://github.com/postmodern/chruby chruby] as a user with sudo privileges.
https://rubinius.com/install/
 
{{bc|
wget -O chruby-0.3.9.tar.gz https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz
tar -xzvf chruby-0.3.9.tar.gz
cd chruby-0.3.9/
sudo make install
}}
 
Next, log in as the {{ic|moe}} user, download the latest rubinius binaries, and extract them to {{ic|/home/moe/}}:
 
{{bc|
sudo -i -u moe
wget -O rubinius-3.70.tar.bz2 https://rubinius-binaries-rubinius-com.s3.amazonaws.com/ubuntu/14.04/x86_64/rubinius-3.70.tar.bz2
tar -xjvf rubinius-3.70.tar.bz2
}}
 
Then, activate chruby with rubinius by adding it to the bashrc.
 
{{hc|/home/moe/.bashrc|<nowiki>
source /usr/local/share/chruby/chruby.sh
 
RUBIES+=(
  "$HOME/rubinius/3.70"
)
</nowiki>}}
 
Finally, log out and log back into the {{ic|moe}} user, and set rubinius 3.70 as the default ruby version.
 
{{bc|
chruby 3.70
}}


=== Method 3: Install Rubinius with RVM ===
=== Method 3: Install Rubinius with RVM ===
Line 180: Line 129:
{{bc|
{{bc|
sudo yum install ruby
sudo yum install ruby
sudo yum install -y patch autoconf patch automake libtool bison sqlite-devel bzip2 zlib-devel libyaml-devel readline-devel openssl-devel
sudo yum install -y patch autoconf patch automake libtool bison sqlite-devel
}}
}}


Line 352: Line 301:
https://zonio.net/rubinius_rpm_packages/
https://zonio.net/rubinius_rpm_packages/
-->
-->
{{Note|If you encounter any issues with gems that say "Ignoring because extensions are not built", run {{ic|gem pristine --all}}}}


== Mandatory Access Control ==
== Mandatory Access Control ==
Line 431: Line 378:


{{bc|bundle install --path vendor/bundle}}
{{bc|bundle install --path vendor/bundle}}
Generate your secret key, which is used for salts and such.
{{bc|bundle exec rake secret}}


Obtain <code>config/database.yml</code> and <code>config/local_config.rb</code> from the <code>.example</code> files, and configure them accordingly. Then set <code>chmod 700</code> so only the moebooru user can read the database password.
Obtain <code>config/database.yml</code> and <code>config/local_config.rb</code> from the <code>.example</code> files, and configure them accordingly. Then set <code>chmod 700</code> so only the moebooru user can read the database password.
Line 440: Line 391:
chmod 700 config/local_config.rb
chmod 700 config/local_config.rb
}}
}}
Generate your secret key, which is used for salts and such.
{{bc|bundle exec rake secret}}


Edit {{ic|config/database.yml}} using your favorite editor (such as nano), and replace {{ic|imouto}} with the password of your database user:
Edit {{ic|config/database.yml}} using your favorite editor (such as nano), and replace {{ic|imouto}} with the password of your database user:
Line 469: Line 416:
{{bc|chmod 600 /home/moe/booru/config/database.yml}}
{{bc|chmod 600 /home/moe/booru/config/database.yml}}


Initialize database with this command (there will be some errors reported with {{ic|ERROR:  must be owner of extension plpgsql}} which is normal, proceed)
Initialize database with this command (there will be some errors reported which is expected)


{{bc|bundle exec rake db:reset}}
{{bc|bundle exec rake db:reset}}
{{Note|If you have trouble creating databases because they set to SQL_ASCII by default, [https://gist.github.com/amolkhanorkar/8706915 follow this guide to require UTF-8 to be set by default.] }}


{{Note|Whenever you update moebooru using {{ic|git pull}}, make sure to migrate the database table schema with the command below.}}
{{Note|Whenever you update moebooru using {{ic|git pull}}, make sure to migrate the database table schema with the command below.}}
Line 485: Line 430:
{{bc|chmod 755 /home/moe/booru/public}}
{{bc|chmod 755 /home/moe/booru/public}}


Start the server: {{ic|bundle exec unicorn}} or {{ic|bundle exec puma}} if using Rubinius. Note that this will start the server in '''development mode''', which is somewhat slower. See the Production Mode section once you are ready to serve the site.
Start the server (<code>bundle exec unicorn</code> or <code>bundle exec puma</code> if using JRuby/Rubinius)


== Customize Header Image and Branding ==
== Customize Header Image and Branding ==
Line 595: Line 540:
=== Run the Server ===
=== Run the Server ===


Finally, to run the server at, for example, port 9292, run one of the following commands:
Finally, to run the server (default is port 9292), run one of the following commands:


Ruby:
Ruby:
Line 603: Line 548:
Rubinius:
Rubinius:


{{bc|<nowiki>RAILS_ENV=production bundle exec puma -e production -p 9292</nowiki>}}
{{bc|<nowiki>RAILS_ENV=production bundle exec puma -e production</nowiki>}}


* [http://stackoverflow.com/a/27318704 Source: StackOverflow - Rails 4: assets not loading in production]
* [http://stackoverflow.com/a/27318704 Source: StackOverflow - Rails 4: assets not loading in production]
Line 614: Line 559:


<pre>grep -c processor /proc/cpuinfo</pre>
<pre>grep -c processor /proc/cpuinfo</pre>
Create the following folders in your application directory:


Create a folder to store your UNIX sockets and PIDs in:
<pre>mkdir -p shared/pids shared/sockets shared/log</pre>
 
{{bc|
sudo mkdir /var/run/moebooru
sudo chown -R moe:moe /var/run/moebooru
}}
 
Create the following folders in your application directory to store logs:
 
<pre>mkdir -p shared/log</pre>
Place the following into {{ic|<app_dir>/shared/puma.rb}}:
Place the following into {{ic|<app_dir>/shared/puma.rb}}:


Line 633: Line 570:
threads 1, 6
threads 1, 6


app_dir = File.expand_path("../..", __FILE__)
app_dir = File.expand_path(&quot;../..&quot;, __FILE__)
shared_dir = "#{app_dir}/shared"
shared_dir = &quot;#{app_dir}/shared&quot;
socket_dir = "/var/run/moebooru"


# Default to production
# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
rails_env = ENV['RAILS_ENV'] || &quot;production&quot;
environment rails_env
environment rails_env


# Set up socket location
# Set up socket location
bind "unix://#{socket_dir}/puma.sock"
bind &quot;unix://#{shared_dir}/sockets/puma.sock&quot;


# Logging
# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true
stdout_redirect &quot;#{shared_dir}/log/puma.stdout.log&quot;, &quot;#{shared_dir}/log/puma.stderr.log&quot;, true


# Set master PID and state locations
# Set master PID and state locations
pidfile "#{socket_dir}/puma.pid"
pidfile &quot;#{shared_dir}/pids/puma.pid&quot;
state_path "#{socket_dir}/puma.state"
state_path &quot;#{shared_dir}/pids/puma.state&quot;
activate_control_app
activate_control_app


on_worker_boot do
on_worker_boot do
   require "active_record"
   require &quot;active_record&quot;
   ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
   ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
   ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
   ActiveRecord::Base.establish_connection(YAML.load_file(&quot;#{app_dir}/config/database.yml&quot;)[rails_env])
end
end
</nowiki>}}
</nowiki>}}
Line 663: Line 599:
{{hc|/etc/nginx/conf.d/booru.eikonos.org.conf|<nowiki>upstream app {
{{hc|/etc/nginx/conf.d/booru.eikonos.org.conf|<nowiki>upstream app {
     # Path to Puma SOCK file, as defined previously
     # Path to Puma SOCK file, as defined previously
     server unix:/var/run/moebooru/puma.sock fail_timeout=0;
     server unix:/home/moe/booru/shared/sockets/puma.sock fail_timeout=0;
}
}


Line 681: Line 617:
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Forwarded-Proto $scheme;
       # Fix the "It appears that your reverse proxy set up is broken" error.
       # Fix the &quot;It appears that your reverse proxy set up is broken&quot; error.
       proxy_pass http://app;
       proxy_pass http://app;
       proxy_read_timeout 90;
       proxy_read_timeout 90;
Line 695: Line 631:


{{bc|bundle exec puma -C shared/puma.rb}}
{{bc|bundle exec puma -C shared/puma.rb}}
== Separate subdomain for images and static content ==
It's often a better idea to have static content served from another subdomain entirely, where it will be cached for much longer than ever changing text. And sometimes the files could be located on an entirely different server.
Edit your {{ic|config/local_config.rb}} to activate the {{ic|assets.}} and {{ic|files.}} subdomains.
{{hc|config/local_config.rb|<nowiki>
# Servers for static files (assets and uploaded files)
CONFIG[:file_hosts] = { :files => "files.eikonos.org", :assets => "assets.eikonos.org" }
</nowiki>}}
Then, create these two nginx configs (customize the server_name to your subdomains, must start with {{ic|assets.}} and {{ic|files.}}):
{{hc|/etc/nginx/conf.d/moebooru_assets.conf|<nowiki>server {
    listen 127.0.0.1:8080; # tells Nginx to listen for traffic passed by Varnish if unencrypted http
    server_name assets.eikonos.org;
    # directory of static assets, first generate with the command:
    # RAILS_ENV=production bundle exec rake assets:precompile
    root /home/moe/booru/public;
    error_page 500 502 503 504 /500.html;
    keepalive_timeout 10;
    location ^~ / {
        expires 1M;
        access_log off;
        add_header Cache-Control "public";
        try_files $uri =404;
    }
    # users must access files.eikonos.org for full images, though thumbs are shared through assets
    location ^~ /data/images/ { deny all; }
}
</nowiki>}}
{{hc|/etc/nginx/conf.d/moebooru_files.conf|<nowiki>
server {
    listen 127.0.0.1:8080; # tells Nginx to listen for traffic passed by Varnish if unencrypted http
    server_name files.eikonos.org;
    # directory of full size files
    root /home/moe/booru/public/;
    error_page 500 502 503 504 /500.html;
    keepalive_timeout 10;
    location ^~ /data/ {
        expires 1M;
        access_log off;
        add_header Cache-Control "public";
        try_files $uri =404;
    }
    location ^~ /assets/ { deny all; } # users must access assets.eikonos.org for this
}
</nowiki>}}


== Systemd Service ==
== Systemd Service ==
Line 862: Line 741:
}}
}}


Images and thumbs and other generated items:
Images only:


{{bc|
{{bc|
tar -cvzf eikonos.org-20170128_data.tar.gz /var/www/moebooru/public/data/
tar -cvzf eikonos.org-20170128_images.tar.gz /var/www/moebooru/public/data/image/
}}
}}


Code only, no binaries or image data:
Code only, no binaries:


{{bc|<nowiki>
{{bc|<nowiki>
tar --exclude='/home/moe/booru/tmp' --exclude='/home/moe/booru/public' --exclude='/home/moe/booru/vendor' -cvjf eikonos.org-20170128_var_www_booru-eikonos-org.tar.gz /home/moe/booru
tar --exclude='/home/moe/booru/tmp' --exclude='/home/moe/booru/vendor' -cvjf eikonos.org-20170128_var_www_booru-eikonos-org.tar.gz /home/moe/booru
</nowiki>}}
</nowiki>}}
== Restore/Move ==
=== PostgreSQL database ===
First, create the user with CreateDB permissions:
{{bc|
# su - postgres
$ psql
postgres # CREATE USER moebooru_user CREATEDB;
}}
then import the sql dump with that user.
== Troubleshooting ==
=== Pagination not showing in Post#index ===
{{Note|This issue only occurs when you are using the default cache instead of Memcached. We strongly recommend using Memcached for this reason.}}
https://github.com/moebooru/moebooru/issues/42
=== Atom RSS Canonical URL Problem ===
Bloo had met an issue with the [https://github.com/moebooru/moebooru/issues/71 Atom RSS URLs pointing to his IP instead of the domain name.] Here's the patch he used:
{{bc|
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -126,7 +126,7 @@ module ApplicationHelper
    elsif post.is_a?(Array)
      posts = post
-      new_params = params.to_unsafe_h.merge :only_path => true
+      new_params = params.to_unsafe_h.merge :host=>'otakupaper.com'
      if posts.previous_page.present?
        html << tag("link", :href => url_for(new_params.merge :page => 1), :rel => "first", :title => "First Page")
diff --git a/app/helpers/post_helper.rb b/app/helpers/post_helper.rb
index 32cf04f..cf98cb5 100644
--- a/app/helpers/post_helper.rb
+++ b/app/helpers/post_helper.rb
@@ -18,7 +18,7 @@ module PostHelper
      "type"  => tag_options[:type] || "application/#{type}+xml",
      "title" => tag_options[:title] || type.to_s.upcase,
      "id"    => tag_options[:id],
-      "href"  => url_options.is_a?(Hash) ? url_for(url_options.merge(:only_path => false)) : url_options
+      "href"  => url_options.is_a?(Hash) ? url_for(url_options.merge(:host => CONFIG["server_host"])) : url_options
    )
  end
}}


== Sources ==
== Sources ==


* Get configuration tips from here: http://wiki.douglasqsantos.com.br/doku.php/deploying_a_rails_app_on_debian_jessie_with_capistrano_nginx_and_puma_en
* Get configuration tips from here: http://wiki.douglasqsantos.com.br/doku.php/deploying_a_rails_app_on_debian_jessie_with_capistrano_nginx_and_puma_en
Please note that all contributions to Bibliotheca Anonoma are considered to be released under the Creative Commons Attribution-ShareAlike (see Bibliotheca Anonoma:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

Templates used on this page: