[katello-devel] Q - should cmd line katello give non-zero exit status for this?

Ivan Nečas inecas at redhat.com
Tue Nov 1 16:44:18 UTC 2011


On 11/01/2011 04:57 PM, Mike McCune wrote:
> On 11/01/2011 08:54 AM, Cliff Perry wrote:
>>
>> [root at dhcp77-176 ~]# katello --username admin --password admin ping
>> ------------------------------------------------------------------------------------------------------------------------------------------- 
>>
>>                                                                
>> Katello Status
>>
>>   Status   Service          Result   Duration   Message
>> ------------------------------------------------------------------------------------------------------------------------------------------- 
>>
>>   ok
>>            candlepin        ok       45ms
>>            pulp_auth        ok       102ms
>>            pulp             ok       72ms
>>            candlepin_auth   ok       44ms
>> [root at dhcp77-176 ~]# echo $?
>> 0
>> [root at dhcp77-176 ~]# service tomcat6 stop
>> Stopping tomcat6:                                          [  OK  ]
>> [root at dhcp77-176 ~]# katello --username admin --password admin ping
>> ------------------------------------------------------------------------------------------------------------------------------------------- 
>>
>>                                                                
>> Katello Status
>>
>>   Status   Service          Result   Duration   Message
>>
>> ------------------------------------------------------------------------------------------------------------------------------------------- 
>>
>>   fail
>>
>>            candlepin        fail                Connection refused -
>> connect(2)
>>            pulp_auth        ok       60ms
>>
>>            pulp             ok       51ms
>>
>>            candlepin_auth   fail                Connection refused -
>> connect(2)
>> [root at dhcp77-176 ~]# echo $?
>> 0
>> [root at dhcp77-176 ~]#
>>
>> So the command ran fine, but it reported failures within the services it
>> is reporting.
>>
>> *IF* it returned non-zero we could automate easier a check at the end of
>> installation - without looking at the strings.
>>
>> So, should the command exit 0 for success, or 1 for failure in this use
>> case? :)
>
> I'd argue yes, it should return non-zero if any of the ping checks 
> fail.  Simple way to determine with that ping command if something is 
> broken if you wanted to cron it or use it in some other script.

We can also assign to each fail status different number and then we can 
use determine easily what failed.
Let's say:

candlepin: 2
candlepin_auth: 4
pulp: 8
pulp_auth: 16

exit status 6 would mean candlepin error, 20 would mean auth error for 
both pulp and candlepin.

To find out what failed in bash we could just use bitwise &

CODE=$?
if [ $[$CODE & 2] -ne 0 ] ; then echo "candlepin error, to fix..."; fi
if [ $[$CODE & 4] -ne 0 ] ; then echo "candlepin auth error, to fix.."; fi
...

Of course we could just grep the output, but I find this way a bit better.
>
> Mike
>
> _______________________________________________
> katello-devel mailing list
> katello-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/katello-devel


-- 
Regards,

  Ivan Necas
  Red Hat Czech s.r.o. Brno




More information about the katello-devel mailing list