Skip to content

Commit

Permalink
ACCUMULO-3666 sudo to user running accumulo before start/stop
Browse files Browse the repository at this point in the history
On a system where the test is running as a user other than
the user running Accumulo, we need to sudo to the Accumulo user.
  • Loading branch information
joshelser committed Mar 19, 2015
1 parent 838a5fc commit 7edfaf7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions TESTING.md
Expand Up @@ -88,6 +88,7 @@ The following properties can be used to configure a standalone cluster:
- `accumulo.it.cluster.standalone.hadoop.conf`, Required: `HADOOP_CONF_DIR`
- `accumulo.it.cluster.standalone.home`, Optional: `ACCUMULO_HOME`
- `accumulo.it.cluster.standalone.conf`, Optional: `ACCUMULO_CONF_DIR`
- `accumulo.it.cluster.standalone.server.user`, Optional: The user Accumulo is running as (used to sudo when starting/stopping Accumulo). Default "accumulo"

Additionally, when running with Kerberos enabled, it is required that Kerberos principals already exist
for the tests to use. As such, a number of properties exist to allow users to be passed down for tests
Expand Down
Expand Up @@ -52,16 +52,18 @@ public class StandaloneAccumuloCluster implements AccumuloCluster {
private String accumuloHome, accumuloConfDir, hadoopConfDir;
private Path tmp;
private List<ClusterUser> users;
private String serverUser;

public StandaloneAccumuloCluster(ClientConfiguration clientConf, Path tmp, List<ClusterUser> users) {
this(new ZooKeeperInstance(clientConf), clientConf, tmp, users);
public StandaloneAccumuloCluster(ClientConfiguration clientConf, Path tmp, List<ClusterUser> users, String serverUser) {
this(new ZooKeeperInstance(clientConf), clientConf, tmp, users, serverUser);
}

public StandaloneAccumuloCluster(Instance instance, ClientConfiguration clientConf, Path tmp, List<ClusterUser> users) {
public StandaloneAccumuloCluster(Instance instance, ClientConfiguration clientConf, Path tmp, List<ClusterUser> users, String serverUser) {
this.instance = instance;
this.clientConf = clientConf;
this.tmp = tmp;
this.users = users;
this.serverUser = serverUser;
}

public String getAccumuloHome() {
Expand Down Expand Up @@ -116,7 +118,7 @@ public ClientConfiguration getClientConfig() {

@Override
public StandaloneClusterControl getClusterControl() {
return new StandaloneClusterControl(null == accumuloHome ? System.getenv("ACCUMULO_HOME") : accumuloHome,
return new StandaloneClusterControl(serverUser, null == accumuloHome ? System.getenv("ACCUMULO_HOME") : accumuloHome,
null == accumuloConfDir ? System.getenv("ACCUMULO_CONF_DIR") : accumuloConfDir);
}

Expand Down
Expand Up @@ -45,20 +45,23 @@
public class StandaloneClusterControl implements ClusterControl {
private static final Logger log = LoggerFactory.getLogger(StandaloneClusterControl.class);

private static final String SUDO_CMD = "sudo";
private static final String START_SERVER_SCRIPT = "start-server.sh", ACCUMULO_SCRIPT = "accumulo", TOOL_SCRIPT = "tool.sh";
private static final String MASTER_HOSTS_FILE = "masters", GC_HOSTS_FILE = "gc", TSERVER_HOSTS_FILE = "slaves", TRACER_HOSTS_FILE = "tracers",
MONITOR_HOSTS_FILE = "monitor";

protected String user;
protected String accumuloHome, accumuloConfDir;
protected RemoteShellOptions options;

protected String startServerPath, accumuloPath, toolPath;

public StandaloneClusterControl() {
this(System.getenv("ACCUMULO_HOME"), System.getenv("ACCUMULO_CONF_DIR"));
public StandaloneClusterControl(String user) {
this(user, System.getenv("ACCUMULO_HOME"), System.getenv("ACCUMULO_CONF_DIR"));
}

public StandaloneClusterControl(String accumuloHome, String accumuloConfDir) {
public StandaloneClusterControl(String user, String accumuloHome, String accumuloConfDir) {
this.user = user;
this.options = new RemoteShellOptions();
this.accumuloHome = accumuloHome;
this.accumuloConfDir = accumuloConfDir;
Expand Down Expand Up @@ -132,7 +135,7 @@ public Entry<Integer,String> execMapreduceWithStdout(Class<?> clz, String[] args
public void adminStopAll() throws IOException {
File confDir = getConfDir();
String master = getHosts(new File(confDir, "masters")).get(0);
String[] cmd = new String[] {accumuloPath, Admin.class.getName(), "stopAll"};
String[] cmd = new String[] {SUDO_CMD, "-u", user, accumuloPath, Admin.class.getName(), "stopAll"};
Entry<Integer,String> pair = exec(master, cmd);
if (0 != pair.getKey().intValue()) {
throw new IOException("stopAll did not finish successfully, retcode=" + pair.getKey() + ", stdout=" + pair.getValue());
Expand Down Expand Up @@ -185,7 +188,7 @@ public void startAllServers(ServerType server) throws IOException {

@Override
public void start(ServerType server, String hostname) throws IOException {
String[] cmd = new String[] {startServerPath, hostname, getProcessString(server)};
String[] cmd = new String[] {SUDO_CMD, "-u", user, startServerPath, hostname, getProcessString(server)};
Entry<Integer,String> pair = exec(hostname, cmd);
if (0 != pair.getKey()) {
throw new IOException("Start " + server + " on " + hostname + " failed for execute successfully");
Expand Down Expand Up @@ -252,9 +255,9 @@ public void signal(ServerType server, String hostname, String signal) throws IOE

String[] stopCmd;
if (isSignalNumber) {
stopCmd = new String[] {"kill", "-" + signal, pid};
stopCmd = new String[] {SUDO_CMD, "-u", user, "kill", "-" + signal, pid};
} else {
stopCmd = new String[] {"kill", "-s", signal, pid};
stopCmd = new String[] {SUDO_CMD, "-u", user, "kill", "-s", signal, pid};
}

Entry<Integer,String> pair = exec(hostname, stopCmd);
Expand Down
Expand Up @@ -129,7 +129,7 @@ public void setupCluster() throws Exception {
case STANDALONE:
StandaloneAccumuloClusterConfiguration conf = (StandaloneAccumuloClusterConfiguration) clusterConf;
ClientConfiguration clientConf = conf.getClientConf();
StandaloneAccumuloCluster standaloneCluster = new StandaloneAccumuloCluster(conf.getInstance(), clientConf, conf.getTmpDirectory(), conf.getUsers());
StandaloneAccumuloCluster standaloneCluster = new StandaloneAccumuloCluster(conf.getInstance(), clientConf, conf.getTmpDirectory(), conf.getUsers(), conf.getAccumuloServerUser());
// If these are provided in the configuration, pass them into the cluster
standaloneCluster.setAccumuloHome(conf.getAccumuloHome());
standaloneCluster.setAccumuloConfDir(conf.getAccumuloConfDir());
Expand Down
Expand Up @@ -58,6 +58,8 @@ public class StandaloneAccumuloClusterConfiguration extends AccumuloClusterPrope
public static final String ACCUMULO_STANDALONE_INSTANCE_NAME_DEFAULT = "accumulo";
public static final String ACCUMULO_STANDALONE_TMP_DIR_KEY = ACCUMULO_STANDALONE_PREFIX + "tmpdir";
public static final String ACCUMULO_STANDALONE_TMP_DIR_DEFAULT = "/tmp";
public static final String ACCUMULO_STANDALONE_SERVER_USER = ACCUMULO_STANDALONE_PREFIX + "server.user";
public static final String ACCUMULO_STANDALONE_SERVER_USER_DEFAULT = "accumulo";

// A set of users we can use to connect to this instances
public static final String ACCUMULO_STANDALONE_USER_KEY = ACCUMULO_STANDALONE_PREFIX + "users.";
Expand All @@ -71,6 +73,7 @@ public class StandaloneAccumuloClusterConfiguration extends AccumuloClusterPrope
public static final String ACCUMULO_STANDALONE_HADOOP_CONF = ACCUMULO_STANDALONE_PREFIX + "hadoop.conf";

private Map<String,String> conf;
private String serverUser;
private File clientConfFile;
private ClientConfiguration clientConf;
private List<ClusterUser> clusterUsers;
Expand Down Expand Up @@ -98,6 +101,12 @@ public StandaloneAccumuloClusterConfiguration(File clientConfFile) {
clientConf.withZkHosts(getZooKeepers());
}

// The user Accumulo is running as
serverUser = conf.get(ACCUMULO_STANDALONE_SERVER_USER);
if (null == serverUser) {
serverUser = ACCUMULO_STANDALONE_SERVER_USER_DEFAULT;
}

clusterUsers = new ArrayList<>();
for (Entry<String,String> entry : conf.entrySet()) {
String key = entry.getKey();
Expand Down Expand Up @@ -230,4 +239,11 @@ public Path getTmpDirectory() {
public List<ClusterUser> getUsers() {
return Collections.unmodifiableList(clusterUsers);
}

/**
* @return The user Accumulo is running as
*/
public String getAccumuloServerUser() {
return serverUser;
}
}

0 comments on commit 7edfaf7

Please sign in to comment.