Thursday, September 14, 2006

How I setup Subversion, Apache, and Capistrono


sudo vi/etc/apache2/mods-enabled/dav_svn.conf
--
#Comment out the following 2 lines with your repo path
#DAV svn <-Comment out this
DAV svn

#SVNPath /var/lib/svn <-Comment out this
SVNPath /var/local/svn

<LimitExcept GET PROPFIND OPTIONS REPORT>
#Require valid-user <-Comment this if you don't need basic authentication
Options Indexes
Order allow,deny
allow from all
</LimitExcept>


HOWTO : Subversion & Eclipse development environment - Ubuntu Forums


You should deviate from the above configuration if you are using this for rails development because otherwise you will allow for anyone to see your database password from the database.yml file. In fact, I wouldn't be surprised if Yahoo or Google crawls the web repository and make the password searchable.

From here, I followed these instructions to get Capistrano started.


On the client, check out the app

svn checkout svn://svnserver.com/app1 (enter user and pass as needed)
cd app1

capistranize the app:

cap --apply-to app1

Now, to set up the app for capistrano deployment, configure deploy.rb(see example below) appropriately with the correct paths, servers,restart method to restart apache, etc.


On the client,

rake remote:exec ACTION=setup

This will setup the base structure ${deploy_to}/releases /current /shared

current is a symlink to the most recent release/YYYYMMDDHHMMSS/ directory. shared contains shared logfiles etc.

That should do it!

example deploy.rb used for app1 (comments removed):

##########

 




  1. set :application, "app1"

  2. set :repository, "svn://svnserver.com/"

  3. role :web, "yourserver.com"

  4. role :app, "yourserver.com"

  5. role :db, "yourserver.com", :primary => true

  6. set :deploy_to, "/home/rails/application_path/"


  7. desc "Restart the web server"

  8. task :restart, :roles => :app do

  9. sudo "/usr/local/etc/rc.d/apache2.sh restart"

  10. end



#########

PS: apache has to point to /home/rails/application_path/current/public for this to function properly.

Quick guide to setting up svn, capistrano, apache and radrails - Rails Weenie



And here is how I set up my svnserve script for /etc/init.d/svnserve. I didn't like trying to get inetd or xnetd to work. This is based off of the default one found in the same directory.



 



#! /bin/sh

### BEGIN INIT INFO

# Provides: svnserve

# Required-Start: $local_fs $remote_fs

# Required-Stop: $local_fs $remote_fs

# Default-Start: 2 3 4 5

# Default-Stop: S 0 1 6

# Short-Description: Subversion server

# Description: This start svnserve on a particular port. Others can

# access it using svn://servernam/.

### END INIT INFO

#

# Author: Jeff Rasmussen <jeff.rasmussen at gmail.com>.

#

# Version: @(#)svnserve 0.0.1 11-Sept-2006 jeff.rasmussen at gmail.com

#set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="Subversion Server"

NAME=svnserve

DAEMON=/usr/bin/$NAME

PIDFILE=/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

PORT=3690

REPOSITORY=/var/local/svn/

DAEMON_OPTS="-d --listen-port=$PORT -r $REPOSITORY"

# Gracefully exit if the package has been removed.

test -x $DAEMON || exit 0

# Read config file if it is present.

#if [ -r /etc/default/$NAME ]

#then

# . /etc/default/$NAME

#fi

#

# Function that starts the daemon/service.

#

d_start() {

start-stop-daemon --start --quiet --pidfile $PIDFILE

--exec $DAEMON -- $DAEMON_OPTS

|| echo -n " already running"

}

#

# Function that stops the daemon/service.

#

d_stop() {

start-stop-daemon --stop --quiet --pidfile $PIDFILE

--name $NAME

|| echo -n " not running"

}

#

# Function that sends a SIGHUP to the daemon/service.

#

d_reload() {

start-stop-daemon --stop --quiet --pidfile $PIDFILE

--name $NAME --signal 1

}

case "$1" in

start)

echo -n "Starting $DESC: $NAME"

d_start

echo "."

;;

stop)

echo -n "Stopping $DESC: $NAME"

d_stop

echo "."

;;

#reload)

#

# If the daemon can reload its configuration without

# restarting (for example, when it is sent a SIGHUP),

# then implement that here.

#

# If the daemon responds to changes in its config file

# directly anyway, make this an "exit 0".

#

# echo -n "Reloading $DESC configuration..."

# d_reload

# echo "done."

#;;

restart|force-reload)

#

# If the "reload" option is implemented, move the "force-reload"

# option to the "reload" entry above. If not, "force-reload" is

# just the same as "restart".

#

echo -n "Restarting $DESC: $NAME"

d_stop

# One second might not be time enough for a daemon to stop,

# if this happens, d_start will fail (and dpkg will break if

# the package is being upgraded). Change the timeout if needed

# be, or change d_stop to have start-stop-daemon use --retry.

# Notice that using --retry slows down the shutdown process somewhat.

sleep 1

d_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2

exit 3

;;

esac

exit 0



technorati tags:, , ,