Ask Your Question
0

service status check

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

ulankford gravatar image

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

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

Comments

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

rajeevsharma gravatar imagerajeevsharma ( 2016-03-02 08:53:06 -0500 )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 -0500 )edit
1

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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

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

Stats

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

Seen: 843 times

Last updated: Mar 06 '16