running windows service in ruby on windows 7 - ruby

I am using this gem:
win32-service (0.7.2 x86-mingw32)
The gem has a demo_daemon.rb and a demo_daemon_ctl.rb in the example directory.
I have tried to run the example as a service using both ruby 1.8.7 and 1.9.3 and I get the error below.
The daemon tries to write to a log file, but it never reaches a point where the log file gets written. Even if I put a log write on startup of the script nothing gets written.
My machine is 64 bit.
Any ideas on what I can try or what could be the issue?
C:/Ruby193/lib/ruby/gems/1.9.1/gems/win32-service-0.7.2-x86-mingw32/lib/win32/se
rvice.rb:760:in `start': The service did not respond to the start or control req
uest in a timely fashion. (Win32::Service::Error)
from demo_daemon_ctl.rb:75:in `<main>'

I think you need use a service wrapper such as srvany . Here is the Microsoft's guide. Use full path for both ruby and the script in the "Application" parameter. And if something goes wrong under 64bit system, just put the srvany.exe in both windows/system32 and windows/sysWow64 folder.

Related

Executing a .rb file (Ruby file) with PRY in Windows 7

I was wondering how I can load a Ruby file into PRY to use the debugger function on my Windows 7 computer with Command Prompt. I want to use PRY to go through my program step by step and following the tutorials online on how to do it aren't working for me (probably because all of them are using Mac Terminal)
I use SublimeText 2 to write everything up and then save it as a .rb file and I was told that if I wanted to debug the file I just made, I need to run it through IRB or PRY. Not, I already ran "gem install debugger". And the Ruby I have installed is 1.9.3 - p545. Do I need to add an extra line of code that says "binding.pry" (I saw that in some of the samples that I could find on stackoverflow). All I'm looking for is a simple step-by-step process. Thank you for reading this, I look forward to the responses.
Make sure you've installed pry and pry-debugger gems
At the top of your file, add statements for require 'pry' and require 'pry-debugger'
In your code, wherever you want to start ddebugging, just add a statement binding.pry
Now, you can run your file like ruby filename.rb and the debugger should open

Running Bundler on Windows - permission denied on /dev/null

I'm trying to set up a Ruby dev environment on Windows. So far it's fairly "vanilla", that is, it pretty much only consists of Ruby (1.9.1), Bundler (1.3.5) and a few random gems.
Now, whenever I try to run Bundler, I get the following exception:
C:/Ruby19/lib/ruby/1.9.1/rubygems/user_interaction.rb:544:in `initialize': Permission denied - /dev/null (Errno::EACCES)
Checking the source code, I found that Bundler determines that you're running Windows by trying to access /dev/null and then rescuing Errno::ENOENT ("No such file or directory"). I tried patching it to also rescue Errno:EACCES ("Permission denied"), and voila - it seems to run just fine.
I tried running the shell in elevated mode, but it still threw Errno:EACCES.
My question is simply this: Am I missing something? Or is this a bug in Bundler?
(for reference, I'm running on Windows 8)
/dev/null is a special file and is typically used for disposing of unwanted output streams of a process, or as a convenient empty file for input streams in *nix operating systems. It's not there in Windows.
If bundler is not checking on which operating system it's trying to use /dev/null then surely it's a problem at their end. To get things working without moving much you can use Cygwin.
I'm running on Windows 7.
I'v observed the issue "Errno:EACCES ("Permission denied")" for c:/dev/null
The directory c:/dev created (no "null" file) and problem resolved.

how to use RVM to a ruby app engine?

i wanna make a simple ruby App Engine in rails just like heroku, i'm dealing with a problem now.
My idea was:
1.use rails to establish the App Engine, use a class 'App' to handle all apps.
2.when a user create an ruby app he should offer it's git path
3.when the user deploys it, my app engine will do these things:
clone the git to a path in my server (done
use RVM to designatine the ruby version witch user wanted and make a gemdir for the project (some problems here
create a nginx conf for the project, then include it and reload nginx (i can do it
Problems in the second step:
codes here:
def start_thin
Dir.chdir(proj_path) do
system('rvm use ruby-1.8.7-p352#testname --create')
system('gem env gemdir')
success = system ('thin start -s3 --socket ' + self.proj_sock)
if success
return true
end
end
return false
end
when the code runs here, the log told me "RVM is not a function...blahblah", i know something about the login-shell and non-login-shell, then i try to fix it via editing .bashrc but same problem occurred.
And if i ignore it, the app can't be deployed, because of a Load Error :
myapp.rb:2:in `require': cannot load such file -- sinatra (LoadError)
if i open a terminal in that app directory, i can use thin to start it.
i wanna know how to run cmd just like in a terminal, without all these odd problem?
or how to edit my method to fix it?
Thanks!
Thanks Casper and GhostRider.
The user and rvm settings are correct.
After lots of googles and tests i found it's impossible...
Finally I fixed it by using RVM's ruby api instead of running system command.
Such as :
require 'rvm'
env = RVM.current
env.gemset.create('app1')

Struggling to boot up WEBrick

First a little indication of what I'm running:
Operating System: Windows 8 64-bit
Ruby version: 1.9.3p362
Rails version: 3.2.11
I've created a new rails project called simple_cms under C:\Users\Dean\Documents\Ruby_Projects\ .
I then navigate into the project directory, so my path then is C:\Users\Dean\Documents\Ruby_Projects\simple_cms\
I then run (with my administrator command prompt)
rails server
but I then get a whole lot of errors but the most prominent one being:
The specified module could not be found some\path\mysql2\1.9\mysql2.so
Any ideas?
EDIT: Attached is my full command prompt output...
It looks like your mysql2 gem hasn't been installed correctly.
Check out the answer to this question for info on properly installing the mysql2 gem. That should take care of the rest of your errors.

Need help with starting RoR: Command "rails server" does not result in "Booting WEBrick"?

I need help to get started with RoR.
I currently follow this guideline:
http://allaboutruby.wordpress.com/2009/07/20/installing-rails-on-windows-3-years-later/#comment-11099
I followed step 1 through 3 w/o problems.
In step 5: I can get the webserver through WEBrick working.
When i put
"rails server"
instead of getting "Booting Webrick", i get "rails new_path option"
thus when i try 127.0.0.1:3000 in the browser... it does work.
Can anyone guide me on this on how to get it up and runnning? (Im a total newb for now...so i need specific explanations! thanks!)
In your tutorial i can't see the command 'bundle install' - it's checking and installing all necessary gems in your system. So why you don't use another great rails tutorial - http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
I'm guessing you are running windows, on which rails can be a little awkward. You'll probably need to run the rails server command by pointing ruby at the server script. On windows, your rails "commmand" is actually just a .bat file that lives in the /bin file of your ruby installation, and that .bat file just passes the arguments to ruby. If you look at the rails gem that is installed on your machine, you'll see the files that correspond to the normal first argument of a rails command (console, generate, server, etc). You might find it helpful to copy these to the /script directory of your application, and when you want to run a rails command you can just run "ruby script\server" from your application's main directory, though there may be more accepted ways of getting the same result.

Resources