【问题标题】:chef centos 7 openvpn service厨师 centos 7 openvpn 服务
【发布时间】:2016-03-01 21:57:47
【问题描述】:

我的自定义说明书通过以下方式安装 openvpn:

package 'openvpn'

... do some configuration ....

service 'openvpn' do
  action [:enable, :start]
end

上面的代码在 centos 6 中运行良好,在 centos 7 (systemd) 中失败

错误:/bin/systemctl enable openvpn - 没有这样的文件或目录

似乎在 systemd 上服务的名称不同:openvpn@server 我如何检测到这个?

【问题讨论】:

    标签: chef-infra centos7


    【解决方案1】:

    您可以检查 platform_version(假设您已经在您的食谱中检查了 CentOS 的平台),然后即时切换 service_name。例如,启动 OpenVPN 服务器

    service 'openvpn_service' do
      if node['platform_version'].to_f >= 7.0
        service_name 'openvpn@server.service'
      else
        service_name 'openvpn'
      end
      action [ :enable, :start ]
    end
    

    【讨论】:

    • 感谢您的帮助。而不是检查 platform_version 我现在这样做: File.exists?('/usr/lib/systemd/system')
    猜你喜欢
    • 2015-12-04
    • 2015-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 2017-07-26
    • 1970-01-01
    相关资源
    最近更新 更多