yakka
yakka

Reputation: 613

Run custom services on startup with puppet

I'm migrating our old process of doing our linux configurations to be managed by puppet but I'm having issues trying to figure out how to do this. We add some custom scripts to the init.d folder on our systems to manage some processes, and then these need this command executed on them to launch on startup:

update-rc.d $file defaults

So what I'm doing with puppet is that I have all these scripts residing a directory, and I copy them over to init.d. I then want to call 'exec' on each of these files with the former command and use the file name as an argument. This is what I have so far:

#copy init files    
file { '/etc/init.d/':
      ensure => 'directory',
      recurse => 'remote',
      source => ["puppet:///files/init_files/"],
      mode => 755,
      notify => Exec[echo],
    }

exec { "echo":
  command => "update-rc.d $file defaults",
  cwd => "/tmp", #directory to execute from
  path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:",
  refreshonly => true
}

This will copy all the files and it calls exec when something is added/updated, but what I can't figure out is how to pass the name of the file as an argument into the exec command. It seems I'm really close but I just can't find anything to help with what I need to do. Is this the right way to try and achieve this?

Thanks.

Upvotes: 2

Views: 6717

Answers (1)

ptierno
ptierno

Reputation: 10074

Your probably not going to accomplish that if your using ensure => 'directory'. You will want to declare the file resource for each individual init script. And the exec isn't the way to go to enable a service. Use the service resource.

 file { '/etc/init.d':
   ensure => 'directory',
   mode   => '0755'
 }

 file { '/etc/init.d/init_script_1':
   ensure => 'present',
   owner  => 'root',
   group  => 'root',
   mode   => '0755',
   notify => Service['init_script_1']
 }

 file { '/etc/init.d/init_script_2':
   ensure => 'present',
   owner  => 'root',
   group  => 'root',
   mode   => '0755',
   notify => Service['init_script_2']
 }

 service { 'init_script_1':
   ensure => running,
   enable => true
 }

 service { 'init_script_2':
   ensure => running,
   enable => true
 }

Hope this helps.

Upvotes: 4

Related Questions