# Switchtower Port Issues

**URL:** <https://www.ruby-forum.com/t/switchtower-port-issues/97695>\
**Category:** Rails\
**Created:** [January 26, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695 "2006-01-26T17:51:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 26, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695/1 "2006-01-26T17:51:45Z")

</div>

Hi there,

I’m having some difficulties finding some decent info on getting  
Switchtower to function for my needs. I’ve read most of the  
Switchtower doc on [Peak Obsession](http://manuals.rubyonrails.com/read/chapter/97),  
however it’s not answering some potent questions I have.

1. The doc mentions, as an example, using an SVN repos at  
[http://svn.switchtower.com/flipper/trunk](http://svn.switchtower.com/flipper/trunk)  
What if I only access my SVN repos through SSH? When you set the  
repository in the deploy.rb file what do you put for this line?

set :repository, “[http://svn.switchtower.com/flipper/trunk](http://svn.switchtower.com/flipper/trunk)”

I would ‘normally’ access my repository like this:  
svn co svn+ssh://USERNAME@11.22.33.44/home/svn/repos/app app

1. The second question I have is when dealing with defining the roles  
in the deploy.rb file. I run all my development on non-standard ports  
(because my ISP blocks the standard ports… grrr!). The example they  
used was the following:

role :app, “[simple.switchtower.com](http://simple.switchtower.com)”  
role :web, “[simple.switchtower.com](http://simple.switchtower.com)”  
role :db, “[simple.switchtower.com](http://simple.switchtower.com)”

I have yet to experiment because of trying to figure out question 1’s  
issues. But, once I get that working, would the following work if all  
of them were running on port 45000 as an example?

role :app, “[simple.switchtower.com:45000](http://simple.switchtower.com:45000)”  
role :web, “[simple.switchtower.com:45000](http://simple.switchtower.com:45000)”  
role :db, “[simple.switchtower.com:45000](http://simple.switchtower.com:45000)”

1. I’m using Lighttpd currently as my server. Am I going to have to  
get Apache working so I can use Switchtower?

Sorry for all the noobie questions!

Thanks!  
Dave H.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 26, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695/2 "2006-01-26T18:00:48Z")

</div>

On Jan 26, 2006, at 9:47 AM, Dave H. wrote:

> repository in the deploy.rb file what do you put for this line?
> 
> set :repository, “[http://svn.switchtower.com/flipper/trunk](http://svn.switchtower.com/flipper/trunk)”
> 
> I would ‘normally’ access my repository like this:  
> svn co svn+ssh://USERNAME@11.22.33.44/home/svn/repos/app app

You would put the “svn+ssh://…” text in the :repository variable,  
in this case. Basically, whatever the address of your repository,  
that’s what you put there. (Note, however, that ST won’t work with  
file:// repositories–the repo has to be accessible both from the  
local host and the remote host.)

> issues. But, once I get that working, would the following work if all  
> of them were running on port 45000 as an example?
> 
> role :app, “[simple.switchtower.com:45000](http://simple.switchtower.com:45000)”  
> role :web, “[simple.switchtower.com:45000](http://simple.switchtower.com:45000)”  
> role :db, “[simple.switchtower.com:45000](http://simple.switchtower.com:45000)”

What do you mean, “running”? The app names here are only used as  
targets for SSH, so as long as SSH is running on the default port  
(22), you should be fine. If it isn’t, you can specify the ssh port  
via the ssh\_options hash:

ssh\_options[:port] = 45000

> 1. I’m using Lighttpd currently as my server. Am I going to have to  
> get Apache working so I can use Switchtower?

Nope, lighttpd works ok as long as you don’t have to restart it via  
switchtower. (For some reason no one has yet determined, if you try  
to restart lighttpd via switchtower, lighttpd shuts down just fine  
but never starts up again.) If you use externally spawned fastcgi  
listeners (as described in the third chapter of the ST manual, I  
believe) you should be just fine.

> Sorry for all the noobie questions!

No worries! ST documentation has a ways to go, yet.

- Jamis

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 26, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695/3 "2006-01-26T18:06:49Z")

</div>

On Jan 26, 2006, at 11:59 AM, Jamis B. wrote:

> > [http://svn.switchtower.com/flipper/trunk](http://svn.switchtower.com/flipper/trunk)  
> > repository, that’s what you put there. (Note, however, that ST  
> > role :db, “[simple.switchtower.com](http://simple.switchtower.com)”  
> > targets for SSH, so as long as SSH is running on the default port  
> > to restart lighttpd via switchtower, lighttpd shuts down just fine  
> > but never starts up again.) If you use externally spawned fastcgi  
> > listeners (as described in the third chapter of the ST manual, I  
> > believe) you should be just fine.

I noticed that it seems to start every other time that the restart  
task is run (when a lighttpd restart was included in the task). I  
changed my deploy.rb around, and now it starts reliably. Here are the  
tasks that I added:

desc “Restart lighty”  
task :before\_restart, :roles =\> :app do  
run “kill -9 `cat /home/#{user}/var/run/lighttpd.pid`”  
end

desc “Restart lighty”  
task :after\_restart, :roles =\> :app do  
run “/usr/local/sbin/lighttpd -f /home/#{user}/web/lighttpd/config/  
lighttpd.conf”  
end

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 26, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695/4 "2006-01-26T18:27:57Z")

</div>

Perhaps the problem is lighttpd shutting down slowly,  
so when the start happens, the .pid file is still  
around.

Perhaps just a sleep between stop and start, or a  
loop to wait for the .pid file to go away?

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 26, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695/5 "2006-01-26T18:24:56Z")

</div>

On Jan 26, 2006, at 10:05 AM, Joseph H. wrote:

> desc “Restart lighty”  
> task :after\_restart, :roles =\> :app do  
> run “/usr/local/sbin/lighttpd -f /home/#{user}/web/lighttpd/  
> config/lighttpd.conf”  
> end

Fascinating! Thanks for this work-around, Joseph. I’m anxious to try  
it out and see if it works for me. I’m still mystified as to why this  
works, and the other doesn’t… Very odd.

- Jamis

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 26, 2006, 6:43pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695/6 "2006-01-26T18:43:06Z")

</div>

On Jan 26, 2006, at 10:27 AM, Tom M. wrote:

> Perhaps the problem is lighttpd shutting down slowly,  
> so when the start happens, the .pid file is still  
> around.
> 
> Perhaps just a sleep between stop and start, or a  
> loop to wait for the .pid file to go away?

That’s what I thought, too, but even a 10s sleep doesn’t seem to  
help. I haven’t try looping to wait for the pid file to disappear,  
though. Has anyone else tried that?

- Jamis

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 26, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695/7 "2006-01-26T18:55:13Z")

</div>

Jamis,

Thanks for the info. That helped a lot actually!

I was actually excited to see this error pop up:

rake deploy  
(in /Users/dhoefler/RubyProjects/rlog)  
loading configuration  
/usr/lib/ruby/gems/1.8/gems/switchtower-0.10.0/lib/switchtower/recipes/standard.rb  
loading configuration ./config/deploy.rb  
executing task deploy  
transaction: start  
executing task update\_code  
querying latest revision…  
ssh: connect to host 12.123.12.12 port 22: Connection refused  
svn: Connection closed unexpectedly  
ssh: connect to host 12.123.12.12 port 22: Connection refused  
svn: Connection closed unexpectedly  
ssh: connect to host 12.123.12.12 port 22: Connection refused  
svn: Connection closed unexpectedly  
ssh: connect to host 12.123.12.12 port 22: Connection refused  
svn: Connection closed unexpectedly  
ssh: connect to host 12.123.12.12 port 22: Connection refused  
svn: Connection closed unexpectedly  
svn: ‘.’ is not a working copy  
svn: ‘.’ is not a working copy  
(proceed to an endless loop of the previous line)

If it matters, I’m trying to connect to my Ubuntu box. I did change  
the port option in the config deploy to:

ssh\_options[:port] = 43022

This is odd though, I can SSH in just fine using an alternate port  
(ssh -p 43022 12.123.12.12) . I think there’s something I’m forgetting  
to set up with SVN.

Hmm…

-Dave

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 26, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/switchtower-port-issues/97695/8 "2006-01-26T20:10:34Z")

</div>

On Jan 26, 2006, at 9:22 AM, Jamis B. wrote:

> > end
> 
> - Jamis

```
Please note that if you do it this way that you will eventually end

```

up leaving zombie fcgi dispatchers laying around taking up memory.  
You need to also kill the dispatchers with kill -9 before you restart  
lighty. Of course if you are using stand alone dispatchers then the  
reaper will work to restart those.

```
Here are my tasks for restarting lighty _and_ the dispatchers. This

```

works for me every time with switchtower.

desc “Restart lighty”  
task :before\_restart, :roles =\> :app do  
pid\_of\_lighty = `ps axww | grep lighttpd | grep -v grep | grep myapp.lighttpd.conf`  
pids\_of\_dispatchers = `ps axww | grep dispatch.fcgi | grep -v grep | grep /yhr/public/dispatch.fcgi`  
lighty = pid\_of\_lighty.scan(/\d\*/).first  
dispatchers = pids\_of\_dispatchers.split(/\n/).map {|line| line.scan  
(/\d\*/).first }  
run “kill -9 #{lighty} #{dispatchers.join(’ ')}”  
end

desc “Restart lighty”  
task :after\_restart, :roles =\> :app do  
run “/usr/local/sbin/lighttpd -f /etc/myapp.lighttpd.conf”  
end

```
Note that you need to replace the last grep's in each of the first

```

ps commands to match something unique to your specific lighty and  
rails app if you are running more then one lighty on the server so  
that it only affects the lighty and dispatchers for that particular  
rails app.

Cheers-

-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid
