]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_common.sh: Do not sudo to root unless needed
authorTommi Virtanen <tommi.virtanen@dreamhost.com>
Mon, 19 Sep 2011 16:47:11 +0000 (09:47 -0700)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Mon, 19 Sep 2011 16:47:11 +0000 (09:47 -0700)
Using do_root_cmd() doesn't really need to sudo to root
if you're already root.

Commit 71dc75bdafe62a098c0493ad62f2d0d2a6ca7946 causes a regression:
when system "foo" has a sudoers config that requires a tty,
init-ceph now fails like this:
  sudo: sorry, you must have a tty to run sudo

when it is invoked by root with something like this:
   ssh foo /etc/init.d/init-ceph start

Signed-off-by: Jim Schutt <jaschut@sandia.gov>
Signed-off-by: Tommi Virtanen <tommi.virtanen@dreamhost.com>
src/ceph_common.sh

index adb8783f4e9a7a88f494a75f460b7946974d7666..1da42bd9436ce85f84e34330e304bc90960d8533 100644 (file)
@@ -97,7 +97,12 @@ do_root_cmd() {
     if [ -z "$ssh" ]; then
        [ $verbose -eq 1 ] && echo "--- $host# $1"
        ulimit -c unlimited
-       sudo bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
+       whoami=`whoami`
+       if [ "$whoami" = "root" ]; then
+           bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
+       else
+           sudo bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
+       fi
     else
        [ $verbose -eq 1 ] && echo "--- $rootssh $2 \"cd $sshdir ; ulimit -c unlimited ; $1\""
        $rootssh $2 "cd $sshdir ; ulimit -c unlimited ; $1" || { echo "failed: '$rootssh $1'" ; exit 1; }