win-service-manager

by Ryan Castro (Originally by James Tucker)
http://github.com/ryancastro/win-service-manager/

DESCRIPTION:

Install, configure, and manage Microsoft Windows services from Ruby. Using Microsoft’s SRVany.exe from the MS Resource Toolkit, run a Ruby script as a Windows service.

FEATURES/PROBLEMS:

  • Turn any application into a Windows service using Srvany.exe. Manage existing services.

  • Depending on how your Ruby process launches (Like rails, which uses a batch file), stopping the service may stop SRVany.exe, but leave the child batch running.

SYNOPSIS:

#Create a new manager
sm = WinServiceManager.new(File.expand_path("srvany.exe"))
#Creat a new service.  Name, exe, arguments, directory to run from, Service description
sm.create('foo service', 'c:\ruby18\bin\rubyw', 'my_awesome_daemon.rb', 'c:\daemon', "This is my Daemon Service" )
sm.start('foo service')
sm.stop('foo service')
sm.delete('foo service')
puts sm.list

TURNING RAILS 4 INTO A WINDOWS SERVICE:

require 'win-service-manager'
service = WinServiceManager.new('c:\mc_ruby\srvany.exe')
service.create('Awesome Rails 4 service', 'c:\ruby200\bin\ruby', 'c:\ruby200\bin\rails server -e production', 'c:\projects\awesomerails', 'Rails 4 Service Description')

REQUIREMENTS:

At the time of writing, some of the dependencies are only available as gems to the ‘x86-mswin32-60’ platform. If you are installing on mingw, you can get away with installing them using a specific –platform argument to rubygems.

  • gem inst win32-service win32-registry

INSTALL:

  • gem inst win-service-manager

  • To create services, download srvany.exe from Microsoft Resource Kit Tools and provide it’s path to WinServiceManager

LICENSE:

(The MIT License)

Copyright © 2008 James Tucker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.