You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raisePuppet::Error.new(_("Unknown Service state '%{current_state}' for '%{service_name}'") % {current_state: status[:dwCurrentState].to_s,service_name: service_name})
370
+
raisePuppet::Error.new(_("Unknown Service state '%{current_state}' for '%{service_name}'") % {current_state: state.to_s,service_name: service_name})
raisePuppet::Error.new(_("Unknown start type '%{start_type}' for '%{service_name}'") % {start_type: config[:dwStartType].to_s,service_name: service_name})
388
+
raisePuppet::Error.new(_("Unknown start type '%{start_type}' for '%{service_name}'") % {start_type: start_type.to_s,service_name: service_name})
raisePuppet::Error,_("The service must be in one of the %{valid_initial_states} states to perform this transition. It is currently in the %{current_state} state.") % {valid_initial_states: valid_initial_states_str,current_state: SERVICE_STATES[initial_state]}
584
-
end
584
+
raisePuppet::Error,_("The service must be in one of the %{valid_initial_states} states to perform this transition. It is currently in the %{current_state} state.") % {valid_initial_states: valid_initial_states_str,current_state: SERVICE_STATES[initial_state]}
585
+
end
585
586
586
-
# Check if there's a pending transition to the final_state. If so, then wait for
# SERVICE_RUNNING has two pending states, SERVICE_START_PENDING and
590
-
# SERVICE_CONTINUE_PENDING. That is why we need the #select here
591
-
FINAL_STATES[pending_state] == final_state
592
-
end
593
-
ifpossible_pending_states.include?(initial_state)
594
-
Puppet.debug_("There is already a pending transition to the %{final_state} state for the %{service_name} service.") % {final_state: SERVICE_STATES[final_state],service_name: service_name}
595
-
wait_on_pending_state(service,initial_state)
587
+
# Check if there's a pending transition to the final_state. If so, then wait for
# SERVICE_RUNNING has two pending states, SERVICE_START_PENDING and
591
+
# SERVICE_CONTINUE_PENDING. That is why we need the #select here
592
+
FINAL_STATES[pending_state] == final_state
593
+
end
594
+
ifpossible_pending_states.include?(initial_state)
595
+
Puppet.debug_("There is already a pending transition to the %{final_state} state for the %{service_name} service.") % {final_state: SERVICE_STATES[final_state],service_name: service_name}
596
+
wait_on_pending_state(service,initial_state)
596
597
597
-
next
598
-
end
598
+
next
599
+
end
599
600
600
-
# If we are in an unsafe pending state like SERVICE_START_PENDING
601
-
# or SERVICE_STOP_PENDING, then we want to wait for that pending
602
-
# transition to finish before transitioning the service state.
603
-
# The reason we do this is because SERVICE_START_PENDING is when
604
-
# the service thread is being created and initialized, while
605
-
# SERVICE_STOP_PENDING is when the service thread is being cleaned
606
-
# up and destroyed. Thus there is a chance that when the service is
607
-
# in either of these states, its service thread may not yet be ready
608
-
# to perform the state transition (it may not even exist).
609
-
ifUNSAFE_PENDING_STATES.include?(initial_state)
610
-
Puppet.debug_("The service is in the %{pending_state} state, which is an unsafe pending state.") % {pending_state: SERVICE_STATES[initial_state]}
611
-
wait_on_pending_state(service,initial_state)
612
-
initial_state=FINAL_STATES[initial_state]
613
-
end
601
+
# If we are in an unsafe pending state like SERVICE_START_PENDING
602
+
# or SERVICE_STOP_PENDING, then we want to wait for that pending
603
+
# transition to finish before transitioning the service state.
604
+
# The reason we do this is because SERVICE_START_PENDING is when
605
+
# the service thread is being created and initialized, while
606
+
# SERVICE_STOP_PENDING is when the service thread is being cleaned
607
+
# up and destroyed. Thus there is a chance that when the service is
608
+
# in either of these states, its service thread may not yet be ready
609
+
# to perform the state transition (it may not even exist).
610
+
ifUNSAFE_PENDING_STATES.include?(initial_state)
611
+
Puppet.debug_("The service is in the %{pending_state} state, which is an unsafe pending state.") % {pending_state: SERVICE_STATES[initial_state]}
612
+
wait_on_pending_state(service,initial_state)
613
+
initial_state=FINAL_STATES[initial_state]
614
+
end
614
615
615
-
Puppet.debug_("Transitioning the %{service_name} service from %{initial_state} to %{final_state}") % {service_name: service_name,initial_state: SERVICE_STATES[initial_state],final_state: SERVICE_STATES[final_state]}
616
+
Puppet.debug_("Transitioning the %{service_name} service from %{initial_state} to %{final_state}") % {service_name: service_name,initial_state: SERVICE_STATES[initial_state],final_state: SERVICE_STATES[final_state]}
616
617
617
-
yieldservice
618
+
yieldservice
618
619
619
-
Puppet.debug_("Waiting for the transition to finish")
raisePuppet::Error,_("Failed to transition the %{service_name} service to the %{final_state} state. Detail: %{detail}") % {service_name: service_name,final_state: SERVICE_STATES[final_state],detail: detail},detail.backtrace
Puppet.debug_("The service transitioned to the %{pending_state} state.") % {pending_state: SERVICE_STATES[pending_state]}
750
-
wait_on_pending_state(service,pending_state)
751
-
return
752
-
end
753
746
754
-
sleep(1)
755
-
elapsed_time += 1
747
+
query_status(service)do |status|
748
+
state=status[:dwCurrentState]
749
+
returnifstate == final_state
750
+
ifstate == pending_state
751
+
Puppet.debug_("The service transitioned to the %{pending_state} state.") % {pending_state: SERVICE_STATES[pending_state]}
752
+
wait_on_pending_state(service,pending_state)
753
+
return
754
+
end
755
+
sleep(1)
756
+
elapsed_time += 1
757
+
end
756
758
end
757
-
758
759
# Timed out while waiting for the transition to finish. Raise an error
760
+
# We can still use the state variable read from the FFI struct because
761
+
# FFI creates new Integer objects during an assignment of an integer value
762
+
# stored in an FFI struct. We verified that the '=' operater is safe
763
+
# from the freed memory since the new ruby object created during the
764
+
# assignment will remain in ruby memory and remain immutable and constant.
759
765
raisePuppet::Error,_("Timed out while waiting for the service to transition from %{initial_state} to %{final_state} OR from %{initial_state} to %{pending_state} to %{final_state}. The service's current state is %{current_state}.") % {initial_state: SERVICE_STATES[initial_state],final_state: SERVICE_STATES[final_state],pending_state: SERVICE_STATES[pending_state],current_state: SERVICE_STATES[state]}
# Check if our service has finished transitioning to
782
-
# the final_state OR if an unexpected transition
783
-
# has occurred
784
-
returnifstate == final_state
785
-
unlessstate == pending_state
786
-
raisePuppet::Error,_("Unexpected transition to the %{current_state} state while waiting for the pending transition from %{pending_state} to %{final_state} to finish.") % {current_state: SERVICE_STATES[state],pending_state: SERVICE_STATES[pending_state],final_state: SERVICE_STATES[final_state]}
787
-
end
784
+
query_status(service)do |status|
785
+
state=status[:dwCurrentState]
786
+
checkpoint=status[:dwCheckPoint]
787
+
wait_hint=status[:dwWaitHint]
788
+
# Check if our service has finished transitioning to
789
+
# the final_state OR if an unexpected transition
790
+
# has occurred
791
+
returnifstate == final_state
792
+
unlessstate == pending_state
793
+
raisePuppet::Error,_("Unexpected transition to the %{current_state} state while waiting for the pending transition from %{pending_state} to %{final_state} to finish.") % {current_state: SERVICE_STATES[state],pending_state: SERVICE_STATES[pending_state],final_state: SERVICE_STATES[final_state]}
794
+
end
788
795
789
-
# Check if any progress has been made since our last sleep
790
-
# using the dwCheckPoint. If no progress has been made then
791
-
# check if we've timed out, and raise an error if so
raisePuppet::Error,_("Timed out while waiting for the pending transition from %{pending_state} to %{final_state} to finish. The current state is %{current_state}.") % {pending_state: SERVICE_STATES[pending_state],final_state: SERVICE_STATES[final_state],current_state: SERVICE_STATES[state]}
796
+
# Check if any progress has been made since our last sleep
797
+
# using the dwCheckPoint. If no progress has been made then
798
+
# check if we've timed out, and raise an error if so
raisePuppet::Error,_("Timed out while waiting for the pending transition from %{pending_state} to %{final_state} to finish. The current state is %{current_state}.") % {pending_state: SERVICE_STATES[pending_state],final_state: SERVICE_STATES[final_state],current_state: SERVICE_STATES[state]}
808
+
end
801
809
end
810
+
wait_time=wait_hint_to_wait_time(wait_hint)
811
+
# Wait a bit before rechecking the service's state
812
+
sleep(wait_time)
813
+
elapsed_time += wait_time
802
814
end
803
-
804
-
# Wait a bit before rechecking the service's state
0 commit comments