Ejemplo n.º 1
0
  private int kill() throws CommandException {
    File prevPid = null;
    String pids = null;

    try {
      prevPid = new File(getServerDirs().getPidFile().getPath() + ".prev");

      if (!prevPid.canRead())
        throw new CommandException(Strings.get("StopInstance.nopidprev", prevPid));

      pids = FileUtils.readSmallFile(prevPid).trim();
      String s = ProcessUtils.kill(Integer.parseInt(pids));

      if (s != null) logger.finer(s);
    } catch (CommandException ce) {
      throw ce;
    } catch (Exception ex) {
      throw new CommandException(
          Strings.get("StopInstance.pidprevreaderror", prevPid, ex.getMessage()));
    }
    return 0;
  }
Ejemplo n.º 2
0
  public Config copyConfig(Configs configs, Config config, String destConfigName, Logger logger)
      throws PropertyVetoException, TransactionFailure {
    final Config destCopy = (Config) config.deepCopy(configs);
    if (systemproperties != null) {
      final Properties properties =
          GenericCrudCommand.convertStringToProperties(systemproperties, ':');

      for (final Object key : properties.keySet()) {
        final String propName = (String) key;
        // cannot update a system property so remove it first
        List<SystemProperty> sysprops = destCopy.getSystemProperty();
        for (SystemProperty sysprop : sysprops) {
          if (propName.equals(sysprop.getName())) {
            sysprops.remove(sysprop);
            break;
          }
        }
        SystemProperty newSysProp = destCopy.createChild(SystemProperty.class);
        newSysProp.setName(propName);
        newSysProp.setValue(properties.getProperty(propName));
        destCopy.getSystemProperty().add(newSysProp);
      }
    }
    final String configName = destConfigName;
    destCopy.setName(configName);
    configs.getConfig().add(destCopy);
    copyOfConfig = destCopy;

    String srcConfig = "";
    srcConfig = config.getName();

    File configConfigDir = new File(env.getConfigDirPath(), configName);
    for (Config c : configs.getConfig()) {
      File existingConfigConfigDir = new File(env.getConfigDirPath(), c.getName());
      if (!c.getName().equals(configName) && configConfigDir.equals(existingConfigConfigDir)) {
        throw new TransactionFailure(
            localStrings.getLocalString(
                "config.duplicate.dir",
                "Config {0} is trying to use the same directory as config {1}",
                configName,
                c.getName()));
      }
    }
    try {
      if (!(new File(configConfigDir, "docroot").mkdirs()
          && new File(configConfigDir, "lib/ext").mkdirs())) {
        throw new IOException(
            localStrings.getLocalString(
                "config.mkdirs", "error creating config specific directories"));
      }

      String srcConfigLoggingFile =
          env.getInstanceRoot().getAbsolutePath()
              + File.separator
              + "config"
              + File.separator
              + srcConfig
              + File.separator
              + ServerEnvironmentImpl.kLoggingPropertiesFileName;
      File src = new File(srcConfigLoggingFile);

      if (!src.exists()) {
        src = new File(env.getConfigDirPath(), ServerEnvironmentImpl.kLoggingPropertiesFileName);
      }

      File dest = new File(configConfigDir, ServerEnvironmentImpl.kLoggingPropertiesFileName);
      FileUtils.copy(src, dest);
    } catch (Exception e) {
      logger.log(Level.WARNING, ConfigApiLoggerInfo.copyConfigError, e.getLocalizedMessage());
    }
    return destCopy;
  }
Ejemplo n.º 3
0
 File getCanonicalFile(File f) {
   return FileUtils.safeGetCanonicalFile(f);
 }