Puppet: create service before file but notify service if file changes
I want file "run" to be created AFTER Service nginx, but also i want to notify Service nginx if file run changes. Notify implies that it is run BEFORE nginx.
The use case is the following. We use dj bernsteins daemontools for managing nginx. Since we need to do some steps (creating /etc/service, adding the run files.. ) we build a defined type which does these things. Now we dont want our nginx module to have any connection to the daemontools module, thats why we dont want to subscribe to a daemontools file. Also subscribe would turn around the dependency cycle. Im searching for something like, only run module when module nginx is completely finished.
class { daemontools:
file {'run':
require => Service[nginx],
notify => Service[nginx]; # <<< this wont do :(
}
}
class { nginx:
service { 'nginx': }
}
Any ideas?
Thomas
You could try using using stages if your use case can handle its limitations.
stage { 'first':
before => Stage['main'],
}
stage { 'last': }
Stage['main'] -> Stage['last']
class { daemontools:
stage => last;
file {'run':
require => Service[nginx],
notify => Service[nginx];
}
}
class { nginx:
stage => last;
service { 'nginx': }
}
it was not an easy task, since the problem changes after the first run. The problem described in my question only applies when the server which has to be configured is completely new.
First run: wait for all files to be copied (class nginx complete) and then place the run file
Second run: take the usual approach of a notify on the run file. this time it can run before the service. this does not work on the first run.
So we solved it by adding an additional "state" file called nginx-ready
so in our defined type add_daemontools.pp
define daemontools::add_service {
file { "/etc/service/${service}/run":
ensure => file,
mode => 0755,
owner => root,
group => root,
content => template("daemontools/service.erb"),
path => "/etc/service/$service/run",
# create run file when service is ready
require => File["/var/run/${service}-ready"],
# notify implies before
notify => Service["${service}"],
}
}
and in our module we create the ready file which depends on everything necessary.
class nginx ( ... params) {
...
file { '/var/run/nginx-ready':
require => [ Package[$nginx_dependencies], File[$nginx_files] ],
before => Service['nginx'],
content => 'ready file for daemontools',
}
}
thank you very much for your help!