test_class.declarator: pidFile
test_class.original_string: File pidFile;
test_class.type: File
test_class.var_name: pidFile
test_class.file: cosmic-common/src/test/java/com/cloud/utils/ProcessUtilTest.java
test_class.identifier: ProcessUtilTest
test_case.body: @Test
      public void pidCheck() throws ConfigurationException, IOException {
          Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
          FileUtils.writeStringToFile(pidFile, "123456\n");
          ProcessUtil.pidCheck(pidFile.getParent(), pidFile.getName());
          final String pidStr = FileUtils.readFileToString(pidFile);
          Assert.assertFalse("pid can not be blank", pidStr.isEmpty());
          final int pid = Integer.parseInt(pidStr.trim());
          final int maxPid = Integer.parseInt(FileUtils.readFileToString(new File("/proc/sys/kernel/pid_max")).trim());
          Assert.assertTrue(pid <= maxPid);
      }
test_case.class_method_signature: ProcessUtilTest.pidCheck()
test_case.full_signature: @Test public void pidCheck()
test_case.identifier: pidCheck
test_case.invocations: assumeTrue writeStringToFile pidCheck getParent getName readFileToString assertFalse isEmpty parseInt trim parseInt trim readFileToString assertTrue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void pidCheck()
focal_class.declarator: s_logger = LoggerFactory.getLogger(ProcessUtil.class.getName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger s_logger = LoggerFactory.getLogger(ProcessUtil.class.getName());
focal_class.type: Logger
focal_class.var_name: s_logger
focal_class.file: cosmic-common/src/main/java/com/cloud/utils/ProcessUtil.java
focal_class.identifier: ProcessUtil
focal_class.class_method_signature: ProcessUtil.pidCheck(final String pidDir, final String run)
focal_class.full_signature: public static void pidCheck(final String pidDir, final String run)
focal_class.identifier: pidCheck
focal_class.modifiers: public static
focal_class.parameters: (final String pidDir, final String run)
focal_class.return: void
focal_class.signature: void pidCheck(final String pidDir, final String run)
focal_class.class_method_signature: ProcessUtil.dumpStack()
focal_class.full_signature: public static String dumpStack()
focal_class.identifier: dumpStack
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String dumpStack()
focal_method.body: public static void pidCheck(final String pidDir, final String run) throws ConfigurationException {
  
          String dir = pidDir == null ? "/var/run" : pidDir;
  
          try {
              final File propsFile = PropertiesUtil.findConfigFile("environment.properties");
              if (propsFile == null) {
                  s_logger.debug("environment.properties could not be opened");
              } else {
                  final Properties props = PropertiesUtil.loadFromFile(propsFile);
                  dir = props.getProperty("paths.pid");
                  if (dir == null) {
                      dir = pidDir == null ? "/var/run" : pidDir;
                  }
              }
          } catch (final IOException e) {
              s_logger.debug("environment.properties could not be opened");
          }
  
          final File pidFile = new File(dir + File.separator + run);
          try {
              if (!pidFile.createNewFile()) {
                  if (!pidFile.exists()) {
                      throw new ConfigurationException("Unable to write to " + pidFile.getAbsolutePath() + ".  Are you sure you're running as root?");
                  }
  
                  final String pidLine = FileUtils.readFileToString(pidFile).trim();
                  if (pidLine.isEmpty()) {
                      throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
                  }
                  try {
                      final long pid = Long.parseLong(pidLine);
                      final Script script = new Script("bash", 120000, s_logger);
                      script.add("-c", "ps -p " + pid);
                      final String result = script.execute();
                      if (result == null) {
                          throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
                      }
                      if (!pidFile.delete()) {
                          throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
                      }
                      if (!pidFile.createNewFile()) {
                          throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
                      }
                  } catch (final NumberFormatException e) {
                      throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
                  }
              }
              pidFile.deleteOnExit();
  
              final Script script = new Script("bash", 120000, s_logger);
              script.add("-c", "echo $PPID");
              final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
              script.execute(parser);
  
              final String pid = parser.getLine();
  
              FileUtils.writeStringToFile(pidFile, pid + "\n");
          } catch (final IOException e) {
              throw new CloudRuntimeException("Unable to create the " + pidFile.getAbsolutePath() + ".  Are you running as root?", e);
          }
      }
focal_method.class_method_signature: ProcessUtil.pidCheck(final String pidDir, final String run)
focal_method.full_signature: public static void pidCheck(final String pidDir, final String run)
focal_method.identifier: pidCheck
focal_method.invocations: findConfigFile debug loadFromFile getProperty debug createNewFile exists getAbsolutePath trim readFileToString isEmpty getAbsolutePath parseLong add execute getAbsolutePath delete getAbsolutePath createNewFile getAbsolutePath getAbsolutePath deleteOnExit add execute getLine writeStringToFile getAbsolutePath
focal_method.modifiers: public static
focal_method.parameters: (final String pidDir, final String run)
focal_method.return: void
focal_method.signature: void pidCheck(final String pidDir, final String run)