如何在 Puppet 中提供启动服务文件
How to provide a startup service file in Puppet
我们有 RedHat 7.2 Linux OS 并使用 puppet 来执行我们的任务。我正在使用 puppet 安装一些软件,效果很好,现在最后一步是创建 OS 级别的服务。在早期版本的 RHEL 中,我们使用 chkconfig,但已被 systemctl 取代。当然,执行此任务的推荐方法是使用服务。由于这是一个自定义软件,我有自己的启动脚本,我通常将其复制到 /etc/init.d, 运行 chkconfig 然后启动服务。我如何通过 Puppet for RedHat 7.2 OS 执行这些任务?我只想创建服务(不启动它或任何东西)。这样,当服务器重新启动时,服务将启动应用程序。
编辑:
@redstonemercury for RHEL 7 我认为需要以下内容。但是你的建议肯定对我有帮助,因为我也是这么想的。
https://serverfault.com/questions/814611/puppet-generated-systemd-unit-files
file { '/lib/systemd/system/myservice.service':
mode => '0644',
owner => 'root',
group => 'root',
content => template('modulename/myservice.systemd.erb'),
}~>
exec { 'myservice-systemd-reload':
command => 'systemctl daemon-reload',
path => [ '/usr/bin', '/bin', '/usr/sbin' ],
refreshonly => true,
}
在 puppet 中,使用包资源安装包(假设它在您已经声明的 repos 中),然后使用文件资源声明 /etc/init.d 文件,并将 require => Package[<package_resource_name>]
作为文件声明中的参数,以确保在安装包后创建自定义文件(因此不会被包的 /etc/init.d 文件覆盖)。例如:
package { 'mypackage':
ensure => present,
}
file { '/etc/init.d/mypackage':
ensure => present,
content => template('mypackage/myinitd'),
require => Package['mypackage'],
}
这是如果你想使用模板。对于文件,而不是内容使用来源:source => puppet://modules/mypackage/myinitd
我们有 RedHat 7.2 Linux OS 并使用 puppet 来执行我们的任务。我正在使用 puppet 安装一些软件,效果很好,现在最后一步是创建 OS 级别的服务。在早期版本的 RHEL 中,我们使用 chkconfig,但已被 systemctl 取代。当然,执行此任务的推荐方法是使用服务。由于这是一个自定义软件,我有自己的启动脚本,我通常将其复制到 /etc/init.d, 运行 chkconfig 然后启动服务。我如何通过 Puppet for RedHat 7.2 OS 执行这些任务?我只想创建服务(不启动它或任何东西)。这样,当服务器重新启动时,服务将启动应用程序。
编辑:
@redstonemercury for RHEL 7 我认为需要以下内容。但是你的建议肯定对我有帮助,因为我也是这么想的。
https://serverfault.com/questions/814611/puppet-generated-systemd-unit-files
file { '/lib/systemd/system/myservice.service':
mode => '0644',
owner => 'root',
group => 'root',
content => template('modulename/myservice.systemd.erb'),
}~>
exec { 'myservice-systemd-reload':
command => 'systemctl daemon-reload',
path => [ '/usr/bin', '/bin', '/usr/sbin' ],
refreshonly => true,
}
在 puppet 中,使用包资源安装包(假设它在您已经声明的 repos 中),然后使用文件资源声明 /etc/init.d 文件,并将 require => Package[<package_resource_name>]
作为文件声明中的参数,以确保在安装包后创建自定义文件(因此不会被包的 /etc/init.d 文件覆盖)。例如:
package { 'mypackage':
ensure => present,
}
file { '/etc/init.d/mypackage':
ensure => present,
content => template('mypackage/myinitd'),
require => Package['mypackage'],
}
这是如果你想使用模板。对于文件,而不是内容使用来源:source => puppet://modules/mypackage/myinitd