[Locomotive-users] Locomotive and Apache?
Grant Neufeld
grant at grantneufeld.ca
Sun Jan 7 00:11:48 GMT 2007
At 2:47 PM -0800 1/6/07, Rich Morin wrote:
>Now I'm looking into adding Locomotive to the mix.
...
>I'll be needing to tie Rails into the existing Apache setup.
Here's a (kind of) quick and dirty way (no software installs/builds except your existing apache, Locomotive and a simple StartupItem).
1) Setup your app in Locomotive and make special note of the Port used (default 3000).
2) Create virtual host entries in your httpd.conf (or a linked .conf file) that proxies to the Locomotive (mongrel) http port:
<VirtualHost *>
ServerName your.virtual.host.name.tld
ServerAdmin your-admin-email at youremailhost.tld
ErrorLog /dev/null
CustomLog /dev/null common
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>
Note that the Port from Locomotive is referenced in ProxyPass and ProxyPassReverse. 127.0.0.1 being the localhost self-referential ip address.
I have Apache's logging off here (/dev/null) because the Rails app generates its own logs. If you want Apache to generate access and error logs, then change those options.
To relaunch Apache with this new config, just:
sudo apachectl graceful
However, you may want to test the config first, to make sure it's correct:
sudo apachectl configtest
3) Setup a StartupItem to have your Locomotive app set to start on system launch. System-wide custom StartupItems are found in /Library/StartupItems/.
I've got an example at:
http://www.grantneufeld.ca/file/grant/LocomotiveStartupItem.zip
Edit the LocomotiveStartupItem file to configure the path(s) of your Locomotive-run Rails site(s).
Copy the LocomotiveStartupItem folder to /Library/StartupItems/
You'll also need to set the owner to root and the group to wheel:
sudo chown -R -P root:wheel LocomotiveStartupItem/
(I'm also attaching the text of the two files that are found in the LocomotiveStartupItem folder so you don't need to download them separately.)
With that in place, you can restart your Mac server and have your Locomotive site(s) run without having to login or run Locomotive manually.
You can get things going without having to restart your Mac. From the command line terminal:
cd /path/to/your/rails/site/root/
sudo locomotive start
Replacing "start" with "stop" will halt your rails site.
Replacing "start" with "restart" will reload your site (useful if you've updated any of the scripts and are running in "production" mode rather than "development").
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/Library/StartupItems/LocomotiveStartupItem/LocomotiveStartupItem:
#!/bin/sh
#
# /Library/StartupItems/LocomotiveStartupItem/LocomotiveStartupItem
#
# A script to automatically start up Ruby on Rails websites,
# using Locomotive, on system bootup for Mac OS X.
#
# CONFIGURATION:
#
# Edit the "RAILS SITE PATHS" and the "COMMANDS" below
#
# Show usage when no command option was given
if [ -z $1 ] ; then
echo "Usage: $0 [start|stop|restart] "
exit 1
fi
# Source the common setup functions for startup scripts
test -r /etc/rc.common || exit 1
. /etc/rc.common
# The path to your locomotive command-line tool
SCRIPT="/usr/local/bin/locomotive"
### RAILS SITE PATHS: ###
# The paths to your rails sites, one per site
RAILSROOT1="/Users/someuser/Sites/railsapp1"
#RAILSROOT2="/Users/someuser/Sites/railsapp2"
### COMMANDS: ###
StartService ()
{
ConsoleMessage "Starting Ruby on Rails website"
cd $RAILSROOT1
$SCRIPT start > /dev/null 2>&1
# repeat for each rails site path
#cd $RAILSROOT2
#$SCRIPT start > /dev/null 2>&1
}
StopService ()
{
ConsoleMessage "Stopping CHAI on Rails website"
cd $RAILSROOT1
$SCRIPT stop > /dev/null 2>&1
# repeat for each rails site path
#cd $RAILSROOT2
#$SCRIPT stop > /dev/null 2>&1
}
RestartService ()
{
ConsoleMessage "Restarting CHAI on Rails website"
cd $RAILSROOT1
$SCRIPT restart > /dev/null 2>&1
# repeat for each rails site path
#cd $RAILSROOT2
#$SCRIPT restart > /dev/null 2>&1
}
if test -x $SCRIPT ; then
RunService "$1"
else
ConsoleMessage "Could not find locomotive command!"
fi
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/Library/StartupItems/LocomotiveStartupItem/StartupParameters.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Description</key>
<string>Rails Websites on Locomotive</string>
<key>OrderPreference</key>
<string>None</string>
<key>Provides</key>
<array>
<string>RailsWebsites</string>
</array>
<key>Uses</key>
<array>
<string>Network</string>
<string>Resolver</string>
</array>
</dict>
</plist>
More information about the Locomotive-users
mailing list