Updated Branches: refs/heads/master 5a8a28af9 -> 5b84dc2a1
ACCUMULO-1960 Fall back onto sudo if the user doesn't run it as root and isn't running processes as their user for agitation. Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/35ff0e50 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/35ff0e50 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/35ff0e50 Branch: refs/heads/master Commit: 35ff0e50ad7d8678e66d193cc53be40f6a72956f Parents: cccdb8c Author: Josh Elser <els...@apache.org> Authored: Tue Dec 3 21:17:03 2013 -0500 Committer: Josh Elser <els...@apache.org> Committed: Tue Dec 3 21:17:03 2013 -0500 ---------------------------------------------------------------------- test/system/continuous/agitator.pl | 71 ++++++++++++++++---- .../system/continuous/continuous-env.sh.example | 3 +- test/system/continuous/start-agitator.sh | 14 +++- test/system/continuous/stop-agitator.sh | 8 ++- 4 files changed, 77 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/35ff0e50/test/system/continuous/agitator.pl ---------------------------------------------------------------------- diff --git a/test/system/continuous/agitator.pl b/test/system/continuous/agitator.pl index f1abcd5..faeb231 100755 --- a/test/system/continuous/agitator.pl +++ b/test/system/continuous/agitator.pl @@ -19,21 +19,22 @@ use POSIX qw(strftime); use Cwd qw(); -if(scalar(@ARGV) != 4 && scalar(@ARGV) != 2){ - print "Usage : agitator.pl <min sleep before kill in minutes>[:max sleep before kill in minutes] <min sleep before tup in minutes>[:max sleep before tup in minutes] [<min kill> <max kill>]\n"; +if(scalar(@ARGV) != 6 && scalar(@ARGV) != 4){ + print "Usage : agitator.pl <min sleep before kill in minutes>[:max sleep before kill in minutes] <min sleep before tup in minutes>[:max sleep before tup in minutes] hdfs_user accumulo_user [<min kill> <max kill>]\n"; exit(1); } -$ACCUMULO_USER='accumulo'; -$HDFS_USER='hdfs'; +$myself=`whoami`; +chomp($myself); +$am_root=($myself eq 'root'); $cwd=Cwd::cwd(); $ACCUMULO_HOME=$cwd . '/../../..'; $HADOOP_PREFIX=$ENV{"HADOOP_PREFIX"}; -print STDERR "Current directory: $cwd\n"; -print STDERR "ACCUMULO_HOME=$ACCUMULO_HOME\n"; -print STDERR "HADOOP_PREFIX=$HADOOP_PREFIX\n"; +print "Current directory: $cwd\n"; +print "ACCUMULO_HOME=$ACCUMULO_HOME\n"; +print "HADOOP_PREFIX=$HADOOP_PREFIX\n"; @sleeprange1 = split(/:/, $ARGV[0]); $sleep1 = $sleeprange1[0]; @@ -67,9 +68,15 @@ if(defined $ENV{'ACCUMULO_CONF_DIR'}){ $ACCUMULO_CONF_DIR = $ACCUMULO_HOME . '/conf'; } -if(scalar(@ARGV) == 4){ - $minKill = $ARGV[2]; - $maxKill = $ARGV[3]; +$HDFS_USER=$ARGV[2]; +$ACCUMULO_USER=$ARGV[3]; + +$am_hdfs_user=($HDFS_USER eq $myself); +$am_accumulo_user=($ACCUMULO_USER eq $myself); + +if(scalar(@ARGV) == 6){ + $minKill = $ARGV[4]; + $maxKill = $ARGV[5]; }else{ $minKill = 1; $maxKill = 1; @@ -133,11 +140,29 @@ while(1){ print STDERR "$t Killing $server $kill_tserver $kill_datanode\n"; if ($kill_tserver) { - system("su -c '$ACCUMULO_HOME/bin/stop-server.sh $server \"accumulo-start.jar\" tserver KILL' - $ACCUMULO_USER"); + if ($am_root) { + # We're root, switch to the Accumulo user and try to stop gracefully + system("su -c '$ACCUMULO_HOME/bin/stop-server.sh $server \"accumulo-start.jar\" tserver KILL' - $ACCUMULO_USER"); + } elsif ($am_accumulo_user) { + # We're the accumulo user, just run the commandj + system("$ACCUMULO_HOME/bin/stop-server.sh $server 'accumulo-start.jar' tserver KILL"); + } else { + # We're not the accumulo user, try to use sudo + system("sudo -u $ACCUMULO_USER $ACCUMULO_HOME/bin/stop-server.sh $server accumulo-start.jar tserver KILL"); + } } if ($kill_datanode) { - system("ssh $server pkill -9 -f [p]roc_datanode"); + if ($am_root) { + # We're root, switch to HDFS to ssh and kill the process + system("su -c 'ssh $server pkill -9 -f [p]roc_datanode' - $HDFS_USER"); + } elsif ($am_hdfs_user) { + # We're the HDFS user, just kill the process + system("ssh $server \"pkill -9 -f '[p]roc_datanode'\""); + } else { + # We're not the hdfs user, try to use sudo + system("ssh $server 'sudo -u $HDFS_USER pkill -9 -f \'[p]roc_datanode\''"); + } } } @@ -145,11 +170,29 @@ while(1){ sleep($nextsleep2 * 60); $t = strftime "%Y%m%d %H:%M:%S", localtime; print STDERR "$t Running tup\n"; - system("su -c $ACCUMULO_HOME/bin/tup.sh - $ACCUMULO_USER"); + if ($am_root) { + # Running as root, su to the accumulo user + system("su -c $ACCUMULO_HOME/bin/tup.sh - $ACCUMULO_USER"); + } elsif ($am_accumulo_user) { + # restart the as them as the accumulo user + system("$ACCUMULO_HOME/bin/tup.sh"); + } else { + # Not the accumulo user, try to sudo to the accumulo user + system("sudo -u $ACCUMULO_USER $ACCUMULO_HOME/bin/tup.sh"); + } if ($kill_datanode) { print STDERR "$t Starting datanode on $server\n"; - system("ssh $server 'su -c \"$HADOOP_PREFIX/sbin/hadoop-daemon.sh start datanode\" - $HDFS_USER'"); + if ($am_root) { + # We're root, switch to the HDFS user + system("ssh $server 'su -c \"$HADOOP_PREFIX/sbin/hadoop-daemon.sh start datanode\" - $HDFS_USER 2>/dev/null 1>/dev/null'"); + } elsif ($am_hdfs_user) { + # We can just start as we're the HDFS user + system("ssh $server '$HADOOP_PREFIX/sbin/hadoop-daemon.sh start datanode'"); + } else { + # Not the HDFS user, have to try sudo + system("ssh $server 'sudo -u $HDFS_USER $HADOOP_PREFIX/sbin/hadoop-daemon.sh start datanode'"); + } } $nextsleep1 = int(rand($sleep1max - $sleep1)) + $sleep1; http://git-wip-us.apache.org/repos/asf/accumulo/blob/35ff0e50/test/system/continuous/continuous-env.sh.example ---------------------------------------------------------------------- diff --git a/test/system/continuous/continuous-env.sh.example b/test/system/continuous/continuous-env.sh.example index af80081..7c23edc 100644 --- a/test/system/continuous/continuous-env.sh.example +++ b/test/system/continuous/continuous-env.sh.example @@ -24,7 +24,8 @@ ZOOKEEPER_HOME=${ZOOKEEPER_HOME:-/opt/zookeeper} CONTINUOUS_LOG_DIR=$ACCUMULO_HOME/test/system/continuous/logs INSTANCE_NAME=instance ZOO_KEEPERS=zhost1,zhost2 -ACCUMULO_USER=accumulo +ACCUMULO_USER=`whoami` +HDFS_USER=`whoami` USER=user PASS=pass TABLE=ci http://git-wip-us.apache.org/repos/asf/accumulo/blob/35ff0e50/test/system/continuous/start-agitator.sh ---------------------------------------------------------------------- diff --git a/test/system/continuous/start-agitator.sh b/test/system/continuous/start-agitator.sh index fd43a14..8c2bafb 100755 --- a/test/system/continuous/start-agitator.sh +++ b/test/system/continuous/start-agitator.sh @@ -21,6 +21,16 @@ export HADOOP_PREFIX mkdir -p $CONTINUOUS_LOG_DIR -nohup ./agitator.pl $KILL_SLEEP_TIME $TUP_SLEEP_TIME $MIN_KILL $MAX_KILL >$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_agitator.out 2>$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_agitator.err & +# Agitator needs to handle HDFS and Accumulo - can't switch to a single user and expect it to work +nohup ./agitator.pl $KILL_SLEEP_TIME $TUP_SLEEP_TIME $HDFS_USER $ACCUMULO_USER $MIN_KILL $MAX_KILL >$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_agitator.out 2>$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_agitator.err & -su -c "nohup $CONTINUOUS_CONF_DIR/magitator.pl $MASTER_KILL_SLEEP_TIME $MASTER_RESTART_SLEEP_TIME >$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_magitator.out 2>$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_magitator.err &" -m - $ACCUMULO_USER +if [[ "`whoami`" == "root" ]]; then + # Change to the correct user if started as root + su -c "nohup $CONTINUOUS_CONF_DIR/magitator.pl $MASTER_KILL_SLEEP_TIME $MASTER_RESTART_SLEEP_TIME >$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_magitator.out 2>$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_magitator.err &" -m - $ACCUMULO_USER +elif [[ "`whoami`" == $ACCUMULO_USER ]]; then + # Just run the magitator if we're the accumulo user + nohup $CONTINUOUS_CONF_DIR/magitator.pl $MASTER_KILL_SLEEP_TIME $MASTER_RESTART_SLEEP_TIME >$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_magitator.out 2>$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_magitator.err & +else + # Not root, and not the accumulo user, hope you can sudo to it + sudo -m -u $ACCUMULO_USER "nohup $CONTINUOUS_CONF_DIR/magitator.pl $MASTER_KILL_SLEEP_TIME $MASTER_RESTART_SLEEP_TIME >$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_magitator.out 2>$CONTINUOUS_LOG_DIR/`date +%Y%m%d%H%M%S`_`hostname`_magitator.err &" +fi http://git-wip-us.apache.org/repos/asf/accumulo/blob/35ff0e50/test/system/continuous/stop-agitator.sh ---------------------------------------------------------------------- diff --git a/test/system/continuous/stop-agitator.sh b/test/system/continuous/stop-agitator.sh index b853a55..8ce448e 100755 --- a/test/system/continuous/stop-agitator.sh +++ b/test/system/continuous/stop-agitator.sh @@ -1,5 +1,4 @@ #! /usr/bin/env bash - # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -18,5 +17,10 @@ CONTINUOUS_CONF_DIR=${CONTINUOUS_CONF_DIR:-$ACCUMULO_HOME/test/system/continuous/} . $CONTINUOUS_CONF_DIR/continuous-env.sh -pkill -f agitator.pl +# Try to use sudo when we wouldn't normally be able to kill the processes +if [[ ("`whoami`" != "root") && ("`whoami`" != $ACCUMULO_USER) ]]; then + sudo -u $ACCUMULO_USER pkill -f agitator.pl +else + pkill -f agitator.pl +fi