How do I use shellscripts for rails with 'screen'?

1

1

I've recently started Ruby on Rails development, and I'm using Vagrant as a VM to contain my Rails project, because Windows is a terrible OS to use for any sort of Ruby development, due to the seemingly random lack of support for various RubyGems.

My question is this: I want to use a shellscript to launch the various three commands in separate DETACHED screen sessions, with respective names:

"rails" ==>  'rails s'
"mail"  ==>  'mailcatcher --http-ip 0.0.0.0'
"guard" ==>  'bundle exec guard --force-polling'

I tried using the following, and it didn't seem to work (startup.sh)

screen -S rails -d -m rails s
screen -S mail -d -m mailcatcher --http-ip 0.0.0.0
screen -S guard -d -m bundle exec guard --force-polling

To no avail, it doesn't seem to do what I want it to do, and I don't know if I am doing something wrong, or invoking screen incorrectly. Can someone shed some light on this situation? As for the OS, it's Ubuntu 12.04 LTS (Precise) x86, as a virtual machine (though the VM part shouldn't matter, I guess.)

Thanks ahead of time for any suggestions. I sort of just wanted a way to use a shellscript to fire up my rails project (and related services) at one time instead of having to manually start up screen sessions every time I brought up my vagrant box.

My other thought was to maybe figure out how to set these commands to run at system startup, using cron or something?

MisutoWolf

Posted 2013-11-16T16:01:39.227

Reputation: 113

Answers

2

You may wish to try the screen command as

 screen -d -m -S screen_name command 

The -S option simply speicifies inside which screen window the following command will be executed. As per -d -m the man page recites:

 -d -m   Start screen in "detached" mode. This creates a new session but
       doesn't  attach  to  it.  This  is  useful  for  system startup
       scripts. 

MariusMatutiae

Posted 2013-11-16T16:01:39.227

Reputation: 41 321

So, for example:

screen -d -m -S rails rails s? – MisutoWolf – 2013-11-16T19:04:38.780