我使用木偶来(理论上)让npcd在安装时启动,但是在Ubuntu上,这个服务安装在RUN =“no”的/ etc / default / npcd默认设置中:
$ cat /etc/default/npcd # Default settings for the NPCD init script. # Should NPCD be started? ("yes" to enable) RUN="no" # Additional options that are passed to the daemon. DAEMON_OPTS="-d -f /etc/pnp4nagios/npcd.cfg"
我会认为这块木偶configuration会照顾的事情:
service { "npcd": enable => true, ensure => "running", require => Package["pnp4nagios"], }
但是,可惜的是,它并没有实际重写/ etc / default中的文件,我不知道该怎么办。 有没有一种简单的方法来启用我没有看到的服务?
为了logging,我使用Ubuntu 12.04.2和puppet版本3.1.0。
更新该文件然后重新启动服务是唯一的方法。 您可以推送一个新文件,然后使该服务需要; 当内容更新时,服务将正常启动。
如果您不想完全replace文件,则可以使用Puppet augeas工具修改默认文件中的单行。
Debian及其衍生产品中有一些服务在软件包安装后不能自动启动,除非它在/ etc / default中启用。 有点讨厌。
编辑:仅供参考初始化脚本实际上是读取该文件的值(通常只是采购)。
对于它的地狱,我检查了我的12.04机器上的一些标准的守护进程。 你必须pipe理这个文件,这个时候没有办法。
SNMPD
# snmpd control (yes means start daemon). SNMPDRUN=yes
collectd
# 0: start collectd on boot, 1: do not start collectd on boot # default: 0 DISABLE=0
木偶
# Start puppet on boot? START=yes
mdadm的
# START_DAEMON: # should mdadm start the MD monitoring daemon during boot? START_DAEMON=true
HAProxy的
# Set ENABLED to 1 if you want the init script to start haproxy. ENABLED=1
我认为可行的方法之一就是使用augeas工具与木偶,例如
augeas { "npcd_default": changes => [ "set /files/etc/default/npcd/Run yes", ], }
有关详细信息,请参阅手册
我使用sed来修改文件。 奥吉亚似乎是矫枉过正。
sed -i /etc/default/puppet -e 's/START=no/START=yes/'
从这里采取的想法:
http://www.codelord.net/2010/12/19/using-puppet-to-automatically-configure-new-ec2-instances/
所以,在你的情况
sed -i /etc/default/npcd -e 's/RUN="no"/RUN="yes"/'
这样做与augeastypes在傀儡是一种方式(由@DukeLionbuild议)。
另一种方法是使用shellvar提供者的augeasproviders模块 :
shellvar { 'npcd_default': ensure => present, target => '/etc/default/npcd', variable => 'RUN', value => 'yes', comment => 'We want npcd to run', }
这样做比较好,因为Ruby提供商会干净地使用Augeas。 它也将自动pipe理报价和评论。