Rvm and Thin, Root Vs. Local User

RVM and thin, root vs. local user

RVM comes with a handy wrapper generator that creates an intermediary loader for an init.d script. This allows you to load a service using a particular Ruby version and gemset. I use it like this (after installing the thin gem):

1 - create init.d entry for thin

sudo thin install 

2 - set up some defaults

sudo /usr/sbin/update-rc.d -f thin defaults 

3 - generate boot config for your rails app

sudo thin config -C /etc/thin/<appname>.yml -c /var/rails/<appdir> --servers 4 -e production

4 - generate rvm wrapper script

rvm wrapper <rubyversion>@<gemset> bootup thin

5 - If you're using a global gemset, you can just use

rvm wrapper ruby-1.9.2-p125 bootup thin

6 - edit thin init

sudo nano /etc/init.d/thin

7 - change the original loader

DAEMON=/usr/local/rvm/gems/ruby-<rubyversion>-<rubyrevision>@<gemset>/bin/thin

8 - to point to the rvm wrapper instead

DAEMON=/usr/local/bin/bootup_thin

9 - start it up

sudo service thin start

If you're running more than one app, just generate a boot config yml file for each one; when booting thin all yml files in /etc/thin/ are parsed. More info here:

http://wiki.rubyonrails.org/deployment/nginx-thin?rev=1233246014 nb: This is linking to a revision, the most current version has been edited to be empty. Consider looking at the link without the ?rev=... in the url, the current version may be back and potentially more up to date.

HTH

2013 BONUS EDIT

While I no longer use RVM in production, thin is still my production server of choice, and I still use steps 1-3 above to get started. But the default configuration it generates can do with a few tweaks, here are some of mine:

Set the user & group that thin runs as:

user: www-data
group: www-data

Remove the port config and switch to using sockets instead (a little faster):

# port: 3000
socket: tmp/sockets/<appname>.sock

Tell thin to restart instances one by one, instead of shutting them all down before starting up again (rolling restart):

onebyone: true

Give the server processes a "tag" to help identify them (in ps aux etc):

tag: <appname>

How to use rvm (ruby version manager) with root account?

I found the solution:

rvmsudo does the trick.

Should I have installed RVM as multi-user?

Preface: I'm not a current passenger user. So following stuff are only thoughts and memories.

Firstly: If I remember correctly than only the main process of nginx runs definitly as root, but the child processes runs under user/group ID which you can set up in the nginx config. (And you should do this if you care for security!)

Don't know if this affect the passenger mod - would say, it should, because the main process is only for spanning up the worker processes which will do the real job. Also can't say, if the helper process for passenger runs with same user rights than the worker. (It should, for same reason like in first paragraph.)

There is a passenger_default_user setting you should use in nginx. It should avoid your user troubles.

Secondly try the tips under https://rvm.beginrescueend.com/integration/passenger/

They might be helpful especially in case of user installs of RVM.

Please read the parts Notes, Troubleshooting and FAQ carefully!

And my third point: I would prefer a system install of RVM on the production system. So you have the possibility to build different setups for different (system/service) users without having troubles of user scopes.

Last but not least: I haven't made so good experiences with a RVM-passenger-nginx setup in past. Also I'm not a friend of overloaded webservers/loadbalancers and so would never use the nginx passenger module any more. Keep out stuff which doesn't belong to it.

Alos keep in mind that the passenger-nginx mod kills the capability to use different rubies and ruby versions with nginx+passenger. Would say in this cases it makes less sense to use RVM. I prefer to use nginx as proxy only and let do the webserver job by unicorn/thin/whatever-else.

Conclusion

I would say, it's not a problem with the root user. I think, something in your setup is missing or misconfigured.

To answer your last questions: No, I think it's not necessary to install a system rvm and yes, it should be possible to run passenger in nginx with correct (user) rvm.

Create RVM installation on single user that is in sudo group

If you want to start from scratch you can use:

rvm implode
sudo rvm implode

implode - (seppuku) removes the rvm installation completely.
This means everything in $rvm_path (~/.rvm || /usr/local/rvm).
This does not touch your profiles. However, this means that you
must manually clean up your profiles and remove the lines which s

How to make upstart work gracefully with RVM?

RVM is really more for personal use. For a system service, I would just install the version of Ruby you want (someplace that doesn't conflict with the system version, like /usr/local/) and use Bundler in deployment mode to get the gemset.

Monit + RVM + Thin on OSX / Linux

monit clears out the environment and also doesn't run a shell for your command (let alone an interactive one). I find I have to do something like:

/usr/bin/bash -c 'export rvm_path=/home/foo/.rvm; . $rvm_path/scripts/rvm; cd my_ruby_app_path; $rvm_path/bin/rvm rvmrc load; ./my_ruby_app'

as the monit start command.

Can't start service with sudo since root user has no access to Ruby

It sounds like su isn't spawning a shell that reads the profile files that normally setup the rvm environment.

I'd try changing the command you run to

 source "/home/dtuite/.rvm/scripts/rvm" && $APP_ROOT/bin/unicorn...


Related Topics



Leave a reply



Submit