[Win32utils-devel] win32-daemon 0.6.1 problem
Berger, Daniel
Daniel.Berger at qwest.com
Thu Oct 30 18:00:38 EDT 2008
Hi,
Ruby 1.8.6-p114 built with VC++ 8
win32-service 0.6.1 (also built with VC++ 8)
Windows XP Pro SP 2
I'm having trouble getting even this simple daemon to work. I can't even
get it to log an error to the file. Any ideas?
# demon.rb
begin
LOG_FILE = "C:\\demon_test.log"
LOG_HANDLE = File.open(LOG_FILE, 'a')
STDIN.close
STDERR.reopen(LOG_HANDLE)
STDOUT.reopen(LOG_HANDLE)
require 'win32/daemon'
include Win32
class Daemon
def service_main
while running?
sleep 3
puts "service is running"
end
end
def service_stop
exit!
end
end
Daemon.mainloop
rescue Exception => err
puts "ERROR: #{err}"
puts
puts "Our Daemon blowed up: " + err.backtrace.join("\n")
raise
ensure
LOG_HANDLE.close if LOG_HANDLE && !LOG_HANDLE.closed?
end
# demo_ctl.rb
require 'win32/service'
require 'rbconfig'
include Config
include Win32
case ARGV.first.chomp
when 'install'
# Some path handling to deal with spaces and slashes
path = File.join(CONFIG['bindir'], 'ruby.exe') + ' '
path += '"' + File.expand_path('demon.rb') + '"'
path = path.tr("/", "\\")
Service.create('DemoService', nil,
:display_name => 'DemoService',
:service_type => Service::WIN32_OWN_PROCESS,
:description => 'Demo Service',
:binary_path_name => path,
:service_start_name => 'my_domain\my_userid',
:password => 'my_password'
)
puts "Service created"
when 'stop'
Service.stop('DemoService')
puts "Service stopped"
when 'start'
Service.start('DemoService')
puts "Service started"
when 'uninstall'
Service.delete('DemoService')
puts "Service uninstalled"
else
STDERR.puts "Valid options are 'install', 'uninstall', 'stop' and
'start'"
end
In other news, it doesn't seem to like the default service_type. If I
don't explicitly pass it an option the CreateService() call at line 332
will die. Maybe I should remove "interactive" as part of the default.
Regards,
Dan
This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.
More information about the win32utils-devel
mailing list