Skip to content

Commit

Permalink
Added manual service stopping
Browse files Browse the repository at this point in the history
  • Loading branch information
xea committed Jun 3, 2018
1 parent 596c4c6 commit 524dde2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
watch_dir: packages
scan_interval: 5
:console:
mode: dumb
mode: normal
2 changes: 1 addition & 1 deletion lib/console/mode_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def list_services(out, framework)
end

def stop_service(out, framework, service_id)
framework.stop_service service_id
framework.stop_service service_id, true
end

def start_service(out, framework, service_id)
Expand Down
20 changes: 18 additions & 2 deletions lib/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def process_stages(stages)

end

satisfied_dependencies = []

registrations = add_requests.map do |add_request|
@service_registry.register_service(*(add_request.drop(1))) { |registration|
if has_required_dependencies? registration.service
Expand All @@ -177,6 +179,8 @@ def process_stages(stages)
dependants(registration.service)[:required].each do |dependant|
if has_required_dependencies? dependant.service and dependant.service.state? RunState::INSTALLED
dependant.service.set_state_resolved

satisfied_dependencies << dependant
end
end
}
Expand All @@ -186,6 +190,10 @@ def process_stages(stages)
start_service registration
end

satisfied_dependencies.each do |dependant|
start_service dependant
end

# Process the remaining stages
process_stages stages
end
Expand Down Expand Up @@ -224,6 +232,12 @@ def update_status(service)
def start_service(service_registration)
service = service_registration[:service]

# If the service had been stopped manually before the start, we'll first need to check if all required dependencies
# are present before proceeding.
if service.state? RunState::STOPPED and has_required_dependencies? service
service.set_state_resolved
end

if service.state? RunState::RESOLVED
service.set_state_starting

Expand Down Expand Up @@ -260,7 +274,7 @@ def start_service(service_registration)
end
end

def stop_service(service_registration)
def stop_service(service_registration, requested = false)
service = service_registration[:service]

if service.state? RunState::ACTIVE
Expand All @@ -280,7 +294,9 @@ def stop_service(service_registration)

service.stop

if has_required_dependencies?(service)
if requested
service.set_state_stopped
elsif has_required_dependencies?(service)
service.set_state_resolved
else
service.set_state_installed
Expand Down
6 changes: 6 additions & 0 deletions lib/core/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module RunState
STARTING = :starting
ACTIVE = :active
STOPPING = :stopping
STOPPED = :stopped

def set_state_uninstalled(verbose_state = "")
@_state = RunState::UNINSTALLED
Expand Down Expand Up @@ -37,6 +38,11 @@ def set_state_starting(verbose_state = "")
@_verbose_state = verbose_state
end

def set_state_stopped(verbose_state = "")
@_state = RunState::STOPPED
@_verbose_state = verbose_state
end

# Query the current state
def state
@_state || RunState::INSTALLED
Expand Down
4 changes: 2 additions & 2 deletions lib/service/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def start_service(service_id)
@core.start_service service_registration unless service_registration.nil?
end

def stop_service(service_id)
def stop_service(service_id, requested = false)
service_registration = @core.service_registry.find { |service| service.service_id == service_id.to_sym }
@core.stop_service service_registration unless service_registration.nil?
@core.stop_service service_registration, requested unless service_registration.nil?
end
end

0 comments on commit 524dde2

Please sign in to comment.