I am using debian squeeze with PostgreSQL 9.1 from backports. Puppet has version 2.7.14.
Unfortunatly the init script returns the wrong exit code for status. Therefore I wrote a custom status
command to detect whether postgresql is running or not.
service { 'postgresql':
ensure => running,
enable => true,
hasstatus => false,
hasrestart => true,
status => "pg_lsclusters -h | awk 'BEGIN {rc=0} {if ($4 != \"online\") rc=3} END { exit rc }'",
provider => debian,
}
My command works like a charme, but puppet seems to have a problem. I always get notice: /Stage[main]/Postgresql/Service[postgresql]/ensure: ensure changed 'stopped' to 'running'
although it is already running.
So tried the following:
service { 'postgresql':
ensure => running,
enable => true,
hasstatus => false,
hasrestart => true,
status => "exit 0",
provider => debian,
}
As I understood this custom status
command, puppet should always think that postgresql is running. Nevertheless puppet tries to start postgresql - every time.
What is my fault? Or is it a bug in puppet?
My best guesses are that the
$4
in your command is getting swallowed up by puppet's own interpolation and thatexit 0
doesn't quite work right due to shell interaction issues.I would try a few things.
$4
in your command escape the$
like so:status => "pg_lsclusters -h | awk 'BEGIN {rc=0} {if (\$4 != \"online\") rc=3} END { exit rc }'"
(sometimes more backslashes are required, but I'm pretty sure 1 is enough here).exit
is a shell internal and I'm not sure how puppet will treat that. So use the canonical "return success" command instead:status => "/bin/true"
Maybe
status
is being overridden byprovider => debian
(which would be a puppet bug), so instead specify all the commands and use the base provider (this won't enable properly, however):