What is best way to write puppet code - "stop crond if /filesystem is not mounted" (filesystem mount is taken care by Redhat Cluter)"

有帮助吗?

解决方案

exec is probably easiest way to deal with this :

exec { "stop_crond" :
   command => "service crond stop",
   path => "/sbin:/usr/sbin:/bin:/usr/bin",
   unless => 'mount | grep -oq "/filesystem"',
}

其他提示

I'd suggest writing a custom fact to check your filesystem mount. Using that variable, you can declare your crond service either stopped, or running, etc.

Alternatively, you could do something like an exec to stop crond, using onlyif to check the mount. For example, grepping for the name of your filesystem in the output of mount.

The custom fact approach is cleaner, more reliable, and better style; if you're in a rush, the exec should work fine.

Below works for me.

exec { "stop_crond":
command => "service crond stop",
path    => "/sbin:/usr/sbin:/bin:/usr/bin",
unless  => '/bin/cat /proc/mounts | /bin/grep -q \' /mnt \'';
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top