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

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
แถว 70: แถว 70:
  
 
Paste the following snippet of code to the file '''<tt>grader</tt>''' just created.
 
Paste the following snippet of code to the file '''<tt>grader</tt>''' just created.
 
+
<pre>
<VirtualHost *>
+
<VirtualHost *>
 
   
 
   
Alias /grader "/home/ioi/grader/web/public"
+
Alias /grader "/home/ioi/grader/web/public"
 
   
 
   
<directory "/home/ioi/grader/web/public/">
+
<directory "/home/ioi/grader/web/public/">
  Options FollowSymLinks
+
  Options FollowSymLinks
  AllowOverride None
+
  AllowOverride None
  Order allow,deny
+
  Order allow,deny
  Allow from all
+
  Allow from all
</directory>
+
</directory>
 
   
 
   
<proxy balancer://mongrel_cluster>
+
<proxy balancer://mongrel_cluster>
  BalancerMember http://127.0.0.1:5000
+
  BalancerMember http://127.0.0.1:5000
  BalancerMember http://127.0.0.1:5001
+
  BalancerMember http://127.0.0.1:5001
  BalancerMember http://127.0.0.1:5002
+
  Allow from all
  BalancerMember http://127.0.0.1:5003
+
</proxy>
  BalancerMember http://127.0.0.1:5004
 
  Allow from all
 
</proxy>
 
 
   
 
   
<Location /balancer-manager>
+
<Location /balancer-manager>
  SetHandler balancer-manager
+
  SetHandler balancer-manager
</Location>
+
</Location>
 
   
 
   
RewriteEngine On
+
RewriteEngine On
 
   
 
   
# Uncomment for rewrite debugging
+
# Uncomment for rewrite debugging
# RewriteLog "/var/log/apache2/ioi_rewrite.log"
+
# RewriteLog "/var/log/apache2/ioi_rewrite.log"
# RewriteLogLevel 9
+
# RewriteLogLevel 9
 
   
 
   
# Redirect all non-static requests to cluster
+
# Redirect all non-static requests to cluster
RewriteCond %{REQUEST_URI} ^/grader/(.*)$
+
RewriteCond %{REQUEST_URI} ^/grader/(.*)$
RewriteCond /home/ioi/grader/web/public/%{REQUEST_FILENAME} !-f
+
RewriteCond /home/ioi/grader/web/public/%{REQUEST_FILENAME} !-f
RewriteRule ^/grader/(.*)$ balancer://mongrel_cluster/$1 [P,QSA,L]
+
RewriteRule ^/grader/(.*)$ balancer://mongrel_cluster/$1 [P,QSA,L]
 
   
 
   
</VirtualHost>
+
</VirtualHost>
 +
</pre>

รุ่นแก้ไขเมื่อ 14:58, 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 make the grader application as one of the available sites.

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

Paste the following snippet of code to the file grader just created.

<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/$1 [P,QSA,L]
 
</VirtualHost>