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 7f9cc93..e8f1b29 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 @@
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 @@
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 @@
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;