1

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?

2

3 Answers 3

1
+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.

0

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.

-1

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.

1
  • This sounds like more of a comment Nov 9, 2013 at 14:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .