Switchtower (0.10.0), ssh and environment confusion

Seems like my day for Rails posts… :slight_smile:

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 [email protected] 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

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

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:inrequire’
[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! :slight_smile:

-Brian

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