Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
fixes for service_restart
Browse files Browse the repository at this point in the history
for issue #330
  • Loading branch information
paulczar committed Aug 31, 2014
1 parent 6a183bd commit 1c83271
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 293 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ vendor/
.kitchen/
.kitchen.local.yml
.bundle/
bin/
bin/
Gemfile.lock
248 changes: 0 additions & 248 deletions Gemfile.lock

This file was deleted.

3 changes: 2 additions & 1 deletion providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def load_current_resource
@service_name = new_resource.service_name || @instance
end

use_inline_resources

action :create do
conf = conf_vars
# Chef::Log.info("config vars: #{conf.inspect}")
Expand All @@ -40,7 +42,6 @@ def load_current_resource
group conf[:group]
mode conf[:mode]
variables conf[:variables]
notifies :restart, "logstash_service[#{conf[:service_name]}]"
action :create
end
new_resource.updated_by_last_action(tp.updated_by_last_action?)
Expand Down
78 changes: 42 additions & 36 deletions providers/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,52 +41,22 @@ def load_current_resource
@supervisor_gid = attributes['supervisor_gid'] || defaults['supervisor_gid']
end

use_inline_resources

action :restart do
svc = svc_vars
case svc[:method]
when 'native'
sv = service svc[:service_name] do
# provider Chef::Provider::Service::Upstart
action [:restart]
end
new_resource.updated_by_last_action(sv.updated_by_last_action?)
end
service_action(:restart)
end

action :start do
svc = svc_vars
case svc[:method]
when 'native'
sv = service svc[:service_name] do
# provider Chef::Provider::Service::Upstart
action [:start]
end
new_resource.updated_by_last_action(sv.updated_by_last_action?)
end
service_action(:start)
end

action :stop do
svc = svc_vars
case svc[:method]
when 'native'
sv = service svc[:service_name] do
# provider Chef::Provider::Service::Upstart
action [:stop]
end
new_resource.updated_by_last_action(sv.updated_by_last_action?)
end
service_action(:stop)
end

action :reload do
svc = svc_vars
case svc[:method]
when 'native'
sv = service svc[:service_name] do
# provider Chef::Provider::Service::Upstart
action [:reload]
end
new_resource.updated_by_last_action(sv.updated_by_last_action?)
end
service_action(:reload)
end

action :enable do
Expand Down Expand Up @@ -243,6 +213,42 @@ def default_args
args
end

def service_action(action)
svc = svc_vars
case svc[:method]
when 'native'
sv = service svc[:service_name]
case pick_provider
when 'systemd'
sv.provider(Chef::Provider::Service::Systemd)
when 'upstart'
sv.provider(Chef::Provider::Service::Upstart)
else
sv.provider(Chef::Provider::Service::Init)
end
sv.run_action(action)
new_resource.updated_by_last_action(sv.updated_by_last_action?)
end
end

def pick_provider
if platform_family? 'fedora'
if node['platform_version'] >= '15'
return 'systemd'
else
return 'default'
end
elsif platform_family? 'debian'
if node['platform_version'] >= '12.04'
return 'upstart'
else
return 'default'
end
else
return 'default'
end
end

def svc_vars
svc = {
name: @instance,
Expand Down
1 change: 1 addition & 0 deletions recipes/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
input_file_name: '/var/log/syslog',
input_file_type: 'syslog'
)
notifies :restart, "logstash_service[#{name}]"
action [:create]
end

Expand Down
Loading

0 comments on commit 1c83271

Please sign in to comment.