From: Mark Slee Date: Mon, 27 Oct 2008 22:45:26 +0000 (+0000) Subject: THRIFT-183 let non-root issues run fb303 status commands X-Git-Tag: 0.2.0~419 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=babaea2f0f2700bd46760d06f35095f89cd33d57;p=common%2Fthrift.git THRIFT-183 let non-root issues run fb303 status commands Reviewed By: mcslee git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@708364 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/contrib/fb303/py/fb303_scripts/fb303_simple_mgmt.py b/contrib/fb303/py/fb303_scripts/fb303_simple_mgmt.py index 7f9cc935..e8f1b29d 100644 --- a/contrib/fb303/py/fb303_scripts/fb303_simple_mgmt.py +++ b/contrib/fb303/py/fb303_scripts/fb303_simple_mgmt.py @@ -34,11 +34,6 @@ def service_ctrl( TBinaryProtocolFactory """ - # Only root should be able to run these scripts, although we could relax this for some of the operations. - if os.getuid() != 0: - print "requires root." - return 4 - if command in ["status"]: try: status = fb303_wrapper('status', port, trans_factory, prot_factory) @@ -57,15 +52,6 @@ def service_ctrl( print "Failed to get status" return 3 - # async commands - if command in ["stop","reload"]: - try: - fb303_wrapper(command, port, trans_factory, prot_factory) - return 0 - except: - print "failed to tell the service to ", command - return 3 - # scalar commands if command in ["version","alive","name"]: try: @@ -87,6 +73,31 @@ def service_ctrl( print "failed to get counters" return 3 + + # Only root should be able to run the following commands + if os.getuid() == 0: + # async commands + if command in ["stop","reload"] : + try: + fb303_wrapper(command, port, trans_factory, prot_factory) + return 0 + except: + print "failed to tell the service to ", command + return 3 + else: + if command in ["stop","reload"]: + print "root privileges are required to stop or reload the service." + return 4 + + print "The following commands are available:" + for command in ["counters","name","version","alive","status"]: + print "\t%s" % command + print "The following commands are available for users with root privileges:" + for command in ["stop","reload"]: + print "\t%s" % command + + + return 0;