void FarmStarter::killFarm() {
	boost::filesystem::path execPath(Options::GetString(OPTION_FARM_EXEC_PATH));
	LOG_ERROR << "Killing " << execPath.filename() << ENDL;

	signal(SIGCHLD, SIG_IGN);
	if (farmPID_ > 0) {
		kill(farmPID_, SIGTERM);
//		wait((int*) NULL);
//		waitpid(farmPID_, 0,WNOHANG);
	}
	system(std::string("killall -9 " + execPath.filename().string()).data());
	farmPID_ = 0;
}
void FarmStarter::startFarm(std::vector<std::string> params) {
	LOG_INFO << "Starting farm with following parameters: ";
	for (std::string param : params) {
		LOG_INFO << param << " ";
	}
	LOG_INFO << ENDL;

	if (Options::GetBool(OPTION_IS_MERGER)) {
		sleep(1);
	}

	if (farmPID_ > 0) {
		killFarm();
		sleep(3);
	}

	farmPID_ = fork();
	if (farmPID_ == 0) {
		boost::filesystem::path execPath(
				Options::GetString(OPTION_FARM_EXEC_PATH));

		LOG_INFO << "Starting farm program " << execPath.string() << ENDL;

		char* argv[params.size() + 2];
		argv[0] = (char*) execPath.filename().string().data();

		for (unsigned int i = 0; i < params.size(); i++) {
			argv[i + 1] = (char*) params[i].data();
		}
		argv[params.size() + 1] = NULL;

		execv(execPath.string().data(), argv);
		LOG_ERROR << "Main farm program stopped!" << ENDL;
		farmPID_ = -1;

		exit(0);
	} else if (farmPID_ == -1) {
		LOG_ERROR << "Forking failed! Unable to start the farm program!"
				<< ENDL;
	}
//myConnector_->sendState(OFF);
}
Exemplo n.º 3
0
  static std::string guess_app_from_path(int argc, const char *argv[])
  {
    boost::filesystem::path execPath(argv[0], qi::unicodeFacet());
    execPath = boost::filesystem::system_complete(execPath).make_preferred();
    execPath = boost::filesystem::path(detail::normalizePath(execPath.string(qi::unicodeFacet())), qi::unicodeFacet());

    //arg0 does not exists, or is not a program (directory)
    if (!boost::filesystem::exists(execPath) || boost::filesystem::is_directory(execPath))
    {
      std::string filename = execPath.filename().string(qi::unicodeFacet());
      std::string envPath = qi::os::getenv("PATH");
      size_t begin = 0;
#ifndef _WIN32
      size_t end = envPath.find(":", begin);
#else
      size_t end = envPath.find(";", begin);
#endif
      while (end != std::string::npos)
      {
        std::string realPath = "";

        realPath = envPath.substr(begin, end - begin);
        boost::filesystem::path p(realPath, qi::unicodeFacet());
        p /= filename;
        p = boost::filesystem::system_complete(p).make_preferred();
        p = boost::filesystem::path(detail::normalizePath(p.string(qi::unicodeFacet())), qi::unicodeFacet());

        if (boost::filesystem::exists(p) && !boost::filesystem::is_directory(p))
          return p.string(qi::unicodeFacet());

        begin = end + 1;
#ifndef _WIN32
        end = envPath.find(":", begin);
#else
        end = envPath.find(";", begin);
#endif
      }
    }
    else
      return execPath.string(qi::unicodeFacet());
    return std::string();
  }
Exemplo n.º 4
0
  SDKLayout* getInstance()
  {
    if (gInstance == NULL) {
      std::string prefix;
      std::string mode;
      const char *program = qi::program();

      if (!boost::filesystem::exists(program)) {
        mode = "error";
      }

      boost::filesystem::path execPath(program, qi::unicodeFacet());
      execPath = boost::filesystem::system_complete(execPath).make_preferred();
      prefix = execPath.parent_path().parent_path().string(qi::unicodeFacet());
      if (execPath.parent_path().filename().string(qi::unicodeFacet()) != "bin")
        mode = execPath.parent_path().filename().string(qi::unicodeFacet());
      else
        mode = "";

      gInstance = new SDKLayout(prefix, mode);
    }

    return gInstance;
  }
Exemplo n.º 5
0
 static std::string guess_app_from_path(const char* path)
 {
   boost::filesystem::path execPath(path, qi::unicodeFacet());
   return system_absolute(execPath).make_preferred()
     .string(qi::unicodeFacet());
 }