# Switchtower (0.10.0), ssh and environment confusion

**URL:** <https://www.ruby-forum.com/t/switchtower-0-10-0-ssh-and-environment-confusion/53947>\
**Category:** Rails\
**Created:** [February 17, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/switchtower-0-10-0-ssh-and-environment-confusion/53947 "2006-02-17T21:27:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_VSHughes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@Brian\_VSHughes](https://www.ruby-forum.com/u/Brian_VSHughes)\
**Post date:** [February 17, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/switchtower-0-10-0-ssh-and-environment-confusion/53947/1 "2006-02-17T21:27:16Z")

</div>

Seems like my day for Rails posts… 🙂

OK. I’ve started using Swtichtower to help with deploying changes to my  
production rails apps. Unfortunately I’ve come accros an inconsistency  
that I  
can’t quite figure out. It’s about the PATH env var under Bash. I’ve  
created a  
task that just does a: run “env”, to show what I’m seeing:

loading configuration ./config/deploy.rb  
executing task show\_env  
executing “env”  
servers: [“foo.dartmouth.edu”]  
processing command  
[foo.dartmouth.edu] executing command  
[out :: foo.dartmouth.edu] TERM=xterm  
[out :: foo.dartmouth.edu] SHELL=/bin/bash  
[out :: foo.dartmouth.edu] SSH\_CLIENT=x.x.x.x 55394 22  
[out :: foo.dartmouth.edu] SSH\_TTY=/dev/ttyp0  
[out :: foo.dartmouth.edu] USER=brianvh  
[out :: foo.dartmouth.edu] MAIL=/var/mail/brianvh  
[out :: foo.dartmouth.edu] PATH=/usr/bin:/bin:/usr/sbin:/sbin  
[out :: foo.dartmouth.edu] PWD=/Users/brianvh  
[out :: foo.dartmouth.edu] SHLVL=1  
[out :: foo.dartmouth.edu] HOME=/Users/brianvh  
[out :: foo.dartmouth.edu] LOGNAME=brianvh  
[out :: foo.dartmouth.edu] SSH\_CONNECTION=x.x.x.x 55394 y.y.y.y 22  
[out :: foo.dartmouth.edu] \_=/usr/bin/env  
command finished

However, if I run what I assumed was the same command, from my OS X  
terminal:

ssh removed\_email\_address@domain.invalid env

The output is different:

SHELL=/bin/bash  
SSH\_CLIENT=x.x.x.x 55395 22  
NAME=Brian V. Hughes  
USER=brianvh  
MAIL=/var/mail/brianvh  
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin  
PWD=/Users/brianvh  
EDITOR=emacs  
SHLVL=1  
HOME=/Users/brianvh  
LOGNAME=brianvh  
SSH\_CONNECTION=x.x.x.x 55395 y.y.y.y 22  
\_=/usr/bin/env

So, clearly, Switchtower is executing the env command in a different  
context  
than my ssh command line client. Unfortunately, I’m not savvy enough  
with Ruby  
to fully dissect the Swtichtower module, or the Net::SSH module.

Can someone tell me what I’m missing? Or, better still, tell me how I  
can get  
Switchtower SSH commands to load a different PATH env variable? The  
reason this  
is a problem is because the call to reaper, at the end of a rake deploy,  
is  
failing because PATH doesn’t contain “/usr/local/bin”.

-Brian

---

<div class="post-metadata">

**Author:** ![Brian\_VSHughes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@Brian\_VSHughes](https://www.ruby-forum.com/u/Brian_VSHughes)\
**Post date:** [February 18, 2006, 4:33am UTC](https://www.ruby-forum.com/t/switchtower-0-10-0-ssh-and-environment-confusion/53947/2 "2006-02-18T04:33:01Z")

</div>

Brian,

ST commands are not executed within a login shell, which means  
your .bashrc and such are not loaded. If your target sshd is  
configured to support it (PermitUserEnvironment is “yes”), you can  
specify things like PATH in ~/.ssh/environment, but that setting is  
typically “no” by default (for security reasons).

I’m not sure why the reap command would be failing for you due to a  
path issue–the default restart task uses the full path to the  
reaper. Are you sure that is the problem? Can you paste the specific  
error you are getting?

- Jamis

---

<div class="post-metadata">

**Author:** ![Brian\_VSHughes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@Brian\_VSHughes](https://www.ruby-forum.com/u/Brian_VSHughes)\
**Post date:** [February 18, 2006, 4:48am UTC](https://www.ruby-forum.com/t/switchtower-0-10-0-ssh-and-environment-confusion/53947/3 "2006-02-18T04:48:26Z")

</div>

Jamis B. wrote:

> Brian,
> 
> ST commands are not executed within a login shell, which means your  
> .bashrc and such are not loaded. If your target sshd is configured to  
> support it (PermitUserEnvironment is “yes”), you can specify things like  
> PATH in ~/.ssh/environment, but that setting is typically “no” by  
> default (for security reasons).

OK… I guess I understand that. I’ll look into the  
PermitUserEnvironment  
setting, if that’s what I need to change.

> I’m not sure why the reap command would be failing for you due to a path  
> issue–the default restart task uses the full path to the reaper. Are  
> you sure that is the problem? Can you paste the specific error you are  
> getting?

executing task restart  
executing  
“/Library/WebServer/Rails/myRailsApp/current/script/process/reaper”  
servers: [“foo.dartmouth.edu”]  
processing command  
[foo.dartmouth.edu] executing command  
[out :: foo.dartmouth.edu]  
/Library/WebServer/Rails/myRailsApp/current/script/process/…/…/config/boot.rb:15:in  
`require': No such file to load -- rubygems (LoadError) [out :: foo.dartmouth.edu] from /Library/WebServer/Rails/myRailsApp/current/script/process/../../config/boot.rb:15 [out :: foo.dartmouth.edu] from /Library/WebServer/Rails/myRailsApp/current/script/process/reaper:2:in`require’  
[out :: foo.dartmouth.edu] from  
/Library/WebServer/Rails/myRailsApp/current/script/process/reaper:2  
command finished  
rake aborted!  
command  
“/Library/WebServer/Rails/myRailsApp/current/script/process/reaper”  
failed on foo.dartmouth.edu

I was getting this exact same error from the command line, when I  
switched to  
Bash as my shell, because it looks like ST requires it. But the error  
went away  
as soon as I pre-pended /usr/local/bin onto my PATH env. If there’s  
another way  
to get this to run, as my user, not under sudo, I’m all for it! 🙂

-Brian

---

<div class="post-metadata">

**Author:** ![Brian\_VSHughes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@Brian\_VSHughes](https://www.ruby-forum.com/u/Brian_VSHughes)\
**Post date:** [February 18, 2006, 7:10am UTC](https://www.ruby-forum.com/t/switchtower-0-10-0-ssh-and-environment-confusion/53947/4 "2006-02-18T07:10:40Z")

</div>

On Feb 17, 2006, at 8:44 PM, Brian V. Hughes wrote:

> [foo.dartmouth.edu] executing command  
> [out :: foo.dartmouth.edu] /Library/WebServer/Rails/myRailsApp/  
> current/script/process/…/…/config/boot.rb:15:in `require’: No  
> such file to load – rubygems (LoadError)

(Above) That’s the problem, there. There’s no rubygems installed for  
the ruby interpreter that is running the reaper.

My guess is that you’ve installed ruby in /usr/local/bin, and left  
the stock OSX one in /usr/bin. My recommendation is to symlink the /  
usr/bin/ruby to /usr/local/bin/ruby.

- Jamis
