int main(int argc, char** argv) { GOOGLE_PROTOBUF_VERIFY_VERSION; slave::Flags flags; // The following flags are executable specific (e.g., since we only // have one instance of libprocess per execution, we only want to // advertise the IP and port option once, here). Option<string> ip; flags.add(&ip, "ip", "IP address to listen on"); uint16_t port; flags.add(&port, "port", "Port to listen on", SlaveInfo().port()); string isolation; flags.add(&isolation, "isolation", "Isolation mechanism, may be one of: process, cgroups", "process"); Option<string> master; flags.add(&master, "master", "May be one of:\n" " zk://host1:port1,host2:port2,.../path\n" " zk://username:password@host1:port1,host2:port2,.../path\n" " file://path/to/file (where file contains one of the above)"); bool help; flags.add(&help, "help", "Prints this help message", false); Try<Nothing> load = flags.load("MESOS_", argc, argv); if (load.isError()) { cerr << load.error() << endl; usage(argv[0], flags); exit(1); } if (help) { usage(argv[0], flags); exit(1); } if (master.isNone()) { cerr << "Missing required option --master" << endl; exit(1); } // Initialize libprocess. if (ip.isSome()) { os::setenv("LIBPROCESS_IP", ip.get()); } os::setenv("LIBPROCESS_PORT", stringify(port)); process::initialize(); logging::initialize(argv[0], flags, true); // Catch signals. LOG(INFO) << "Creating \"" << isolation << "\" isolator"; Isolator* isolator = Isolator::create(isolation); if (isolator == NULL) { cerr << "Unrecognized isolation type: " << isolation << endl; exit(1); } LOG(INFO) << "Build: " << build::DATE << " by " << build::USER; LOG(INFO) << "Starting Mesos slave"; Try<MasterDetector*> detector = MasterDetector::create(master.get()); CHECK_SOME(detector) << "Failed to create a master detector"; Files files; Slave* slave = new Slave(flags, false, detector.get(), isolator, &files); process::spawn(slave); process::wait(slave->self()); delete slave; delete detector.get(); Isolator::destroy(isolator); return 0; }
int main(int argc, char** argv) { GOOGLE_PROTOBUF_VERIFY_VERSION; Configurator configurator; Logging::registerOptions(&configurator); Slave::registerOptions(&configurator); // The following options are executable specific (e.g., since we // only have one instance of libprocess per execution, we only want // to advertise the port and ip option once, here). configurator.addOption<int>("port", 'p', "Port to listen on", 0); configurator.addOption<string>("ip", "IP address to listen on"); configurator.addOption<string>("isolation", "Isolation module", "process"); #ifdef MESOS_WEBUI configurator.addOption<int>("webui_port", "Web UI port", 8081); #endif configurator.addOption<string>( "master", 'm', "May be one of:\n" " host:port\n" " zk://host1:port1,host2:port2,.../path\n" " zk://username:password@host1:port1,host2:port2,.../path\n" " file://path/to/file (where file contains one of the above)"); if (argc == 2 && string("--help") == argv[1]) { usage(argv[0], configurator); exit(1); } Configuration conf; try { conf = configurator.load(argc, argv); } catch (ConfigurationException& e) { cerr << "Configuration error: " << e.what() << endl; exit(1); } Logging::init(argv[0], conf); if (conf.contains("port")) { setenv("LIBPROCESS_PORT", conf["port"].c_str(), 1); } if (conf.contains("ip")) { setenv("LIBPROCESS_IP", conf["ip"].c_str(), 1); } // Initialize libprocess library (but not glog, done above). process::initialize(false); if (!conf.contains("master")) { cerr << "Missing required option --master (-m)" << endl; exit(1); } string master = conf["master"]; string isolation = conf["isolation"]; LOG(INFO) << "Creating \"" << isolation << "\" isolation module"; IsolationModule* isolationModule = IsolationModule::create(isolation); if (isolationModule == NULL) { cerr << "Unrecognized isolation type: " << isolation << endl; exit(1); } LOG(INFO) << "Build: " << build::DATE << " by " << build::USER; LOG(INFO) << "Starting Mesos slave"; if (chdir(dirname(argv[0])) != 0) { fatalerror("Could not chdir into %s", dirname(argv[0])); } Slave* slave = new Slave(conf, false, isolationModule); process::spawn(slave); Try<MasterDetector*> detector = MasterDetector::create(master, slave->self(), false, Logging::isQuiet(conf)); CHECK(detector.isSome()) << "Failed to create a master detector: " << detector.error(); #ifdef MESOS_WEBUI webui::start(slave->self(), conf); #endif process::wait(slave->self()); delete slave; MasterDetector::destroy(detector.get()); IsolationModule::destroy(isolationModule); return 0; }
int main(int argc, char** argv) { GOOGLE_PROTOBUF_VERIFY_VERSION; slave::Flags flags; // The following flags are executable specific (e.g., since we only // have one instance of libprocess per execution, we only want to // advertise the IP and port option once, here). Option<string> ip; flags.add(&ip, "ip", "IP address to listen on"); uint16_t port; flags.add(&port, "port", "Port to listen on", SlaveInfo().port()); Option<string> master; flags.add(&master, "master", "May be one of:\n" " zk://host1:port1,host2:port2,.../path\n" " zk://username:password@host1:port1,host2:port2,.../path\n" " file:///path/to/file (where file contains one of the above)"); bool help; flags.add(&help, "help", "Prints this help message", false); Try<Nothing> load = flags.load("MESOS_", argc, argv); if (load.isError()) { cerr << load.error() << endl; usage(argv[0], flags); EXIT(1); } if (help) { usage(argv[0], flags); EXIT(1); } if (flags.version) { version(); exit(0); } if (master.isNone()) { EXIT(1) << "Missing required option --master"; } // Initialize modules. Note that since other subsystems may depend // upon modules, we should initialize modules before anything else. if (flags.modules.isSome()) { Try<Nothing> result = ModuleManager::load(flags.modules.get()); if (result.isError()) { EXIT(1) << "Error loading modules: " << result.error(); } } // Initialize libprocess. if (ip.isSome()) { os::setenv("LIBPROCESS_IP", ip.get()); } os::setenv("LIBPROCESS_PORT", stringify(port)); process::initialize("slave(1)"); logging::initialize(argv[0], flags, true); // Catch signals. LOG(INFO) << "Build: " << build::DATE << " by " << build::USER; LOG(INFO) << "Version: " << MESOS_VERSION; if (build::GIT_TAG.isSome()) { LOG(INFO) << "Git tag: " << build::GIT_TAG.get(); } if (build::GIT_SHA.isSome()) { LOG(INFO) << "Git SHA: " << build::GIT_SHA.get(); } Try<Containerizer*> containerizer = Containerizer::create(flags, false); if (containerizer.isError()) { EXIT(1) << "Failed to create a containerizer: " << containerizer.error(); } Try<MasterDetector*> detector = MasterDetector::create(master.get()); if (detector.isError()) { EXIT(1) << "Failed to create a master detector: " << detector.error(); } LOG(INFO) << "Starting Mesos slave"; Files files; GarbageCollector gc; StatusUpdateManager statusUpdateManager(flags); Slave* slave = new Slave( flags, detector.get(), containerizer.get(), &files, &gc, &statusUpdateManager); process::spawn(slave); process::wait(slave->self()); delete slave; delete detector.get(); delete containerizer.get(); return 0; }