Ruby server-side back end scripting tools/resources - ruby

I am trying to learn how ruby is used in a server based back end environment. For example I want to be running a ruby script 24/7 on a server. What are the best practices for this and how does one go about doing this?
Can anyone provide some resources on how to do this or if you could label what I am trying to do? I am unsure of the terms that I am supposed to be googling.

Use cron. From OS point of view Ruby app is just a script like bash.
Also all Unix OSes have some kind of daemon script (like see examples in /etc/init.d)

Try BackgroundRb - this is a special Rails plugin that works like a Linux daemon. You could use any classes/models defined in your Rails application within the background code. You could also pass data to/from background process.

Related

Ruby Script to Runnable File

I'm a programming newb trying to send a Ruby script/mini-game thing to his teacher that can be ran by doubleclick. JRuby seems like a possible solution, as does Warbler, but I can't seem to figure either of those out. It doesn't have to be a specific filetype if it can be run without the terminal, just by clicking on it. Another possible solution is creating a shell script that runs the file as shown here, but I think that only works if you tell the computer running the script that it can be doubleclicked. It may even be possible to run by doing something in the Ruby file itself, but I am too inexperienced to know.
Thanks in advance for your answers!
When you say that only works if you tell the computer running the script that it can be doubleclicked, that isn't entirely true. If you email the file by itself, it might have its permissions removed, but if you package it up into a zip, then you're teacher shouldn't need to run chmod again.
Anyway, I'm not sure about the windows support for this approach (Ruby programmers tend to use Unix systems like OSX or Linux).
To make a cross platform executable, take a look at this question, which links to some packages such as "Ruby Ship"

Ruby (not Rails) on IIS 7 via FastCGI

Hopefully this is a simple one. I want to run Ruby on IIS 7+ as I would PHP, Perl, Python, etc. (that is to set a handler mapping to .rb files).
Every time I Google for it I get Rails. But I don't want to run Rails, I would just like to run straight Ruby.
I know I'll to set up my headers and all sorts of other stuff, since, unlike PHP, Ruby isn't technically native to the web.
I'm looking for a manual installation for this, not something automated with an executable.
My reason for needing this is simply for learning.
Any answers would be very helpful! Thanks!

Can I use interactive command line for Squeak/Pharo development?

I tried to install Squeak/Pharo into Ubuntu server machine.
./squeak -vm-display-null ./Pharo-1.2.2-12353/Pharo-1.2.image
It executed, but there was no command-line. No way to use without GUI?
Have a look at Coral, it provides a scripting interface to Pharo. Not sure where to find up-to-date documentation, but there is a build on the Pharo Build Server.
You can send scripts by parameter to the VM.
./squeak -vm-display-null ./Pharo-1.2.2-12353/Pharo-1.2.image myScript.st
But that's all you can do apart from Coral. Otherwise you should use GNUSmalltalk
I believe in the current VM you have to use a full "file:///" URL, a choice made a while back and only recently having been discussed as wanting to be reversed.
I am not sure if I understand your needs correctly, but I guess you could write a few liner read-eval loop, and pass it as script argument at start up.
Other than that most headless usages of smalltalk are for web servers (seaside, aida), in which case there is usually an admin url which lets you to poke around image by sending messages to objects and similar. If you have seaside one click image you could try out:
http://localhost:8080/tools/classbrowser
http://localhost:8080/tools/screenshot
http://localhost:8080/tools/versionuploader
to give you a taste of what can be done.
There is Coral, but you might also look into a lighter version of Pharo called "Pharo Kernel":
Pharo Kernel is a small Smalltalk kernel that is stripped down from Pharo Core image. Meanwhile there is also a 3MB Pharo-Kernel-Gofer image available that has networking support and Gofer (a pharo installer to load packages) installed.
Check it out at https://ci.inria.fr/pharo-contribution/view/Pharo-Kernel-2.0/job/PharoKernel2.0/

How to invoke watir scripts from a web application?

I have a watir script ,that i have to run from a web interface, on the same browser invoking the scripts. Is it possible?
This isn't possible to do, as a browser doesn't understand what ruby is.
I believe that it is possible. I've been intending to begin a similar project to what adithi wanted to do at some point, using PHP. From PHP, you can use the shell_exec command or backtick operator to execute commands in the shell. The ruby returns output using puts, which can be read by the PHP.
http://chipmunkninja.com/Program-Execution-in-PHP%3A-exec-m# seems to be a good page detailing this technique.

Ruby as a scripting language for web server

Is it possible to use Ruby as a scripting language with a HTTP server ? I'd like to be able to simply put some Ruby files in a web directory and be able to execute them from my browser - just like I did with PHP.
I have absolutely nothing against frameworks such as RoR, but I was told that I should first learn Ruby and only then move on with higher level frameworks. Of course, I could write some Ruby scripts and run them in the console, but I would prefer getting the input/output from my browser :)
Is that possible at all ? Otherwise, how hard would it be for me to build a quick and simple web framework ?
Take a look at Sinatra - not your plain ol' CGI/PHP style, but really really simple web framework to get started with, elegant so it won't get in your way while learning Ruby, and powerful enough to make quite useful web apps.
ERB is similar in spirit to PHP (in the sense you need).
You need to setup apache to parse rhtml files with erb, here is a guide for OSX.
Depends on your server, but any language can be used with CGI Programming, including Ruby.
Generally speaking - to find out - put a basic "Hello World" .rb or .cgi file on your web server and chmod it's permissions so it is executable to "others":
chmod 755 YourScript.rb
When writing CGI scripts, you have to ensure that you have the appropriate shebang at the top of your file. For Ruby you'd probably use something like...
#!/usre/bin/ruby
(no promises this is the one)
Then write yourself a little hello world CGI script. The output of a CGI script is kind of a partial HTTP Response: (I'm not really a Ruby coder so this might be completely arse-backwards)
puts "Content-Type:text/plain\n"
puts "Content-Length:12\n"
puts "\n"
puts "Hello World!"
Visit the file the same way you would a PHP or Perl script and you'll see if it works. Again; it depends on your server.
You can do that configuring your server for CGI.
You can even write web applications with assembler if you want to, using CGI.
(In the dawn of time, they used C/C++ to write web applications, go figure).

Resources