Update poise-archive and poise-service cookbooks
This commit is contained in:
@@ -1,5 +1,23 @@
|
||||
# Poise-Service Changelog
|
||||
|
||||
## v1.5.2
|
||||
|
||||
* Set `declared_type` on the mixin-created `poise_service` resource so it works
|
||||
correctly with ChefSpec.
|
||||
|
||||
## v1.5.1
|
||||
|
||||
* Fix the `sysvinit` provider on Amazon Linux under Chef 13.
|
||||
|
||||
## v1.5.0
|
||||
|
||||
* Added `never_start` and `never_stop` provider options to prevent Chef from starting
|
||||
or stopping a service.
|
||||
* Automatically reload systemd when removing a service if auto_reload is enabled.
|
||||
* Improved dummy provider, records process output to `/var/run/service_name.out`
|
||||
and a `restart_delay` provider option to the dummy provider to wait between
|
||||
stopping and starting.
|
||||
|
||||
## v1.4.2
|
||||
|
||||
* Fix the `noterm` test service to work on Ruby 2.3.
|
||||
|
||||
@@ -256,6 +256,8 @@ process creating a PID file in the given path.
|
||||
* `reload_signal` – Override the service reload signal.
|
||||
* `stop_signal` – Override the service stop signal.
|
||||
* `user` – Override the service user.
|
||||
* `never_start` – Never try to start the service.
|
||||
* `never_stop` – Never try to stop the service.
|
||||
* `never_restart` – Never try to restart the service.
|
||||
* `never_reload` – Never try to reload the service.
|
||||
* `script_path` – Override the path to the generated service script.
|
||||
@@ -294,6 +296,8 @@ default and will throw an error if a reload signal other than SIGHUP is used.
|
||||
* `reload_signal` – Override the service reload signal.
|
||||
* `stop_signal` – Override the service stop signal.
|
||||
* `user` – Override the service user.
|
||||
* `never_start` – Never try to start the service.
|
||||
* `never_stop` – Never try to stop the service.
|
||||
* `never_restart` – Never try to restart the service.
|
||||
* `never_reload` – Never try to reload the service.
|
||||
|
||||
@@ -320,6 +324,8 @@ end
|
||||
* `reload_signal` – Override the service reload signal.
|
||||
* `stop_signal` – Override the service stop signal.
|
||||
* `user` – Override the service user.
|
||||
* `never_start` – Never try to start the service.
|
||||
* `never_stop` – Never try to stop the service.
|
||||
* `never_restart` – Never try to restart the service.
|
||||
* `never_reload` – Never try to reload the service.
|
||||
* `auto_reload` – Run `systemctl daemon-reload` after changes to the unit file. *(default: true)*
|
||||
@@ -343,6 +349,8 @@ as they are enabled.
|
||||
|
||||
#### Options
|
||||
|
||||
* `never_start` – Never try to start the service.
|
||||
* `never_stop` – Never try to stop the service.
|
||||
* `never_restart` – Never try to restart the service.
|
||||
* `never_reload` – Never try to reload the service.
|
||||
* `pid_file` – Path to PID file that the service command will create.
|
||||
@@ -350,6 +358,32 @@ as they are enabled.
|
||||
auto-generated hash based on the service name. If these collide, bad things
|
||||
happen. Don't do that.
|
||||
|
||||
### `dummy`
|
||||
|
||||
The `dummy` provider supports launching services directly from Chef itself.
|
||||
This is for testing purposes only and is entirely unsuitable for use in
|
||||
production. This is mostly useful when used alongside kitchen-docker.
|
||||
|
||||
```ruby
|
||||
poise_service 'myapp' do
|
||||
provider :dummy
|
||||
command 'myapp --serve'
|
||||
end
|
||||
```
|
||||
|
||||
The service information is written to `/var/run`. The PID file is `service_name.pid`,
|
||||
the command output is `service_name.out`, and the service parameters are in
|
||||
`service_name.json`.
|
||||
|
||||
#### Options
|
||||
|
||||
* `never_start` – Never try to start the service.
|
||||
* `never_stop` – Never try to stop the service.
|
||||
* `never_restart` – Never try to restart the service.
|
||||
* `never_reload` – Never try to reload the service.
|
||||
* `restart_delay` – Number of seconds to wait between stop and start when
|
||||
restarting. *(default: 1)*
|
||||
|
||||
## ServiceMixin
|
||||
|
||||
For the common case of a resource (LWRP or plain Ruby) that roughly maps to
|
||||
|
||||
@@ -167,6 +167,7 @@ module PoiseService
|
||||
def service_resource
|
||||
@service_resource ||= PoiseService::Resources::PoiseService::Resource.new(new_resource.name, run_context).tap do |r|
|
||||
# Set some defaults.
|
||||
r.declared_type = :poise_service
|
||||
r.enclosing_provider = self
|
||||
r.source_line = new_resource.source_line
|
||||
r.service_name(new_resource.service_name)
|
||||
|
||||
@@ -70,12 +70,14 @@ module PoiseService
|
||||
end
|
||||
|
||||
def action_start
|
||||
return if options['never_start']
|
||||
notify_if_service do
|
||||
service_resource.run_action(:start)
|
||||
end
|
||||
end
|
||||
|
||||
def action_stop
|
||||
return if options['never_stop']
|
||||
notify_if_service do
|
||||
service_resource.run_action(:stop)
|
||||
end
|
||||
@@ -139,6 +141,7 @@ module PoiseService
|
||||
# restart actions.
|
||||
def service_resource
|
||||
@service_resource ||= Chef::Resource::Service.new(new_resource.service_name, run_context).tap do |r|
|
||||
r.declared_type = :service
|
||||
r.enclosing_provider = self
|
||||
r.source_line = new_resource.source_line
|
||||
r.supports(status: true, restart: true, reload: true)
|
||||
|
||||
@@ -25,7 +25,16 @@ module PoiseService
|
||||
class Dummy < Base
|
||||
provides(:dummy)
|
||||
|
||||
# @api private
|
||||
def self.default_inversion_options(node, resource)
|
||||
super.merge({
|
||||
# Time to wait between stop and start.
|
||||
restart_delay: 1,
|
||||
})
|
||||
end
|
||||
|
||||
def action_start
|
||||
return if options['never_start']
|
||||
return if pid
|
||||
Chef::Log.debug("[#{new_resource}] Starting #{new_resource.command}")
|
||||
# Clear the pid file if it exists.
|
||||
@@ -45,39 +54,62 @@ module PoiseService
|
||||
end
|
||||
else
|
||||
# :nocov:
|
||||
Chef::Log.debug("[#{new_resource}] Forked")
|
||||
# First child, daemonize and go to town. This handles multi-fork,
|
||||
# setsid, and shutting down stdin/out/err.
|
||||
Process.daemon(true)
|
||||
Chef::Log.debug("[#{new_resource}] Daemonized")
|
||||
# Daemonized, set up process environment.
|
||||
Dir.chdir(new_resource.directory)
|
||||
Chef::Log.debug("[#{new_resource}] Directory changed to #{new_resource.directory}")
|
||||
ENV['HOME'] = Dir.home(new_resource.user)
|
||||
new_resource.environment.each do |key, val|
|
||||
ENV[key.to_s] = val.to_s
|
||||
begin
|
||||
Chef::Log.debug("[#{new_resource}] Forked")
|
||||
# First child, daemonize and go to town. This handles multi-fork,
|
||||
# setsid, and shutting down stdin/out/err.
|
||||
Process.daemon(true)
|
||||
Chef::Log.debug("[#{new_resource}] Daemonized")
|
||||
# Daemonized, set up process environment.
|
||||
Dir.chdir(new_resource.directory)
|
||||
Chef::Log.debug("[#{new_resource}] Directory changed to #{new_resource.directory}")
|
||||
ENV['HOME'] = Dir.home(new_resource.user)
|
||||
new_resource.environment.each do |key, val|
|
||||
ENV[key.to_s] = val.to_s
|
||||
end
|
||||
Chef::Log.debug("[#{new_resource}] Process environment configured")
|
||||
# Make sure to open the output file and write the pid file before we
|
||||
# drop privs.
|
||||
output = ::File.open(output_file, 'ab')
|
||||
IO.write(pid_file, Process.pid)
|
||||
Chef::Log.debug("[#{new_resource}] PID #{Process.pid} written to #{pid_file}")
|
||||
ent = Etc.getpwnam(new_resource.user)
|
||||
if Process.euid != ent.uid || Process.egid != ent.gid
|
||||
Process.initgroups(ent.name, ent.gid)
|
||||
Process::GID.change_privilege(ent.gid) if Process.egid != ent.gid
|
||||
Process::UID.change_privilege(ent.uid) if Process.euid != ent.uid
|
||||
Chef::Log.debug("[#{new_resource}] Changed privs to #{new_resource.user} (#{ent.uid}:#{ent.gid})")
|
||||
end
|
||||
# Log the command. Happens before ouput redirect or this ends up in the file.
|
||||
Chef::Log.debug("[#{new_resource}] Execing #{new_resource.command}")
|
||||
# Set up output logging.
|
||||
Chef::Log.debug("[#{new_resource}] Logging output to #{output_file}")
|
||||
$stdout.reopen(output)
|
||||
$stdout.sync = true
|
||||
$stderr.reopen(output)
|
||||
$stderr.sync = true
|
||||
$stdout.write("#{Time.now} Starting #{new_resource.command}")
|
||||
# Split the command so we don't get an extra sh -c.
|
||||
Kernel.exec(*Shellwords.split(new_resource.command))
|
||||
# Just in case, bail out.
|
||||
$stdout.reopen(STDOUT)
|
||||
$stderr.reopen(STDERR)
|
||||
Chef::Log.debug("[#{new_resource}] Exec failed, bailing out.")
|
||||
exit!
|
||||
rescue Exception => e
|
||||
# Welp, we tried.
|
||||
$stdout.reopen(STDOUT)
|
||||
$stderr.reopen(STDERR)
|
||||
Chef::Log.error("[#{new_resource}] Error during process spawn: #{e}")
|
||||
exit!
|
||||
end
|
||||
Chef::Log.debug("[#{new_resource}] Process environment configured")
|
||||
IO.write(pid_file, Process.pid)
|
||||
Chef::Log.debug("[#{new_resource}] PID written to #{pid_file}")
|
||||
ent = Etc.getpwnam(new_resource.user)
|
||||
if Process.euid != ent.uid || Process.egid != ent.gid
|
||||
Process.initgroups(ent.name, ent.gid)
|
||||
Process::GID.change_privilege(ent.gid) if Process.egid != ent.gid
|
||||
Process::UID.change_privilege(ent.uid) if Process.euid != ent.uid
|
||||
end
|
||||
Chef::Log.debug("[#{new_resource}] Changed privs to #{new_resource.user} (#{ent.uid}:#{ent.gid})")
|
||||
# Split the command so we don't get an extra sh -c.
|
||||
Chef::Log.debug("[#{new_resource}] Execing #{new_resource.command}")
|
||||
Kernel.exec(*Shellwords.split(new_resource.command))
|
||||
# Just in case, bail out.
|
||||
exit!
|
||||
# :nocov:
|
||||
end
|
||||
Chef::Log.debug("[#{new_resource}] Started.")
|
||||
end
|
||||
|
||||
def action_stop
|
||||
return if options['never_stop']
|
||||
return unless pid
|
||||
Chef::Log.debug("[#{new_resource}] Stopping with #{new_resource.stop_signal}. Current PID is #{pid.inspect}.")
|
||||
Process.kill(new_resource.stop_signal, pid)
|
||||
@@ -87,6 +119,8 @@ module PoiseService
|
||||
def action_restart
|
||||
return if options['never_restart']
|
||||
action_stop
|
||||
# Give things a moment to stop before we try starting again.
|
||||
sleep(options['restart_delay'])
|
||||
action_start
|
||||
end
|
||||
|
||||
@@ -151,6 +185,11 @@ module PoiseService
|
||||
"/var/run/#{new_resource.service_name}.pid"
|
||||
end
|
||||
|
||||
# Path to the output file.
|
||||
def output_file
|
||||
"/var/run/#{new_resource.service_name}.out"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,8 +27,6 @@ module PoiseService
|
||||
|
||||
# @api private
|
||||
def self.provides_auto?(node, resource)
|
||||
# Don't allow systemd under docker, it won't work in most cases.
|
||||
return false if node['virtualization'] && %w{docker lxc}.include?(node['virtualization']['system'])
|
||||
service_resource_hints.include?(:systemd)
|
||||
end
|
||||
|
||||
@@ -75,8 +73,10 @@ module PoiseService
|
||||
end
|
||||
|
||||
def destroy_service
|
||||
reloader = systemctl_daemon_reload
|
||||
file "/etc/systemd/system/#{new_resource.service_name}.service" do
|
||||
action :delete
|
||||
notifies :run, reloader, :immediately if options['auto_reload']
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ module PoiseService
|
||||
r.provider(case node['platform_family']
|
||||
when 'debian'
|
||||
Chef::Provider::Service::Debian
|
||||
when 'rhel'
|
||||
when 'rhel', 'amazon'
|
||||
Chef::Provider::Service::Redhat
|
||||
else
|
||||
# Better than nothing I guess? Will fail on enable I think.
|
||||
|
||||
@@ -30,11 +30,17 @@ module PoiseService
|
||||
provides(:upstart)
|
||||
|
||||
def self.provides_auto?(node, resource)
|
||||
# Don't allow upstart under docker, it won't work.
|
||||
return false if node['virtualization'] && %w{docker lxc}.include?(node['virtualization']['system'])
|
||||
service_resource_hints.include?(:upstart)
|
||||
end
|
||||
|
||||
# @api private
|
||||
def self.default_inversion_options(node, resource)
|
||||
super.merge({
|
||||
# Time to wait between stop and start.
|
||||
restart_delay: 1,
|
||||
})
|
||||
end
|
||||
|
||||
# True restart in Upstart preserves the original config data, we want the
|
||||
# more obvious behavior like everything else in the world that restart
|
||||
# would re-read the updated config file. Use stop+start to get this
|
||||
@@ -42,6 +48,8 @@ module PoiseService
|
||||
def action_restart
|
||||
return if options['never_restart']
|
||||
action_stop
|
||||
# Give things a moment to stop before we try starting again.
|
||||
sleep(options['restart_delay'])
|
||||
action_start
|
||||
end
|
||||
|
||||
|
||||
@@ -16,5 +16,5 @@
|
||||
|
||||
|
||||
module PoiseService
|
||||
VERSION = '1.4.2'
|
||||
VERSION = '1.5.2'
|
||||
end
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user