Can't start thin server as service, RubyGems: Could not find thin
Asked Answered
G

2

5

I used the following instructions to install and configure the Thin server as a service on Ubuntu 10.04.4 with Rails 3.2.3:

http://articles.slicehost.com/2008/5/6/ubuntu-hardy-thin-web-server-for-ruby

Thin server works fine running it from the application root, using 'thin start'

However, when I try to run the service using any of these commands:

service thin start
sudo service thin start
/etc/init.d/thin start
sudo /etc/init.d/thin start

I get the following error:

/home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find thin (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)
    from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
    from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
    from /home/myuser/.rvm/gems/ruby-1.9.3-p125/bin/thin:18:in `<main>'

This does not seem to be an issue with PATH, 'which thin' correctly returns:

home/myuser/.rvm/gems/ruby-1.9.3-p125/bin/thin

I have also verified the existence of **/bin/thin wherever it's referenced

I have tried reinstalling the gem using 'gem uninstall thin', 'gem install thin' without success

Has anyone experienced this before? I only found one other instance of this problem: Cannot restart thin via remote machine

That issue seems to have been only over ssh, while I can't even get the thin service started locally

Thanks

Gstring answered 30/4, 2012 at 20:19 Comment(2)
The guide you are following is for old version of ubuntu, 10.04 has has changed the way init scripts work. Besides, Why do you want to run thin using /etc/init.d? instead of thin -d?Cost
Trying to get it to run as a service at startup, should I make an sh file that runs thin -d and put it somewhere to run at startup?Gstring
C
2

It seems that each startup job is loaded its own shell. so, Try loading rvm before trying to start thin:

#! /bin/sh
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then

  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"

elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then

  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"

else

  printf "ERROR: An RVM installation was not found.\n"

fi

rvm use 1.9.3
cd /path/to/your/application/code
bundle exec thin -d

place this in /etc/init.d/thin_service & run

$ sudo update-rc.d  thin_service defaults

Lastly, you can test by by simply typing sudo start thin_service & sudo stop start_thin instead of rebooting. If this still doesn't work, try railsgems-bundler and rvm wrapper. Also, do read rvm's Deployment Best Practices

Cost answered 30/4, 2012 at 22:31 Comment(0)
T
5

Since its seems from your stacktrace you are using rvm, and you are using thin installed as a gem, you need to use rvm wrappers for the service to work. First remove the service end re-install it rvmsudo thin install instead of sudo thin install. You should also use rvmsudo thin config while creating the configuration file as well.

To createa a wrapper,

rvm wrapper <your_rvm_ruby_version>@<your_rvm_gemset_in_use> bootup thin

you can find the names by using rvm list and rvm gemset list respectively. The wrapper will have name bootup_thin which you can confirm it is using the right rvm by which bootup_thin. You can give it whatever name you want while creating it. Then you need to edit thin script by

sudo nano /etc/init.d/thin

Change the original DAEMON to

DAEMON=location_of_bootup_thin 

Which should be the result of which bootup_thin. Then you can start the service.

sudo service thin start

I hope this helps

Timecard answered 1/5, 2012 at 14:16 Comment(0)
C
2

It seems that each startup job is loaded its own shell. so, Try loading rvm before trying to start thin:

#! /bin/sh
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then

  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"

elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then

  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"

else

  printf "ERROR: An RVM installation was not found.\n"

fi

rvm use 1.9.3
cd /path/to/your/application/code
bundle exec thin -d

place this in /etc/init.d/thin_service & run

$ sudo update-rc.d  thin_service defaults

Lastly, you can test by by simply typing sudo start thin_service & sudo stop start_thin instead of rebooting. If this still doesn't work, try railsgems-bundler and rvm wrapper. Also, do read rvm's Deployment Best Practices

Cost answered 30/4, 2012 at 22:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.