MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / mainEntryClickHouseStart

Function mainEntryClickHouseStart

programs/install/Install.cpp:1248–1306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1246
1247int mainEntryClickHouseStart(int argc, char ** argv);
1248int mainEntryClickHouseStart(int argc, char ** argv)
1249{
1250 try
1251 {
1252 po::options_description desc;
1253 desc.add_options()
1254 ("help,h", "produce help message")
1255 ("prefix", po::value<std::string>()->default_value("/"), "prefix for all paths")
1256#if defined (OS_DARWIN)
1257 /// https://stackoverflow.com/a/36734569/22422288
1258 ("binary-path", po::value<std::string>()->default_value("usr/local/bin"), "directory with binary")
1259#else
1260 ("binary-path", po::value<std::string>()->default_value("usr/bin"), "directory with binary")
1261#endif
1262 ("config-path", po::value<std::string>()->default_value("etc/clickhouse-server"), "directory with configs")
1263 ("pid-path", po::value<std::string>()->default_value("var/run/clickhouse-server"), "directory for pid file")
1264 ("user", po::value<std::string>()->default_value(DEFAULT_CLICKHOUSE_SERVER_USER), "clickhouse user")
1265 ("group", po::value<std::string>()->default_value(DEFAULT_CLICKHOUSE_SERVER_GROUP), "clickhouse group")
1266 ("no-sudo", po::bool_switch(), "use clickhouse su instead of sudo (useful when running in a Docker container)")
1267 ("max-tries", po::value<unsigned>()->default_value(60), "Max number of tries for waiting the server (with 1 second delay)")
1268 ;
1269
1270 po::variables_map options;
1271 po::store(po::parse_command_line(argc, argv, desc), options);
1272
1273 bool no_sudo = options["no-sudo"].as<bool>();
1274
1275 if (options.contains("help"))
1276 {
1277 std::cout << "Usage: " << formatWithSudo("clickhouse start", !no_sudo && getuid() != 0) << " [options]\n";
1278 std::cout << desc << "\n";
1279 return 0;
1280 }
1281
1282 std::string user = options["user"].as<std::string>();
1283 std::string group = options["group"].as<std::string>();
1284 /// `--group` has a default for help/documentation purposes only.
1285 /// It should be applied to the launched server only when the user
1286 /// explicitly requested it. Otherwise `clickhouse start --user alice`
1287 /// would force `-g clickhouse` (or `alice:clickhouse` on the no-sudo
1288 /// path), which fails when the user is not a member of `clickhouse`.
1289 if (options["group"].defaulted())
1290 group.clear();
1291
1292 fs::path prefix = options["prefix"].as<std::string>();
1293 fs::path binary = prefix / options["binary-path"].as<std::string>() / "clickhouse";
1294 fs::path executable = prefix / options["binary-path"].as<std::string>() / "clickhouse-server";
1295 fs::path config = prefix / options["config-path"].as<std::string>() / "config.xml";
1296 fs::path pid_file = prefix / options["pid-path"].as<std::string>() / "clickhouse-server.pid";
1297 unsigned max_tries = options["max-tries"].as<unsigned>();
1298
1299 return start(user, group, binary, executable, config, pid_file, max_tries, no_sudo);
1300 }
1301 catch (...)
1302 {
1303 std::cerr << getCurrentExceptionMessage(false) << '\n';
1304 return getCurrentExceptionCode();
1305 }

Callers

nothing calls this directly

Calls 8

storeFunction · 0.85
formatWithSudoFunction · 0.85
getCurrentExceptionCodeFunction · 0.85
add_optionsMethod · 0.80
startFunction · 0.70
containsMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected