How to use a custom status command for a service in puppet?

My best guesses are that the $4 in your command is getting swallowed up by puppet's own interpolation and that exit 0 doesn't quite work right due to shell interaction issues.

I would try a few things.

  1. If the problem is puppet's interpolation on $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).
  2. Make sure the test command is really working right. 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"
  3. Maybe status is being overridden by provider => debian (which would be a puppet bug), so instead specify all the commands and use the base provider (this won't enable properly, however):

    service { 'postgresql':
      provider => base,
      ensure   => 'running',
      start    => '/etc/init.d/postgresql start',
      restart  => '/etc/init.d/postgresql restart',
      stop     => '/etc/init.d/postgresql stop',
      status   => "pg_lsclusters -h | awk 'BEGIN {rc=0} {if (\$4 != \"online\") rc=3} END { exit rc }'",
    }