在 Chef 上,使用 poise-service 和 poise-monit,我如何使用 systemd 作为底层

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

我这里的根本问题是术语 provider 的使用。 Monit 是 运行 和监控服务状态的提供者。但是 monit 又依赖于系统上的 provider 来启动和停止服务——sysinitv、upstart、systemd。

来自cookbooks/poise-monit我看到了

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.

现在,我想做的是管理各种进程,例如 redis-server 通过 Monit 来管理状态,但是 systemd 做底层管道。

我应该这样做吗:

#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

很高兴:在 systemd 下而不是通过 /etc/init.d/monit 启动 monit 自身

环境:

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

您必须创建自己的服务提供商 class,因为 https://github.com/poise/poise-monit/blob/master/lib/poise_monit/service_providers/monit.rb 是 100% 硬连线到 sysvinit 样式(由于是它的子class)。我想我认为一起使用 monit 和 systemd 没有多大意义,systemd 已经跟踪失败的单元并重新启动它们。您可以在 Chef community slack 上更直接地联系我。