puma / puma-dev

A tool to manage rack apps in development with puma
BSD 3-Clause "New" or "Revised" License
1.74k stars 107 forks source link

Puma-dev starts all my rails apps with the same version of ruby #187

Open gambala opened 5 years ago

gambala commented 5 years ago

For example, I have 2 projects with different ruby versions:

# foo/.ruby-version
2.4.4
# bar/.ruby-version
2.6.0

Then I start puma-dev from any folder:

> cd ~
> rvm list
=* ruby-2.4.4 [ x86_64 ]
   ruby-2.6.0 [ x86_64 ]
> puma-dev -sysbind
Puma-dev starts as usual

Then I open my foo project in the browser, and foo puma server start as usual.

But then I open my bar project in the browser, and bar puma server fails. Because of ruby version mismatching. That's what I see in console:

! Booting app 'bar' on socket /home/gambala/.puma-dev/bar/tmp/puma-dev-67426.sock
bar[67439]: Puma starting in single mode...
bar[67439]: * Version 3.12.0 (ruby 2.4.4-p296), codename: Llamas in Pajamas
bar[67439]: * Min threads: 0, max threads: 5
bar[67439]: * Environment: development
bar[67439]: ! Unable to load application: Bundler::GemNotFound: Could not find i18n-1.0.1 in any of the sources
bar[67439]: /home/gambala/.rvm/gems/ruby-2.4.4/gems/bundler-1.16.6/lib/bundler/spec_set.rb:91:in `block in materialize': Could not find i18n-1.0.1 in any of the sources (Bundler::GemNotFound)

Do you see that? Puma-dev tried to start puma server with ruby version 2.4.4, because puma-dev starts itself with that version. But I need bar puma server starts with 2.6.0 ruby version.

How can I get it work?

gambala commented 5 years ago

Any reaction? Is puma-dev no longer maintained like as pow?

mtyeh411 commented 5 years ago

any luck? this looks like an absolute deal breaker to me

h0jeZvgoxFepBQ2C commented 5 years ago

Would be great if anyone could answer this? Looks also like a dealbreaker for me.

cmetcalf-hired commented 5 years ago

Puma-dev respects the .powenv file, where you can ensure that puma is starting in the correct environment.

https://gist.github.com/mattscilipoti/25178ad883b226e995a0140914b691d8

nonrational commented 4 years ago

Can anyone reproduce in v0.13? I'm happy to look into it, but need more debugging information.

ziemekwolski commented 4 years ago

The problem seems to be with zsh and rvm path not being installed properly. I already tried to install the path correctly into .zshenv, but that does not seem to help.

The way to reproduce this problem is to install a version of ruby other than the one on current machine. IE the one in /usr/bin/ruby.

Making sure your path is something like:

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/{USER}/.rvm/gems/ruby-2.5.3/bin:/Users/{USER}/.rvm/gems/ruby-2.5.3@global/bin

If you can run, from outside of application :

rvm list

and get the following error:

Warning! PATH is not properly set up, /Users/{USERNAME}/.rvm/gems/ruby-2.5.3/bin is not at first place.
         Usually this is caused by shell initialization files. Search for PATH=... entries.
         You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
         To fix it temporarily in this shell session run: rvm use ruby-2.5.3
         To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.

you are on the right path.

I'm still trying to find a way around this problem, right now. I'm leaning towards using the .powenv file solution.

nonrational commented 4 years ago

FWIW I haven't encountered any issues using rbenv and bash. So, rvm and zsh might produce different results.

Regardless, this is is what needs to be debugged, essentially.

https://github.com/puma/puma-dev/blob/8907643a169565e11951e8ed0e425453108dcf56/dev/app.go#L254-L258

That puma has to be found in $PATH, and needs to be the correct shim to the correct ruby version. It's being run in a login shell (-l) and has os.Environ() appended to it, so I would completely expect the correct rvm environment et al to be loaded.

Can you try running this shell script and report back?

export APP_PATH_ONE=  #path of first app
export APP_PATH_TWO=  #path of second app, with a diff ruby version

for appPath in $APP_PATH_ONE $APP_PATH_TWO; do
  echo "=========== $appPath"
  $SHELL -l -i -c "exec bash -c 'cd $appPath; which puma; ruby --version'"
done

For reference, this is what I get.

=========== ~/.puma-dev/app1
/Users/norton/.rbenv/shims/puma
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
=========== ~/.puma-dev/app2
/Users/norton/.rbenv/shims/puma
ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-darwin18]
xanderificnl commented 3 years ago

Similar problem with ZSH (and ASDF) here, my .bashrc:

# -snip-
source $HOME/.asdf/asdf.sh
test -e /usr/bin/zsh && exec /usr/bin/zsh # LDAP managed user profile has $SHELL set to /bin/bash; not all machines have zsh.

And puma-dev will return:

❯ puma-dev -sysbind # setcap 
2021/06/26 01:49:45 Existing valid puma-dev CA keypair found. Assuming previously trusted.
* Directory for apps: /home/xander/.puma-dev
* Domains: test
* HTTP Server port: 80
* HTTPS Server port: 443
! Puma dev listening on http and https
! Booting app 'todos' on socket /home/xander/.puma-dev/todos/tmp/puma-dev-1067630.sock
! Killing 'todos' (1067645) - 'stdout/stderr closed'
* App 'todos' shutdown and cleaned up
! Detecting app 'todos' dying on start

What bugs me the most is that puma-dev isn't telling me what the problem is at all. I saw nothing except "stdout/stderr closed', I curled puma-dev/events which just told me "lookup_error", "dying on start" which wasn't helpful either. Even strace didn't help at all! -- Maybe that should be a feature enhancement.

@ziemekwolski put me on the right path. I temporarily disabled ZSH and it started working straight away. Mind you ruby/rails from the CLI with ZSH/ASDF work just fine.

I haven't been able to workaround this besides not using ZSH. Interestingly enough when running via systemd (as a user unit: ~/.config/systemd/user/puma-dev.service), I get the following error (via webbrowser and journal):

! Booting app 'Alfred-5b60fa1e' on socket /home/xander/.puma-dev/alfred/tmp/puma-dev-1081544.sock
Alfred-5b60fa1e[1081728]: bash: cannot set terminal process group (1081544): Inappropriate ioctl for device
Alfred-5b60fa1e[1081728]: bash: no job control in this shell

Even when creating a startup script with --norc:

#!/bin/bash --norc
source $HOME/.asdf/asdf.sh
puma-dev

it still doesn't work unless ZSH isn't being used. I suppose I'm an edge case for having to manually exec zsh due to LDAP user management.

I've got it working now by excluding this specific host from automatically executing zsh on interactive shells.

Edit: just noticed that the "bash:cannot set terminal process...." & "bash: no job control" messages also appear when puma-dev does work with only bash; so I don't think the issue with ZSH is related to that.

thomaswitt commented 2 days ago

Same Problem here, I also get

14:42:42 web.1          | test-ec2f0df9[89451]: bash: cannot set terminal process group (75284): Inappropriate ioctl for device
14:42:42 web.1          |test-ec2f0df9[89451]: bash: no job control in this shell

In all my rc and profile files I included

# If not running interactively, don't do anything
[[ $- != *i* ]] && return