Welcome Guest Login Register Member List
ExpressionEngine Forums
Advanced Search
Username: Password:
Remember Me? forgot password?
You are here: Forum Home  >  Installation  >  Linux  >  Thread
   
 
HOWTO: Install Tracks on a CentOS 5 Server using Apache (proxy) and SSL
 
sparkyjf
Posted: 10 November 2008 09:53 PM   [ Ignore ]  
Newbie
Rank
Total Posts:  3
Joined  2008-11-09

Hi all,

I’ve spent some time researching GTD apps and am still searching for the one that suits me best. My boss introduced me to Tracks and I have to say I’m impressed so far. To give it a fair go I installed in on my VPS (CentOS 5 x86_64) with SSL so that I can access it from anywhere securely. It took me a while to come up with all the bits - the information below is an amalgamation of lots of bits on the web so I hope someone will find it useful as it show’s a pretty complete install onto CentOS 5. Comments or thoughts welcome smile

This was performed in a CentOS 5.2 server (fully updated) and assumes that MySQL and Apache (the standard CentOS packages) are installed and working. It also requires mysql-devel to build the Ruby gem for MySQL.

1. Make sure the Ruby RPM’s are installed - the CentOS ones are 1.8.5 but these are known to work so we won’t do a recompile here.

# yum install ruby ruby-devel ruby-libs ruby-irb ruby-rdoc 

2. Install Ruby Gems.

# cd /usr/local/src
# mkdir -p rubygems/1.3.1
# cd rubygems/1.3.1
# wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
# tar -xzf rubygems-1.3.1.tgz
# cd rubygems-1.3.1
# ruby ./setup.rb 

3. Install Rails

# gem install rails 

4. Install the MySQL gem

# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config 

(without these switches the install fails - it seems it can’t find the right MySQL files)

5. Set up the MySQL DB

# mysql -uroot -p
mysql> CREATE DATABASE tracks;
mysql> GRANT ALL PRIVILEGES ON tracks.* TO 'tracksuser'@'localhost' IDENTIFIED BY 'password-goes-here'; 

6. Unpack Tracks

# cd /var/www
# wget http://www.rousette.org.uk/projects/files/tracks-current.zip
# unzip tracks-current.zip
# ln -s tracks-1.6/ tracks
# rm -f tracks-current.zip 

7. Create a user for tracks and update file ownership:

# useradd -d /var/www/tracks tracks
# chown -R tracks:tracks /var/www/tracks-1.6 

8. Put this file into /etc/init.d so that tracks can be run at startup:

# cat /etc/init.d/tracks

#!/bin/bash
#
# tracks      This shell script takes care of starting and stopping
#             the standalonetracks web server.
#
# chkconfig: 345 60 50
# description: Tracks is a web-based application to help you implement David Allen's
#              Getting Things Done. methodology. It was built using Ruby on Rails,
#              and comes with a built-in webserver (WEBrick) which this script controls
# processname: ruby /var/www/tracks/script/server --daemon --environment=production
# config: /var/www/tracks/config/*.rb

# Source function library.
. /etc/rc.d/init.d/functions

PROC
=/var/www/tracks/script/server
USER
=tracks
PIDFILE
=/var/run/tracks.pid

PATH
="/sbin:/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
export PATH
LOCK
=/var/lock/subsys/tracks
RETVAL
=0

[ 
-x $PROC ] || exit 0

start
() {
       
# Check if it is already running
       
if [ ! -f $LOCK ]; then
           
echo -n $"Starting Tracks: "
           
daemon --user=$USER $PROC --daemon --environment=production
           RETVAL
=$?
           if 
[ $RETVAL -eq 0 ]; then
               touch $LOCK
               pgrep 
-f -u $USER $"ruby $PROC --daemon --environment=production" > $PIDFILE
           fi
           
echo
       
fi
       
return $RETVAL
}

stop
() {
       
echo -n $"Stopping Tracks: "
       
killproc -p $PIDFILE tracks
       RETVAL
=$?
       
[ $RETVAL -eq 0 ] && rm -f $LOCK
       
echo
       return 
$RETVAL
}

restart
() {
       stop
       start
}

case "$1" in
start
)
       
start
       
;;
stop)
       
stop
       
;;
reload)
       
reload
       
;;
restart)
       
restart
       
;;
condrestart)
       if 
[ -f $LOCK ]; then
           restart
       fi
       
;;
status)
       
status -p $PIDFILE tracks
       
;;
*)
       echo $
"Usage: $0 {start|stop|status|restart|condrestart}"
       
exit 1
esac

exit $RETVAL 

9. Configure tracks to run on startup

# chkconfig --add tracks
# chkconfig --list tracks 

10. Set up the config files:

# cd /var/www/tracks/config 

As per the Tracks web site:

• If you downloaded Tracks 1.6 via Subversion, you need to duplicate the files database.yml.tmpl and environment.yml.tmpl and remove the *.tmpl extension from the duplicates. Similarly, duplicate /log.tmpl and remove the *.tmpl extension, then edit the files as described in steps 2 and 3.
• Open the file /config/database.yml and edit the production: section with the details of your database. If you are using MySQL the adapter: line should read adapter: mysql, host: localhost (in the majority of cases), and your username and password should match those you assigned when you created the database. If you are using SQLite3, you should have only two lines under the production section: adapter: sqlite3 and database: db/tracks-15-blank.db. If you downloaded the zipped file, the database.yml file is already configured to use the provided SQLite3 file.
• Open the file /config/environment.rb, and read through the settings to make sure that they suit your setup. In most cases, all you need to change is the SALT = “change-me” line (change the string “change-me” to some other string of your choice), and the time zone setting.

11. Add the following to the end of config/environment.rb - this will enable us to run Tracks as http://www.example.com/tracks rather than as http://www.example.com/ as the Rails environment expects.

ActionController::AbstractRequest.relative_url_root = "/tracks" 

12. Set up the DB schema

# rake db:migrate RAILS_ENV=production 
Profile
 
sparkyjf
Posted: 10 November 2008 09:55 PM   [ Ignore ]   [ # 1 ]  
Newbie
Rank
Total Posts:  3
Joined  2008-11-09

Ran out of room in the first post - continued…

13. Start up the server - this will start it running on localhost (0.0.0.0) on port tcp/3000 so remember to firewall this off if you don’t want public access to it. This will depend on your firewall config - I have iptables set up to deny access to everything unless I specifically allow it, so I didn’t have to do anything here.

If all goes well you will get the following output:

# service tracks start
Starting Tracks: => Booting WEBrick...
=> 
Rails application started on http://0.0.0.0:3000
[2008-11-10 15:13:26] INFO  WEBrick 1.3.1
[2008
-11-10 15:13:26] INFO  ruby 1.8.5 (2006-08-25) [x86_64-linux]
                                                          [  OK  ] 

14. Finally configure Apache to Proxy to the Rails install, and rewrite to HTTPS so that we can access it securely as if it was running on our Apache install.

For this you need to have mod_proxy and mod_rewrite installed - this is already there on CentOS 5. All I had to do was create the following file in /etc/httpd/conf.d:

# cat /etc/httpd/conf.d/tracks.conf
RewriteEngine on
# Prevent redundant rewrites - only rewrite when https is off
RewriteCond %{HTTPS} !=on
RewriteRule 
^/tracks(.*) https://www.example.com/tracks$1 [R,L]


ServerSignature On
ProxyRequests Off
<Proxy *>
     
Order deny,allow
     Allow from all
</Proxy>
ProxyPass /tracks http://127.0.0.1:3000
ProxyPassReverse /tracks http://127.0.0.1:3000
ProxyPreserveHost On 

If you don’t want to run under HTTPS, just remove the RewriteCond line and change https to http on the RewriteRule line.

15. Restart Apache

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd
:                                            [  OK  ] 

Note

If you want to run Tracks as the web root (i.e. http://www.example.com/ instead of http://www.example.com/tracks) you can skip step 11, and for step 14 change all instances of /tracks to /

Profile
 
Reinier Balt
Posted: 11 November 2008 02:44 PM   [ Ignore ]   [ # 2 ]  
Sr. Member
RankRankRankRank
Total Posts:  551
Joined  2006-10-05

nice writeup. I have added a link to your post on the wiki here: http://dev.rousette.org.uk/wiki/Tracks/Install

Profile
 
sparkyjf
Posted: 12 November 2008 06:07 PM   [ Ignore ]   [ # 3 ]  
Newbie
Rank
Total Posts:  3
Joined  2008-11-09

Ok, so my trial of Tracks has been going well so far - however memory is very limited on my VPS and I don’t have the option to add a swap file. I’ve been trying a few things out recently and discovered I was in danger of running out of memory.

Having a look through the output of top I found that the built in tracks web server was occupying about 50Mb of memory. Not sure if this is right or not - however on shutting it down my memory usage did drop down by around 50Mb. So I thought I’d better see if there was another option.

Digging round the web, I wasn’t sure whether it was best to try fastcgi, mod_fcgi or mod_rails (something I only found out about when I was investigating the first two). mod_rails looked like a good option (http://www.modrails.com/) so I thought I’d give it a go. It installed flawlessly and and doesn’t seem to be using drawing significantly more memory since I added it to my Apache install, and Tracks seems to work just as well and quickly as it did before. So for me this is a success - I guess as they say though YMMV. I haven’t rewritten the above guide, but for anyone who’s interested here’s how I went from the setup about to one using mod_rails.

If anyone would find it helpful I could make a new version of the above guide.

1. Install Passenger using gem:

# gem install passenger 

I got some warnings about already initialized constants in horo.rb in the RDocs install, but the actual gem seemed to install ok without any additional configuration.

2. Install the Apache module:

# passenger-install-apache2-module 

Follow the prompts - it all installed ok for me.

3. Delete or move the old /etc/httpd/conf.d/tracks.conf aside, and then create a new one that will make use of mod_rails instead:

# mv /etc/httpd/conf.d/tracks.conf /etc/httpd/conf.d/tracks.conf.webrick 

Create a config file so that Apache knows to use mod_rails:

# cat /etc/httpd/conf.d/modrails.conf
  
LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
  PassengerRoot 
/usr/lib64/ruby/gems/1.8/gems/passenger-2.0.3
  PassengerRuby 
/usr/bin/ruby 

And one for tracks:

# cat /etc/httpd/conf.d/tracks.conf
RailsBaseURI /tracks 

4. Finally create a symbolic link to the public directory under tracks in the DocumentRoot of your Apache server:
My DocumentRoot is /var/www/html, so this is done as follows:

# ln -s /var/www/tracks/public/ /var/www/html/tracks 

5. Finally shut down WEBrick, disable the init.d script, and get Apache to pick up the new configuration:

# service tracks stop
# chkconfig --del tracks
# service httpd restart 

Tracks should now be accessible as it was before.

Profile
 
tom_k
Posted: 19 December 2008 02:37 AM   [ Ignore ]   [ # 4 ]  
Newbie
Rank
Total Posts:  1
Joined  2008-12-18

One small nit and a question.

I configured tracks on a seperate virtual machine then where I am running the web server, so mostly followed the instructions of the original poster. 

The small nit.  It looks like CentOS 5.2 starts mysqld after it starts tracks.  Tracks has a start priority of 60 in the above posting while mysqld on my vm has a start priority of 64.  This was causing tracks to start but generate failure messages when using it.  A small change of the start priory to 99 allows tracks to start after mysqld and happily work after a reboot of the vm.

[root@tracks init.d]# grep chkconfig mysqld tracks
mysqld:# chkconfig: - 64 36
tracks:# chkconfig: 345 99 10

Now my question.

It looks like both the first time you enter your credentials into the login screen, and whenever you use the mobile interface, the next page does not correctly attach the “/tracks” to the url.  I have added the line to the environment.rb file as directed above.

[root@tracks config]# tail -1 environment.rb
ActionController::AbstractRequest.relative_url_root = “/tracks” 

But that does not help for the initial login nor any of the mobile pages. 

I was able to fix the mobile pages by adding more configurations into the httpd conf.d/tracks.conf file.  This fixed the most painful part, all the mobile pages not working.

[root@tao conf.d]# cat tracks.conf
RewriteEngine on
ServerSignature On
ProxyRequests Off

    Order deny,allow
    Allow from all
</Proxy>

RewriteCond %{HTTPS} !=on
RewriteRule ^/tracks(.*) https://www.pretend.net/tracks$1 [R,L]
ProxyPass /tracks http://tracks.private.pretend.net:3000
ProxyPassReverse /tracks http://tracks.private.pretend.net:3000
ProxyPreserveHost On

RewriteCond %{HTTPS} !=on
RewriteRule ^/mobile(.*) https://www.pretend.net/tracks/mobile$1 [R,L]
ProxyPass /mobile http://tracks.private.pretend.net:3000/mobile
ProxyPassReverse /mobile http://tracks.private.pretend.net:3000/mobile
ProxyPreserveHost On

RewriteCond %{HTTPS} !=on
RewriteRule ^/m(.*) https://www.pretend.net/tracks/m$1 [R,L]
ProxyPass /m http://tracks.private.pretend.net:3000/m
ProxyPassReverse /m http://tracks.private.pretend.net:3000/m
ProxyPreserveHost On

But that has not stopped the initial login page for the main interface to redirect me to the wrong place.  Since it only happens that initial time, it is not a huge problem.  But it would be nice if it worked correctly right away.

So, the question.

Can anyone tell me how to fix http issue where I need to dedicate both “/m” and “/mobile” to the tracks app?

And can anyone tell me how to fix the http issue of the initial login not taking me to the proper “/tracks” url?

If there is a better place to ask these questions, please direct me there and I will

Profile
 
   
 
 
‹‹ Problem running Tracks on Ubuntu      Installation on Ubuntu v8.10 - html issue ››

Powered By ExpressionEngine
Template Design By Sonnenvogel.com
Select a theme:

ExpressionEngine Discussion Forum - Version 2.1.2 (20091002)
Script Executed in 0.1814 seconds

Atom Feed
RSS 2.0