Ask Your Question

service status check

asked 2016-03-01 21:08:52 -0600

ulankford gravatar image

updated 2016-03-04 00:57:27 -0600

The init script I have for a service I am managing in puppet is all messed up so instead of using the standard 'ensure = > running' and waiting for an exit code of 0 or 1 I have to write my own status check, as follows

 service { 'myservice':
    ensure    => 'running',
    hasstatus => false,
    status    => 'ps -ef | grep "connector-logging.jar:/opt/gsa/Connectors/Oracle/Tomcat/bin/bootstrap.jar" | grep -v grep | cut -d \' \' -f5,
    enable    => true,

When I run the ps command on the command line it works, as in it returns the PID when the service is running and doesn't return anything if the service is stopped. Yet, when I run puppet agent it doesn't do anything if the service is stopped.

As a side note when I change the status command from using cut to awk, like so.

status    => 'ps -ef | grep "connector-logging.jar:/opt/gsa/Connectors/Oracle/Tomcat/bin/bootstrap.jar" | grep -v grep | awk {\'print \$2\'}',

Running puppet with this status check will entail that the service is never running and will also attempt to start it even though the process already exists.

Does anyone have experience with these status checks for the service reference type?

edit retag flag offensive close merge delete


I wonder, how does that sub-command even work? Don't you get any error for awk for cut?

Mr_Sharma gravatar imageMr_Sharma ( 2016-03-02 08:53:06 -0600 )edit

No errors at all when I use the same command on the command-line. I have played around with using single quotes and double quotes and escape characters. I have come to a stage where if the service is running it ignores it (which is correct) but if the service is stopped nothing...

ulankford gravatar imageulankford ( 2016-03-04 01:19:02 -0600 )edit

Puppet runs commands in a very limited shell env. Have you tried putting the full path to all the commands in there? It's possible one is failing along the way because puppet can't find it, but the final cut or awk still returns.

lavaman gravatar imagelavaman ( 2016-03-04 17:41:33 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-03-06 23:43:28 -0600

ulankford gravatar image

After a bit of towing and froing I managed to create a simpler check

status    => '/etc/init.d/gsac status | /bin/grep -q "is running"',

For others be careful as you will have to work with the correct escape characters to get puppet to interpret the command.

edit flag offensive delete link more


does the status check the return value 0 or 1? or "is running" or "not running", how does the service judge that and start/stop service accordingly ?

jamwu2 gravatar imagejamwu2 ( 2018-05-09 06:32:47 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-03-01 21:08:52 -0600

Seen: 2,134 times

Last updated: Mar 06 '16