[Win32utils-devel] win32-service patch

Heesob Park phasis at gmail.com
Tue Jun 18 05:11:18 UTC 2013


Hi,

2013/6/18 Daniel Berger <djberg96 at gmail.com>:
>
>
> On Mon, Jun 17, 2013 at 8:21 AM, Heesob Park <phasis at gmail.com> wrote:
>>
>> Hi,
>>
>> 2013/6/17 Daniel Berger <djberg96 at gmail.com>:
>> >
>> >> >
>> >> > However, it seems the JVM takes too long to spin up. When I try to
>> >> > start
>> >> > the
>> >> > service, I get the "did not start in a timely fashion" error with
>> >> > JRuby.
>> >> > Although, I would think the service_init method would give it enough
>> >> > time.
>> >> > From watching the log file, though, it doesn't look like it ever gets
>> >> > to
>> >> > service_init.
>> >> >
>> >> I guess this is an environment issue.
>> >>
>> >> In my test with jruby-1.7.4, it works fine and the log file looks good.
>> >>
>> >> 0
>> >> 1
>> >> 2
>> >> 3
>> >> 4
>> >> 5
>> >> 6
>> >> 7
>> >> 8
>> >> 9
>> >> service_main entered at: 2013-06-17 22:21:12 +0900
>> >> Args: DemoSvc,hello
>> >> Service is running as of: 2013-06-17 22:21:32 +0900
>> >> Service is running as of: 2013-06-17 22:21:52 +0900
>> >> Service is running as of: 2013-06-17 22:22:12 +0900
>> >>
>> >
>> > Weird. I installed the latest JRuby x64 + JVM:
>> >
>> > jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) Client VM
>> > 1.7.0_21-b11 [Windows
>> > 7-x86]
>> >
>> > This is Windows 7 Home Premium, btw.
>> >
>> > Still get this error:
>> >
>> > SystemCallError: Unknown error 1053 - StartService: The service did not
>> > respond to the start or control request in a timely fashion.
>> >   raise_windows_error at
>> >
>> > c:/Users/djberge/Repositories/win32-service/lib/win32/windows/helper.rb:36
>> > start at
>> > c:/Users/djberge/Repositories/win32-service/lib/win32/service.rb:725
>> > (root) at examples\demo_daemon_ctl.rb:68
>> >
>> I guess this means your demo_daemon.rb has some errors.
>> I recommend you to try "jruby demo_daemon.rb" and make sure
>> demo_daemon.rb has no error.
>>
>> > Well, I'm happy to know that it works for someone. I'll try it on my
>> > Windows
>> > 7 Pro box and see if it makes any difference.
>> >
>> I added some constant definition to daemon.rb
>>
>>    # Service is not running
>>     STOPPED = SERVICE_STOPPED
>>     # Service has received a start signal but is not yet running
>>     START_PENDING = SERVICE_START_PENDING
>>     # Service has received a stop signal but is not yet stopped
>>     STOP_PENDING  = SERVICE_STOP_PENDING
>>     # Service is running
>>     RUNNING = SERVICE_RUNNING
>>     # Service has received a signal to resume but is not yet running
>>     CONTINUE_PENDING = SERVICE_CONTINUE_PENDING
>>     # Service has received a signal to pause but is not yet paused
>>     PAUSE_PENDING = SERVICE_PAUSE_PENDING
>>     # Service is paused
>>     PAUSED = SERVICE_PAUSED
>>
>>     # Service controls
>>     # Notifies service that it should stop
>>     CONTROL_STOP = SERVICE_CONTROL_STOP
>>     # Notifies service that it should pause
>>     CONTROL_PAUSE = SERVICE_CONTROL_PAUSE
>>     # Notifies service that it should resume
>>     CONTROL_CONTINUE = SERVICE_CONTROL_CONTINUE
>>     # Notifies service that it should return its current status
>> information
>>     CONTROL_INTERROGATE = SERVICE_CONTROL_INTERROGATE
>>     # Notifies a service that its parameters have changed
>>     CONTROL_PARAMCHANGE = SERVICE_CONTROL_PARAMCHANGE
>>     # Notifies a service that there is a new component for binding
>>     CONTROL_NETBINDADD = SERVICE_CONTROL_NETBINDADD
>>     # Notifies a service that a component for binding has been removed
>>     CONTROL_NETBINDREMOVE = SERVICE_CONTROL_NETBINDREMOVE
>>     # Notifies a service that a component for binding has been enabled
>>     CONTROL_NETBINDENABLE = SERVICE_CONTROL_NETBINDENABLE
>>     # Notifies a service that a component for binding has been disabled
>>     CONTROL_NETBINDDISABLE = SERVICE_CONTROL_NETBINDDISABLE
>>     IDLE = 0
>>
>> And My demo_daemon.rb is https://gist.github.com/phasis68/5797203
>
>
> Ok, I added those constants.
>
> Well, there's good news and bad news. The good news is that I got things
> cleared up and things work fine with JRuby. The bad news is that it seems to
> be doubling the sleep call with MRI.
>
> For example, here's the output from the logfile with JRuby:
>
> service_main entered at: 2013-06-17 17:57:56 -0600
> Args: DemoSvc,hello
> Service is running as of: 2013-06-17 17:58:16 -0600
> Service is running as of: 2013-06-17 17:58:36 -0600
> Service is running as of: 2013-06-17 17:58:56 -0600
>
> Works as expected, with 20 seconds between writes.
>
> With MRI, here's what I see:
>
> service_main entered at: 2013-06-17 18:06:43 -0600
> Args: DemoSvc,hello
> Service is running as of: 2013-06-17 18:07:25 -0600
> Service is running as of: 2013-06-17 18:08:05 -0600
> Service is running as of: 2013-06-17 18:08:45 -0600
>
> So, it's writing every 40 seconds instead of 20.
>
> This is with Ruby 1.9.3-p374.
>
> Ideas?
>
I found the solution for this issue.
The modification of blocking of WaitForSingleObject function fixes
time delay problem.

The line #28 of functions.rb
    attach_function :WaitForSingleObject, [:handle, :dword], :dword
should be
    attach_function :WaitForSingleObject, [:handle, :dword], :dword,
:blocking => true


Regards,
Park Heesob


More information about the win32utils-devel mailing list