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

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
แถว 104: แถว 104:
 
Next, restart apache2.
 
Next, restart apache2.
 
  /etc/init.d/apache2 restart
 
  /etc/init.d/apache2 restart
 +
 +
Then, we edit '''<tt>routes.rb</tt>'''.
 +
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 '<b>grader/</b>', :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 '<b>grader/</b>:controller/:action/:id.:format'
 +
  map.connect '<b>grader/</b>:controller/:action/:id'
 +
end

รุ่นแก้ไขเมื่อ 15:30, 16 มีนาคม 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::config -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.

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

Then, we 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