Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I don't really have any need to mess with passenger or capistrano at the moment. I simply want to run rails on boot on port 3000. I've attempted to replicate this tutorial for node as much as I could to run rails:

I've a railsup script in /etc/init.d/ that goes something like:

#!/bin/sh
export PATH=$PATH:/usr/local/bin

case "$1" in
  start)
   cd /root/rails_app; /usr/local/rvm/gems/ruby-2.0.0-p247/bin/rails server -d -p 3005
  ;;
  # starting other stuff
*)

I've also included it with update-rc.d

I got it to work, but only if I run the script manually - it doesn't seem to run on boot. Is there any reason why ../bin/rails is unavailable on boot?

I imagine there's something about ruby path \ rvm \ rails that I'm unaware of? Is there a way to use crontab's @reboot for this?

share|improve this question
    
    
What's answer of update-rc.d when you run the command? –  F. Hauri Nov 9 '13 at 15:29
add comment

3 Answers

up vote 1 down vote accepted
+100

Using init.d

Whith new System-V parallelisation system, you have to add a INIT INFO part at top of your script.

Have a look at /etc/init.d/README and try to add this at top of your script:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          rails
# Required-Start:    $local_fs $remote_fs
# Required-Stop:
# X-Start-Before:    rmnologin
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Start Rails on port 3000
### END INIT INFO

Using cron (and run as your own user)

You could run your daemon on each reboot with specific cron syntax:

crontab -l |
   sed '$a@reboot /usr/bin/rail-or-other-bin -arg1 -arg2 -port 3000' |
   crontab

Warning running this command (crontab with no argument and stdin from pipe) will alter your crontab! See man crontab!

... and try this without the last crontab before:

crontab -l |
   sed '$a@reboot /usr/bin/rail-or-other-bin -arg1 -arg2 -port 3000'

The advantage of this is that daemon is run in userland and run errors will be sent to you as mail by normal cron way.

share|improve this answer
add comment

Is the script running at all? I'd try adding:

echo RAILSUP >/tmp/railsup.log

If it really is, have you checked the logs to see what the error is while trying to run on boot? Personally, I'd run that under strace and log all actions to a file to examine once you can log in. It will probably provide some clue.

share|improve this answer
add comment

it really is, have you checked the logs to see what the error is while trying to run on boot? Personally, I'd run that under strace and log all actions to a file to examine once you can log in. It will probably provide some clue.

share|improve this answer
    
This sounds like more of a comment –  Drew Khoury Nov 9 '13 at 14:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.