public synchronized void open() throws IOException { // TODO (jon) be less strict. ?? need to return on and figure out why thisis // wrong, add // latches. // Preconditions.checkState(state == ManagerState.CLOSED, // "Must be in CLOSED state to open, currently " + state); // make the dirs if they do not exist if (!FileUtil.makeDirs(importDir)) { throw new IOException("Unable to create import dir: " + importDir); } if (!FileUtil.makeDirs(writingDir)) { throw new IOException("Unable to create writing dir: " + writingDir); } if (!FileUtil.makeDirs(loggedDir)) { throw new IOException("Unable to create logged dir: " + loggedDir); } if (!FileUtil.makeDirs(sendingDir)) { throw new IOException("Unable to create sending dir: " + sendingDir); } if (!FileUtil.makeDirs(errorDir)) { throw new IOException("Unable to create error dir: " + sendingDir); } state = ManagerState.OPEN; }
/** * This function checks the agent logs dir to make sure that the process has the ability to the * directory if necessary, that the path if it does exist is a directory, and that it can in fact * create files inside of the directory. If it fails any of these, it throws an exception. * * <p>Finally, it checks to see if the path is in /tmp and warns the user that this may not be the * best idea. */ public static void nodeConfigChecksOk() throws IOException { // TODO (jon) if we add more checks in here, make the different managers // responsible for throwing an Exception on construction instead. FlumeConfiguration conf = FlumeConfiguration.get(); String s = conf.getAgentLogsDir(); File f = new File(s); if (!FileUtil.makeDirs(f)) { throw new IOException("Path to Log dir cannot be created: '" + s + "'. Check permissions?"); } if (!f.isDirectory()) { throw new IOException("Log dir '" + s + "' already exists as a file. Check log dir path."); } File f2 = null; try { f2 = File.createTempFile("initcheck", ".test", f); } catch (IOException e) { throw new IOException("Failure to write in log directory: '" + s + "'. Check permissions?"); } if (!f2.delete()) { throw new IOException( "Unable to delete " + f2 + " from log directory " + "(but writing succeeded) - something is strange here"); } File tmp = new File("/tmp"); File cur = f; while (cur != null) { if (cur.equals(tmp)) { LOG.warn("Log directory is writing inside of /tmp. This data may not survive reboot!"); break; } cur = cur.getParentFile(); } }