[Win32utils-devel] win32-daemon 0.6.1 problem

Heesob Park phasis at gmail.com
Fri Oct 31 06:52:01 EDT 2008


2008/10/31 Berger, Daniel <Daniel.Berger at qwest.com>:
> 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
>
In my test, I found two problems in the above demon.rb .
First, your environment may has RUBYOPT and raised following error.
ruby: no such file to load -- ubygems (LoadError)

I have workarounded by modifing "RUBYOPT" to "RUBYOPTX" in ruby.c #755.

Second, STDIN.close in demon.rb raise error.
In my thought, STDIN.close is just a meaningless code.

Regards,

Park Heesob


More information about the win32utils-devel mailing list