In this case you could be kinda sneaky and use the 'onlyif' parameter:onlyif => "/usr/sbin/squid -k parse",
exec { "reload-squid":
command => "/etc/init.d/squid reload",
subscribe => Exec["check-squid"],
refreshonly => true,
}
Though in all honesty your init script should be doing that check (the one I just looked at for my setup does) so you could just you the service type.
Well, here's what I ended up with. It's kind of hack, but I don't see
a better way at the moment to foolproof it.
class squid {
$bak_ext = ".puppet-bak"
package { "squid":
ensure => installed
}
file { "squid.conf":
path => "/etc/squid/squid.conf",
ensure => file,
owner => "root",
group => "squid",
mode => 0640,
backup => $bak_ext,
source => [
"puppet:///squid/squid/config/squid.conf"
],
}
service { "squid":
ensure => running,
hasstatus => true,
hasrestart => true,
require => [ Package["squid"], File["squid.conf"] ]
}
exec { "reload-squid":
command =>
"/usr/sbin/squid -k parse && /etc/init.d/squid reload ||
( /bin/cp -pr /etc/squid/squid.conf{${bak_ext},}
/usr/sbin/squid -k parse && /etc/init.d/squid
reload && /bin/false )",
subscribe => File["squid.conf"],
refreshonly => true,
}
exec { "cleanup-squid":
command => "/bin/rm -f /etc/squid/squid.conf${bak-ext}",
subscribe => Exec["reload-squid"],
refreshonly => true,
}
}
class squid::squidguard inherits squid {
package { "squidguard":
ensure => installed
}
file { "squidguard.conf":
path => "/etc/squid/squidguard.conf",
ensure => file,
owner => "root",
group => "squid",
mode => 0640,
backup => $bak_ext,
source => [
"puppet:///squid/squidguard/config/squidguard.conf"
],
}
file { "blacklists":
path => "/var/lib/squidguard/blacklists",
ensure => directory,
owner => "root",
group => "squid",
mode => 0640,
recurse => true,
ignore => ".svn",
backup => $bak_ext,
source => [
"puppet:///squid/squidguard/blacklists"
],
}
exec { "rebuild-squidguard-db":
command =>
"/usr/bin/squidGuard -C all ||
( /bin/cp -pr /etc/squid/squidguard.conf{${bak_ext},}
for i in `find /var/lib/squidguard/blacklists
-name '*${bak_ext}'`; do
cp -pr \$i \${i%${bak_ext}}
done
/usr/bin/squidGuard -C all && /bin/false )",
subscribe => [ File["squidguard.conf"], File["blacklists"] ],
refreshonly => true,
}
exec { "apply-squidguard-diffs":
command => "/usr/bin/squidGuard -u",
subscribe => Exec["rebuild-squidguard-db"],
refreshonly => true,
}
exec { "cleanup-squidguard":
command => "/bin/rm -f /etc/squid/squidguard.conf${bak_ext}
/bin/rm -f `find
/var/lib/squidguard/blacklists -name '*${bak_ext}'` || /bin/true",
subscribe => Exec["reload-squid"],
refreshonly => true,
}
Service["squid"] {
require +> [ Package["squidguard"], File["squidguard.conf"],
File["blacklists"] ]
}
Exec["reload-squid"] {
subscribe +> [ Exec["rebuild-squidguard-db"],
Exec["apply-squidguard-diffs"] ],
}
}