Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/win32/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class Service
# * failure_command => nil,
# * failure_actions => nil,
# * failure_delay => 0
# * failure_flag => nil
#
# Example:
#
Expand Down Expand Up @@ -317,6 +318,7 @@ def initialize(options = {})
"failure_command" => nil,
"failure_actions" => nil,
"failure_delay" => 0,
"failure_flag" => nil,
"host" => nil,
"service_name" => nil,
}
Expand Down Expand Up @@ -396,7 +398,7 @@ def initialize(options = {})
end

if opts["failure_reset_period"] || opts["failure_reboot_message"] ||
opts["failure_command"] || opts["failure_actions"]
opts["failure_command"] || opts["failure_actions"] || !opts["failure_flag"].nil?
self.class.configure_failure_actions(handle_scs, opts)
end
ensure
Expand Down Expand Up @@ -425,6 +427,7 @@ def initialize(options = {})
# * failure_reboot_message
# * failure_command
# * failure_actions
# * failure_flag
# * failure_delay
#
# Examples:
Expand Down Expand Up @@ -475,6 +478,7 @@ def self.configure(options = {})
"failure_command" => nil,
"failure_actions" => nil,
"failure_delay" => 0,
"failure_flag" => nil,
"service_name" => nil,
"host" => nil,
"delayed_start" => false,
Expand Down Expand Up @@ -579,7 +583,7 @@ def self.configure(options = {})
end

if opts["failure_reset_period"] || opts["failure_reboot_message"] ||
opts["failure_command"] || opts["failure_actions"]
opts["failure_command"] || opts["failure_actions"] || !opts["failure_flag"].nil?
configure_failure_actions(handle_scs, opts)
end
ensure
Expand Down Expand Up @@ -1397,6 +1401,18 @@ def self.configure_failure_actions(handle_scs, opts)
close_service_handle(handle_scs)
raise SystemCallError.new("ChangeServiceConfig2", error)
end

unless opts["failure_flag"].nil?
sfaf = SERVICE_FAILURE_ACTIONS_FLAG.new
sfaf[:fFailureActionsOnNonCrashFailures] = opts["failure_flag"] ? 1 : 0
bool = ChangeServiceConfig2(
handle_scs,
SERVICE_CONFIG_FAILURE_ACTIONS_FLAG,
sfaf
)

FFI.raise_windows_error("ChangeServiceConfig2") unless bool
end
end

# Returns a human readable string indicating the action type.
Expand Down
6 changes: 6 additions & 0 deletions lib/win32/windows/structs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class SERVICE_FAILURE_ACTIONS < FFI::Struct
)
end

class SERVICE_FAILURE_ACTIONS_FLAG < FFI::Struct
layout(
:fFailureActionsOnNonCrashFailures, :int
)
end

class SERVICE_TABLE_ENTRY < FFI::Struct
layout(
:lpServiceName, :pointer,
Expand Down