Site5 Community Forums


Go Back   Site5 Web Hosting Forums > Community Forums > Scripts and Programming > Ruby

Ruby Discussion of Ruby and all related code, and its usage and development, both on Site5 servers and elsewhere

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old January 6th, 2006, 07:11 PM
jdnorthrup jdnorthrup is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Dec 2005
Posts: 8
Arrow OVERVIEW: setting up ROR, SVN and Switchtower on Site5

Hi all--

i want to share my experiences getting ruby on rails deployed to site5, since it appears there aren't that many details about some of the finer points.

here's what i assume (since these were my needs):
a) you have a rails development setup on your local box
b) you want to deploy to your site5 shared account
c) you want a subversion repository on the site5 account to manage your files
d) you want to use switchtower to deploy your application

here are some of my notes from getting this working:

- get subversion working on your local box. you really only need to use the client from this end. visit http://subversion.tigris.org if you're new to subversion.

{BEGIN WINDOWS INTERLUDE}

- i (have to) use a windows box at work, so i had to do some more things to get ssh and subversion working from a command line. i use cygwin to get more unix-y tools, including a command-line ssh client (note: i do use the windows-native installer of subversion because i've found that easier). see http://www.cygwin.com/ if you're not familiar.

basically, i had to setup the subversion client to use my cygwin's ssh.exe for communicating with the remote server. there's a config file in:
Code:
C:\Documents and Settings\{user}\Application Data\Subversion\config
in the section about "configuring tunnel agents", i setup my ssh client to use the one in my cygwin bin directory:
Code:
ssh = $SVN_SSH C:\\tools\\cygwin\\bin\\ssh.exe
(yes, those are double-backslashes)

there are also ways to do this using the PuTTy suite.
see http://www.chiark.greenend.org.uk/~sgtatham/putty/

now you should be able to do things like run the svn command line client or use TortoiseSVN from the Explorer, and connect to repositories on your Site5 account using svn+ssh -style URLs (once you get a few other things set up)

- on anoter note, windows users will have to set the execute and eof-style properties for several files in a rails project. this is a fairly intermediate-to-advanced subversion task that's ez if you just read the subversion book at http://svnbook.red-bean.com/
you need to set these properties on all the files in the script/ folder, as well as public/.htaccess and public/dispatch.*.
from the script folder, you can execute
Code:
svn propset svn:executable ON -R .
svn propset svn:eol-style NATIVE -R .
and so-on for the files in public/.

{WINDOWS INTERLUDE OVER}

- meanwhile, back at the ranch, open a ticket with support to get Bash enabled as your login shell in order to begin setting up subversion, and once you've logged in at least once to agree to the banner, ask to have the banner removed. Otherwise you'll have problems with some fancy ssh work later on.

- once ssh'ed into your account with bash (prompt will be something like "-bash-3.00$"), create your subversion repository. i did this at /home/{myaccount}/repos/. if you don't know how to do this, you can learn more about subversion by visiting http://subversion.tigris.org

- setup an RSA key pair to login using SSH without entering the password a bunch of times. this is useful for using subversion and switchtower since they sometimes SSH into the machine several times.

i generated a public key on my local box using ssh-keygen, and then put my public key onto the site5 server at ~/.ssh/authorized_keys using the scp program, which lets you remotely copy files to a server.

a good tutorial that includes information on doing the RSA key thing:
http://berserk.org/2005/10/08/textma...ng-workaround/
note that some of this tutorial may not apply to what you're doing here! just pay attention to the parts about getting SSH working.

- at this point you should be able to test svn from your local command line as follows:
Code:
svn list svn+ssh://{username}@{domain or ip}/home/{username}/repos/
anything you've imported to your repository will be listed, and at the very least you will see no errors

note: you may need to change this up in your case if you're not just pointing to the ip address of your sit5 host (like i am, since i haven't gotten this whole thing stable enough yet to move our company's domain over!)

- now switchtower will pretty much work out of the box, as far as i've seen. if you're not familiar, the book is up at:
http://manuals.rubyonrails.com/read/book/17
i created a folder on my site called /home/{user}/apps to store my rails application code.

a few things that you need to set in your deploy.rb file. note you will need to sustitute in your username (unless it's 'jd'):

Code:
set :repository, "file:///home/jd/repos/#{application}/trunk"
...
set :deploy_to, "/home/jd/apps/#{application}"
set :user, "jd"     
...
desc "Restart the web server. Overrides the default task for Site5 use"
task :restart, :roles => :app do
  # reaper script doesn't check the user of the fcgi instances, so this will
  # try to send a 'kill -USR2' restart message to EVERY found dispatch.fcgi.
  send(restart_via, "#{current_path}/script/process/reaper -d 'dispatch.fcgi'")
end
the last part is something i added because the default restart task wasn't working on site5. you will see error messages when your run this because the reaper script attempts to restart EVERYONE'S .fcgi processes (regardless of the owner). since you only have priveleges to restart yours, others will not be affected. if anyone at Site5 administration has issues with this approach, please let me know!

- once all that was in place, i was able to do this:
Code:
rake remote_exec ACTION=setup
and then this
Code:
rake deploy
!!!


note:i link my site5 public_html folder to my rails public folder. from your home folder on site5:
Code:
ln -s /home/{username}/apps/site/curent/public public_html

- getting FCGI working: i changed my .htaccess to point to .fcgi instead of .cgi. i do this on my local copy, so the change shows up when switchtower checks the app out on the site5 server. it's no bother to me since i develop under WEBrick, which ignores this anyway.

ditto to the workaround to setting rails into production mode by uncommenting the first statement in the environment.rb file. it doesn't really bother me locally to test with this left in, and once i've deployed to the server the application works in production mode by default.

- however, when you're doing this, you will have to kill your dispatch.fcgi instances whenever you wish to re-deploy your application to the server (since we changed the restart task to be a no-op). anyone know of a good way to restart the .fcgi instances that can be executed by the restart task?


i'm sure i've glossed over some things, but jeez i hope this long-winded post helps somebody. at the very least i can look myself up when i need to do this next

jd northrup
visionwise, inc

Last edited by jdnorthrup; January 9th, 2006 at 04:20 PM.
  #2  
Old January 6th, 2006, 07:37 PM
Steven Byrd Steven Byrd is offline
Site5 Forum Addict
Error: User posts too much! -- Over 1,000 posts.
 
Join Date: Dec 2004
Location: Site5 Forums
Posts: 15,721
JD, thanks. I've stuck this thread so others can find it easier.
__________________
-Steven
Site5 Forum Overseer
Want the answers to the universe and everything? Check out the Site5 Wiki!
"To err is human, to forgive divine."
  #3  
Old January 8th, 2006, 01:17 PM
dwlt dwlt is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 10
SwitchTower on OS X

Just as an addendum to this, if you are on OS X, then you need to install a working copy of Ruby in order for SwitchTower to work properly (the default that comes with OS X has a problem with OpenSSL apparently).

See this page for more information.

David
  #4  
Old January 22nd, 2006, 07:29 PM
hjezik hjezik is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Dec 2005
Posts: 11
Awesome, just what I needed. Thanks!!
  #5  
Old January 25th, 2006, 02:08 AM
rath's Avatar
rath rath is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Sep 2005
Posts: 2
Subclipse and Subversion svn+ssh://

Another addendum

If you want to use Subclipse 0.9.105 (an Eclipse Extension) to manage your subversion repository you are interested on this post.

jyap created a wiki with some information about "Subversion on Site5". It will be good to look at:
http://www.julianyap.com/wiki/index....rsion_on_Site5

Check that it is running properly:
Quote:
Originally Posted by jdnorthrup View Post

- at this point you should be able to test svn from your local command line as follows:
Code:
svn list svn+ssh://{username}@{domain or ip}/home/{username}/repos/
anything you've imported to your repository will be listed, and at the very least you will see no errors

note: you may need to change this up in your case if you're not just pointing to the ip address of your sit5 host (like i am, since i haven't gotten this whole thing stable enough yet to move our company's domain over!)
Install Subclipse 0.9.105 within Eclipse. Help -> Software Updates -> Find and Install
Select "Search for new features to install" and Click "Next ->"
Click "New Remote Site..." and type:

Code:
Name: "Subclipse"
URL: http://subclipse.tigris.org/update
Click OK and Finish
It will check for the latest update. Select the version you want to install and OK.

After a while and the Workbench has restarted click Window -> Show View -> Other
And select "SVN Repository"

This will change the perspective of Eclipse to the SVN Perspective.

Change the properties of SVN to JavaSVN
Window -> Preferences... +Team +SVN and select "JavaSVN (Pure Java)"
Click OK

Now, right click on the "SVN Repository" panel and "New" -> Repository Location

The URL is
Code:
svn+ssh://{domain or ip}/home/{username}/repos/
Click Finish.

It will ask you the username and password. Click Ok and that is all

I ignore how to show the svn directory on the web. If anyone knows, it will be very useful to add a post

If you are interested or want more information please check http://subclipse.tigris.org/servlets...ers&msgNo=3334

Last edited by rath; January 25th, 2006 at 02:13 AM.
  #6  
Old January 27th, 2006, 03:24 PM
motorizedflowers motorizedflowers is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 7
Thanks for the great walk-through. I'm having problems in the "rake deploy" section.

When I issue
Code:
rake deploy
from my local machine, I get the following error:
Code:
querying latest revision...
c:/ruby/bin/rake: No such file or directory - svn log -q -rhead svn+ssh://{domain}/home/{username}/{path-to-repository}/trunk
And when I try that same command from my shell account, I get
Code:
-bash-3.00$ svn log -q -rhead  svn+ssh://{domain}/home/{username}/{path-to-repository}/trunk
svn: Permission denied
Does anyone know what I'm doing wrong?
Thanks!

Edit:
I should say that I can checkout the repository in question to my local machine via TortoiseSVN using the same URL...

Last edited by motorizedflowers; January 27th, 2006 at 03:57 PM.
  #7  
Old January 27th, 2006, 05:04 PM
dwlt dwlt is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 10
Quote:
Originally Posted by motorizedflowers
Thanks for the great walk-through. I'm having problems in the "rake deploy" section.

When I issue
Code:
rake deploy
from my local machine, I get the following error:
Code:
querying latest revision...
c:/ruby/bin/rake: No such file or directory - svn log -q -rhead svn+ssh://{domain}/home/{username}/{path-to-repository}/trunk
And when I try that same command from my shell account, I get
Code:
-bash-3.00$ svn log -q -rhead  svn+ssh://{domain}/home/{username}/{path-to-repository}/trunk
svn: Permission denied
Does anyone know what I'm doing wrong?
Thanks!

Edit:
I should say that I can checkout the repository in question to my local machine via TortoiseSVN using the same URL...
For your local machine, it looks like the error is that you don't have the 'svn' command installed (I assume Tortoise does all the SVN server interaction itself).

On your shell account, I'd say that you need to pass a username and password to the svn command? What do your settings in Tortoise for the repository say?
  #8  
Old January 27th, 2006, 05:14 PM
jdnorthrup jdnorthrup is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Dec 2005
Posts: 8
yes, from your windows command line, if you type "svn -h" do you get the help listing?

the second problem is if you're on the site5 server via ssh, you use the file:/// sytax to access your repository, not the svn+ssh. if you're already there, there's no need to tunnel in!
eg:
Code:
-bash-3.00$ svn list file:///home/jd/repos/{application}/trunk

hope that helps,
jd
__________________
visionwise, inc.
http://www.visionwise.com/
  #9  
Old January 28th, 2006, 11:11 AM
edgar edgar is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 7
Using differents repo from my local box and site5

jd,

I got problems running switchtower 0.10.0 when I try to run "rake deploy" from my local box (windows)

If I set the repository to (deploy.rb):
set :repository, "file:///home/[my_user]/repo/[my_app]/trunk"

My local box (windows) can't reach the subversion repository located in site5

If I set the repository to:

set :repository, "svn+ssh://[my_user]@[my_site]/home/[my_user]/repo/[my_app]/trunk/"

I got a "permission denied" when svn run in site5.

How do you deal with this?

The workaround I found was:

1. Leave the :repository property in deploy.rb to file:// syntax.
set :repository, "file:///home/[my_user]/repo/[my_app]/trunk"
2.Define a new property :repository_from_dev in deploy.rb to svn+ssh:// syntax
set :repository_from_dev, "svn+ssh://[my_user]@[my_site]/home/[my_user]/repo/[my_app]/trunk/"
3. Modify the lib/tasks/switchtower.rake file in order to change the switchtower behavior, adding this line:

# ================================================== =====
# Extension to deploy to site5
# ================================================== =====
require 'switchtower/scm/subversion'

module SwitchTower
module SCM
class Subversion
def latest_revision
configuration.logger.debug "querying latest revision..." unless @latest_revision
#repo = configuration.repository
repo = configuration.repository_from_dev
puts "usando repository_from_dev: #{repo}"
until @latest_revision
match = svn_log(repo).scan(/r(\d+)/).first
@latest_revision = match ? match.first : nil
if @latest_revision.nil?
# if a revision number was not reported, move up a level in the path
# and try again.
repo = File.dirname(repo)
end
end
@latest_revision
end
end
end
end

Now "rake deploy" works fine

Any suggestions? maybe another approach?
  #10  
Old January 28th, 2006, 11:12 AM
motorizedflowers motorizedflowers is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 7
Quote:
Originally Posted by dwlt View Post
For your local machine, it looks like the error is that you don't have the 'svn' command installed (I assume Tortoise does all the SVN server interaction itself).
Right! I installed 'svn' on my local machine and configured it to work with putty. Now I can get to my Site5 repository from my local command line.

Quote:
Originally Posted by jdnorthrup View Post
the second problem is if you're on the site5 server via ssh, you use the file:/// sytax to access your repository, not the svn+ssh. if you're already there, there's no need to tunnel in!
Yes, you're right. The problem I was running into is the same as edgar, since switchtower expects to be able to use the same URL on the local and remote machines...

So now switchtower can connect to site5 and my repository, (after giving me local errors for the file:/// syntax), but when it runs the ":restart" task above, it runs it sudo, which is unnecessary, and which I don't have permissions for anyway. How can I get rid of the sudo?

Thanks for all your help!

Last edited by motorizedflowers; January 28th, 2006 at 11:20 AM.
  #11  
Old January 28th, 2006, 12:37 PM
dwlt dwlt is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 10
Quote:
Originally Posted by motorizedflowers View Post
So now switchtower can connect to site5 and my repository, (after giving me local errors for the file:/// syntax), but when it runs the ":restart" task above, it runs it sudo, which is unnecessary, and which I don't have permissions for anyway. How can I get rid of the sudo?
In deploy.rb, you can override the restart task. Here's what I have that seems to work quite well:

Code:
task :restart, :roles => :app do
  run "killall -9 dispatch.fcgi"
end
Cheers,
David
  #12  
Old January 28th, 2006, 03:47 PM
motorizedflowers motorizedflowers is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 7
David,

Thanks for that tip. Doing the "kill" gave me errors in the rake-ing (even though I think it worked), so I combined your task with jd's like so:

Code:
desc "Restart the web server. Overrides the default task for Site5 use"
task :restart, :roles => :app do
    run "#{current_path}/script/process/reaper -d 'dispatch.fcgi'"
end
And that seems to work!

Another note, in case it helps anyone...in order to make the reaper script executable, I had to issue

Code:
svn propset svn:executable ON scripts/process/*
Thanks again!
  #13  
Old January 28th, 2006, 06:08 PM
Gary King Gary King is offline
Site5 Forum Regular
Between 30 and 100 posts... been around the block a few times.
 
Join Date: Mar 2005
Posts: 37
Here is a very helpful post that I think makes the process of creating your first RoR app and deploying it, very easy: http://forums.asmallorange.com/index...75&#entry26875
  #14  
Old January 31st, 2006, 12:42 PM
anant anant is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Nov 2005
Posts: 7
When I tried reset as mentioned here I get the following message. Any ideas

executing "sudo /home/uid/apps/app/current/script/process/reaper -d
'dispatch.fcgi'"

processing command
[www.mydomain.com] executing command
[out :: www.mydomain.com] UID is not in the sudoers file. This incident
will be reported.
command finished
rake aborted!
command "sudo /home/uid/apps/itrademall/current/script/process/reaper -d 'd
ispatch.fcgi'" failed on www.mydomain.com
  #15  
Old January 31st, 2006, 12:49 PM
dwlt dwlt is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 10
Quote:
Originally Posted by anant View Post
When I tried reset as mentioned here I get the following message. Any ideas

executing "sudo /home/uid/apps/app/current/script/process/reaper -d
'dispatch.fcgi'"

processing command
[www.mydomain.com] executing command
[out :: www.mydomain.com] UID is not in the sudoers file. This incident
will be reported.
command finished
rake aborted!
command "sudo /home/uid/apps/itrademall/current/script/process/reaper -d 'd
ispatch.fcgi'" failed on www.mydomain.com
That was the same error I got with that command, so I use
Code:
killall -9 dispatch.fcgi
instead which works for me.

Cheers,
David
  #16  
Old February 3rd, 2006, 10:38 PM
Strangeglow Strangeglow is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Sep 2005
Posts: 20
I'm having problems getting the scp command to work right when copying my public key from the local machine to my site5 account.

If I enter:

% scp .ssh/id_rsa.pub username@remote_host:.ssh/

I get a "no such file or directory error" on the remote host.

Any help would be appreciated.

jw
  #17  
Old February 6th, 2006, 04:30 PM
scottnj scottnj is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Dec 2005
Posts: 16
svn:ignore *.log

I started playing with SVN for the first time this weekend and I love it.

How do you keep svn from trying to keep the log files in the repository?
I am using tortoiseSVN and RadRails.

When ever I run webrick, it updates the log files, then on my next commit, it always tries to add the development.log.

I added the property svn:ignore *.log to the log folder, but that doesn't seem to help.

Keeping log files under version control seem like a waste of space.

[Edit]
Stupid me, I just realized if I delete the log files from the repo, they will no longer be under version control.

Last edited by scottnj; February 6th, 2006 at 05:56 PM.
  #18  
Old February 7th, 2006, 10:40 AM
motorizedflowers motorizedflowers is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2006
Posts: 7
Strangeglow,

I'd try copying to the directory

/home/[username]/.ssh/

See if that works...
  #19  
Old February 8th, 2006, 02:17 PM
Strangeglow Strangeglow is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Sep 2005
Posts: 20
Quote:
I'd try copying to the directory

/home/[username]/.ssh/
I get an error that there's no such directory. If I do "ls -al", I don't see .ssh listed either. Do I need to do something special to create this directory?
  #20  
Old February 8th, 2006, 02:23 PM
Steven Byrd Steven Byrd is offline
Site5 Forum Addict
Error: User posts too much! -- Over 1,000 posts.
 
Join Date: Dec 2004
Location: Site5 Forums
Posts: 15,721
You should be able to create that directory like any other directory.
__________________
-Steven
Site5 Forum Overseer
Want the answers to the universe and everything? Check out the Site5 Wiki!
"To err is human, to forgive divine."
Closed Thread

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -4. The time now is 11:20 PM.
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.