Search code examples
chef-inframonit

On chef, using poise-service and poise-monit, how do I use systemd as the underlying


My underlying problem here is the use of the term provider. Monit is a provider to run and monitor service state. But monit in turn relies on a provider on the system to launch and stop services - sysinitv, upstart, systemd.

from cookbooks/poise-monit I see

Service Provider

The monit service provider is included to allow poise_service resources to use Monit as the service manager. This uses the normal sysvinit provider from poise-service to generate the init scripts, but manages service state through Monit.

Now, what I want to do is manage various processes, such as redis-server via Monit to manage state, but systemd does the underlying plumbing.

Should I do something like this:

#configuration file for redis
fnp_redis_conf = "#{node['redis']['conf_dir']}/redis.conf"

template fnp_redis_conf do
  source        "redis.conf.erb"
  owner         "root"
  group         "root"
  mode          "0644"
  variables     :redis => node['redis'], :redis_server => node['redis']['server']
end

#instructions for systemd
poise_service 'redis-server' do
  provider Chef::Provider::Service::Systemd
  command '/usr/local/bin/redis-server #{fnp_redis_conf}'
end

#instructions for monit to call on systemd
poise_service 'redis-server' do
  command 'systemctl start redis-server'
  provider :monit
end

Nice to have: starting monit itself under systemd rather than via /etc/init.d/monit.

environment:

macos 12 host
Ubuntu 16.04 guest
Chef Development Kit Version: 2.3.4
chef-client version: 13.4.19
delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427)
berks version: 6.3.1
kitchen version: 1.17.0
inspec version: 1.36.1

Solution

  • You would have to make your own service provider class because https://github.com/poise/poise-monit/blob/master/lib/poise_monit/service_providers/monit.rb is 100% hardwired to the sysvinit style (by virtue of being a subclass of it). I suppose I don't see much point in using monit and systemd together, systemd already tracks failed units and restarts them. You can reach me more directly on the Chef community slack.