ผลต่างระหว่างรุ่นของ "Installing Grader Web Interface"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
แถว 46: แถว 46:
  
 
Have mongrel create a config file for you:
 
Have mongrel create a config file for you:
  mongrel_rails cluster::config -e production -p 5000 -a 127.0.0.1 -N 2 -c ~/grader/web
+
  mongrel_rails cluster::configure -e production -p 5000 -a 127.0.0.1 -N 2 -c ~/grader/web
  
 
The config file is located at '''<tt>~/grader/web/config/mongrel_cluster.yml</tt>'''. It should look like this:
 
The config file is located at '''<tt>~/grader/web/config/mongrel_cluster.yml</tt>'''. It should look like this:

รุ่นแก้ไขเมื่อ 07:56, 17 มีนาคม 2551

Return to ฐานความรู้

The aim of this document is to set up the grader's web interface rails application so that users can access it via http://your-web-server/grader. The application uses mongrel_cluster as its load balancer.

Install HAML

The grader makes use of HAML. So you need to install it first.

gem install haml --no-ri

Check out the Grader Web Interface

First, make a directory that will contain all the grader files. In my case, I make a directory called "grader" inside my home directory.

mkdir ~/grader

Inside the directory, you check out the web interface.

svn co http://theory.cpe.ku.ac.th/grader/web/tags/0.1 ~/grader/web

Create routes.rb

cd ~/grader/web/config
cp routes.rb.SAMPLE routes.rb

Set up the Database

cd ~/grader/web/config
cp database.yml.SAMPLE database.yml

Then, edit database.yml so that it reflects the database setting of your machine.

Note: In Ubuntu, the database socket is not located at /tmp/mysql.sock as it is in other distributions. You need to add one extra line in database.yml to tell rails this:

 adapter: mysql
 socket: /var/run/mysqld/mysqld.sock
 database: ioi
 username: ioi
 password: whateverpassword
 host: localhost

Next, you do the migration:

cd ~/grader/web
rake db:migrate

Check your MySQL to see if the tables actually appear.

Test the Grader for the First Time

Then, run the server

ruby script/server

Go check http://localhost:3000. You can login as root and the password is ioionrails. You should change the password immediately and logout.

Set up Mongrel Cluster

We assume that you already have mongrel_cluster installed in your system.

Have mongrel create a config file for you:

mongrel_rails cluster::configure -e production -p 5000 -a 127.0.0.1 -N 2 -c ~/grader/web

The config file is located at ~/grader/web/config/mongrel_cluster.yml. It should look like this:

--- 
cwd: /home/ioi/grader/web
log_file: log/mongrel.log
port: "5000"
environment: production
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
servers: 2

Next, start the server.

cd /~grader/web
mongrel_rails cluster::start

See if it works by checking out http://localhost:5000/.

Connect mongrel_cluster with apache2

First, we edit apache2's configuration.

cd /etc/apache2/sites-available
sudo emacs default

Paste the following snippet of code into the bottom part of the file before </VirtualHost>

Alias /grader "/home/ioi/grader/web/public"
 
<directory "/home/ioi/grader/web/public/">
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
</directory>
 
<proxy balancer://mongrel_cluster>
  BalancerMember http://127.0.0.1:5000
  BalancerMember http://127.0.0.1:5001
  Allow from all
</proxy>
 
<Location /balancer-manager>
  SetHandler balancer-manager
</Location>
 
RewriteEngine On
 
# Uncomment for rewrite debugging
# RewriteLog "/var/log/apache2/ioi_rewrite.log"
# RewriteLogLevel 9
 
# Redirect all non-static requests to cluster
RewriteCond %{REQUEST_URI} ^/grader/(.*)$
RewriteCond /home/ioi/grader/web/public/%{REQUEST_FILENAME} !-f
RewriteRule ^/grader/(.*)$ balancer://mongrel_cluster/grader/$1 [P,QSA,L]

Next, restart apache2.

/etc/init.d/apache2 restart

Edit routes.rb

cd ~/grader/web/config
emacs routes.rb

Add the bolden text to the file:

ActionController::Routing::Routes.draw do |map|
  # The priority is based upon order of creation: first created -> highest priority.
  
  # Sample of regular route:
  # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
  # This route can be invoked with purchase_url(:id => product.id)

  # You can have the root of your site routed by hooking up  
  # -- just remember to delete public/index.html.
  map.connect 'grader/', :controller => 'main', :action => 'login'

  # Allow downloading Web Service WSDL as a file with an extension
  # instead of a file named 'wsdl'
  map.connect ':controller/service.wsdl', :action => 'wsdl'

  # Install the default route as the lowest priority.
  map.connect 'grader/:controller/:action/:id.:format'
  map.connect 'grader/:controller/:action/:id'
end

Edit environments/production.rb

cd ~/grader/web/config/environments
emacs production.rb

Set config.action_controller.asset_host to the URL of your grader site.

# Settings specified here will take precedence over those in config/environment.rb

# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true

# Use a different logger for distributed setups
# config.logger = SyslogLogger.new

# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching             = true

# Enable serving of images, stylesheets, and javascripts from an asset server
config.action_controller.asset_host                  = "http://<your-host-name-or-ip-address>/grader"

# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false

Make a Symbolic Link Hack

In order to make CCS work, we need to create a symbolic link ~/grader/web/public/grader to ~/grader/web/public.

cd ~/grader/web/public
ln -s ~/grader/web/public grader

Restart mongrel_cluster

cd ~grader/web
mongrel_rails cluster::restart

And this should do it!