Skip to content

Commit

Permalink
THRIFT-183 let non-root issues run fb303 status commands
Browse files Browse the repository at this point in the history
Reviewed By: mcslee



git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@708364 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mcslee committed Oct 27, 2008
1 parent 444e51b commit 4fdf4d2
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions contrib/fb303/py/fb303_scripts/fb303_simple_mgmt.py
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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;


Expand Down

0 comments on commit 4fdf4d2

Please sign in to comment.