This project is archived and is in readonly mode.
[rails3 beta] "rails runner" can't be used in shebang lines
-
Andreas Mayer
- Title changed from "rails runner" can't be used in shebang lines to [rails3 beta] "rails runner" can't be used in shebang lines
-
trevor
+1
this is a big issue for me as well
-
Yehuda Katz (wycats)
- Milestone cleared.
- Tag changed from rails 3.0 beta, runner to rails3, runner
- Assigned user set to Yehuda Katz (wycats)
-
Yehuda Katz (wycats)
- State changed from new to open
-
Rohit Arondekar
Yehuda, will you be working on this? There is this one more ticket #2244 script runner should overwrite $0 and I was about to write some tests, I'm guessing I should wait for changes caused by this ticket?
-
Rohit Arondekar
... because parameters don't get separated in shebang lines ...
According to this Wikipedia entry it's a portability thing. Not all systems separate the arguments :(
So building a wrapper might be the only option imho.
-
raggi
Yup, portability is a bitch with this, we have the same problem with
rackupfor cgis in rack. No ideal solution, I just recommend to people that they write a .cgi / .fcgi with a shebang directed atwhich ruby. -
raggi
Maybe add a generator that makes a script/runner?
That way it could be built by a rake task, rather than having a potentially non-working committed version?
-
Rohit Arondekar
Attached is a patch that fixes the --help output to include runner in the shebang line. Although it won't work on many systems it might still work on some as indicated here #5637 rails runner --help documentation is off
Till a wrapper is introduced I think it's a good idea to fix the help output to something that's not entirely wrong.
-
Rohit Arondekar
- Assigned user changed from Yehuda Katz (wycats) to José Valim
-
Repository
(from [76266a818449c732440e7e2ef4de8442ac6af891]) Fix output of 'rails runner --help' [#4249 [rails3 beta] "rails runner" can't be used in shebang lines state:open] http://github.com/rails/rails/commit/76266a818449c732440e7e2ef4de84...
-
Rohit Arondekar
I think the patch should be applied to 3-0-stable too so that in 3.0.1 as a bare minimum the help message will be correct, in case the wrapper isn't ready by then.
-
Santiago Pastorino
Hey Rohit which is the state of this issue?. Needs something else?
-
Rohit Arondekar
- Assigned user changed from José Valim to Rohit Arondekar
Santiago, the original issue still remains. You can't use rails runner from shell scripts (in the shebang line) on certain platforms. I'll take a look at it again as soon as I can and try to work on a patch.
-
Rohit Arondekar
I tried 3 ways of going about this —
1] Moving the
rails runnercommand code intoscript/runnerThis is easy and I think I've gotten it working 100%. But it leads to duplication i.e there is a rails runner command and the same code in script/runner. We could maybe deprecate
rails runnerand in the next to next release remove it altogether.2] Running the
rails runnercommand from withinscript/runnerusing shell scriptI don't know if I can write a general script that will work in bash, sh and other scripting environments. So I immediately stopped trying in this direction.
3] Running the
rails runnercommand from withinscript/runnerusing RubyThis looks like the most promising way and seems to work perfectly fine. I use the
railsexecutable from app/script/rails since even the rails command uses it.I can work on a patch on either option 1 or option 2. I personally suggest option 3 since it reuses the rails runner command using just a 3 line ruby script. No duplication that comes with the first method.
-
Rohit Arondekar
P.S the script for option 3 is as follows:
#!/usr/bin/env ruby path_to_rails = File.dirname(File.expand_path(__FILE__)) exec("#{path_to_rails}/rails runner #{ARGV[0]}")You can just drop it in
your_rails_app/script/runner—chmod +xthe file and use it in place of rails runner. -
Rohit Arondekar
I'm actually trying to find somebody who uses the runner as shebang lines in their scripts and I honestly can't find one person. If anybody following this ticket does use runner that way, could you give some feedback on the above wrapper approach? I don't know if there are any limitations of doing it that way.
-
Rohit Arondekar
I'm going to just attach the patch which creates a wrapper for rails runner — basically the script just executes rails runner command.
-
Andreas Mayer
@Rohit: I did, and why shouldn't I? It is a documented feature and I didn't even have the idea that I couldn't run a Ruby script from crontab with a single command (so, using the shebang line).
Of course, if it's documented that this doesn't work, it's also OK. I just want to be able to call method from my Rails project from crontab with one command.
-
Rohit Arondekar
Andreas, could you give some feedback on the above patch? Does that do what you want? I'm sorry but I'm unsure about things as I myself don't use the rails runner. If the patch isn't satisfactory could you please work on one?
-
Andreas Mayer
@Rohit: Thank you. As far as I see, this should work, but I haven't tested yet.
-
Rohit Arondekar
Andreas, please do test it. I'm finding it hard to find more people who can take a look at it actually. So if you know anybody else who might have an opinion please do direct them here! Thanks :)
-
José Valim
Please remove the help message from the script/rails runner output. I think it is easier for people to roll their own script then having a script/runner in rails mostly because using script/runner directly wouldn't work as you need to call bundle exec script/runner.
