[Win32utils-devel] Need help with win32-service, failure actions

Heesob Park phasis at gmail.com
Mon Nov 19 00:41:21 EST 2007


Hi,

2007/11/19, Daniel Berger <djberg96 at gmail.com>:
>
> Hi all,
>
> I'm trying to get failure action support working. I've modified the
> Service.configure method to accept the following options:
>
> failure_reset_period
> failure_command
> failure_reboot_message
> failure_actions
> failure_delay
>
> I've got the failure_command and failure_reboot message working, but the
> rest aren't working properly. I'm mostly focused on
> failure_reboot_actions.
>
> Here's an example:
>
> Service.configure('some_service', nil,
>    :failure_reset_period => 10,
>    :failure_command      => "notepad.exe",
>    :failure_delay        => 5000,
>    :failure_actions      => [
>       Service::ACTION_RESTART,
>       Service::ACTION_RUN_COMMAND,
>       Service::ACTION_REBOOT
>    ]
> )
>
> I've probably just packed the data structures wrong, but I couldn't see
> how. Please take a look at Service.configure in CVS.
>
> Thanks,
>
> Dan



The main reason of not working is the wrong definition of SC_ACTION_RESTART
and SC_ACTION_REBOOT and the lack of privileges.

1. Modify SC_ACTION_RESTART and SC_ACTION_REBOOT constant value.
   windows-pr/lib/windows/service.rb #23

      SC_ACTION_NONE        = 0
      SC_ACTION_RESTART     = 1
      SC_ACTION_REBOOT      = 2
      SC_ACTION_RUN_COMMAND = 3

2. Define some constants and API functions.
   windows-pr/lib/windows/process.rb #53

         TOKEN_ADJUST_PRIVILEGES = 0x20
         TOKEN_QUERY = 0x8
         SE_PRIVILEGE_ENABLED = 0x2

         API.new('OpenProcessToken', 'LLP', 'L', 'advapi32')
         API.new('LookupPrivilegeValue', 'PPP', 'L', 'advapi32')
         API.new('AdjustTokenPrivileges', 'LLPLPP', 'L', 'advapi32')

3. Modify service.rb configure method.

    Modify line # 443
         handle_scs = OpenService(handle_scm, service,
SERVICE_CHANGE_CONFIG)
   to
         handle_scs = OpenService(handle_scm, service, SERVICE_CHANGE_CONFIG
| SERVICE_START)

   Insert following line after line #503

           hdlTokenHandle = 0.chr * 4
           OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES |
TOKEN_QUERY, hdlTokenHandle)
           hdlTokenHandle = hdlTokenHandle.unpack('L').first

           #Get the LUID for shutdown privilege.
           tmpLuid = 0.chr * 8
           LookupPrivilegeValue("", "SeShutdownPrivilege", tmpLuid)
           tkp = [1].pack('L') + tmpLuid + [SE_PRIVILEGE_ENABLED].pack('L')

           # Enable the shutdown privilege in the access token of this
process.
           AdjustTokenPrivileges(hdlTokenHandle, 0,tkp, tkp.length , nil,
nil)


Regards,

Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071119/1763f96b/attachment-0001.html 


More information about the win32utils-devel mailing list