| 1386 | |
| 1387 | int mainEntryClickHouseRestart(int argc, char ** argv); |
| 1388 | int mainEntryClickHouseRestart(int argc, char ** argv) |
| 1389 | { |
| 1390 | try |
| 1391 | { |
| 1392 | po::options_description desc; |
| 1393 | desc.add_options() |
| 1394 | ("help,h", "produce help message") |
| 1395 | ("prefix", po::value<std::string>()->default_value("/"), "prefix for all paths") |
| 1396 | #if defined (OS_DARWIN) |
| 1397 | /// https://stackoverflow.com/a/36734569/22422288 |
| 1398 | ("binary-path", po::value<std::string>()->default_value("usr/local/bin"), "directory with binary") |
| 1399 | #else |
| 1400 | ("binary-path", po::value<std::string>()->default_value("usr/bin"), "directory with binary") |
| 1401 | #endif |
| 1402 | ("config-path", po::value<std::string>()->default_value("etc/clickhouse-server"), "directory with configs") |
| 1403 | ("pid-path", po::value<std::string>()->default_value("var/run/clickhouse-server"), "directory for pid file") |
| 1404 | ("user", po::value<std::string>()->default_value(DEFAULT_CLICKHOUSE_SERVER_USER), "clickhouse user") |
| 1405 | ("group", po::value<std::string>()->default_value(DEFAULT_CLICKHOUSE_SERVER_GROUP), "clickhouse group") |
| 1406 | ("no-sudo", po::bool_switch(), "use clickhouse su instead of sudo (useful when running in a Docker container)") |
| 1407 | ("force", po::value<bool>()->default_value(false), "Stop with KILL signal instead of TERM") |
| 1408 | ("do-not-kill", po::bool_switch(), "Do not send KILL even if TERM did not help") |
| 1409 | ("max-tries", po::value<unsigned>()->default_value(60), "Max number of tries for waiting the server (with 1 second delay)") |
| 1410 | ; |
| 1411 | |
| 1412 | po::variables_map options; |
| 1413 | po::store(po::parse_command_line(argc, argv, desc), options); |
| 1414 | |
| 1415 | bool no_sudo = options["no-sudo"].as<bool>(); |
| 1416 | |
| 1417 | if (options.contains("help")) |
| 1418 | { |
| 1419 | std::cout << "Usage: " << formatWithSudo("clickhouse restart", !no_sudo && getuid() != 0) << " [options]\n"; |
| 1420 | std::cout << desc << "\n"; |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
| 1424 | std::string user = options["user"].as<std::string>(); |
| 1425 | std::string group = options["group"].as<std::string>(); |
| 1426 | /// See the comment in `mainEntryClickHouseStart`: only apply `--group` |
| 1427 | /// when the user explicitly provided it. |
| 1428 | if (options["group"].defaulted()) |
| 1429 | group.clear(); |
| 1430 | |
| 1431 | fs::path prefix = options["prefix"].as<std::string>(); |
| 1432 | fs::path binary = prefix / options["binary-path"].as<std::string>() / "clickhouse"; |
| 1433 | fs::path executable = prefix / options["binary-path"].as<std::string>() / "clickhouse-server"; |
| 1434 | fs::path config = prefix / options["config-path"].as<std::string>() / "config.xml"; |
| 1435 | fs::path pid_file = prefix / options["pid-path"].as<std::string>() / "clickhouse-server.pid"; |
| 1436 | |
| 1437 | bool force = options["force"].as<bool>(); |
| 1438 | bool do_not_kill = options["do-not-kill"].as<bool>(); |
| 1439 | unsigned max_tries = options["max-tries"].as<unsigned>(); |
| 1440 | |
| 1441 | if (int res = stop(pid_file, force, do_not_kill, max_tries)) |
| 1442 | return res; |
| 1443 | return start(user, group, binary, executable, config, pid_file, max_tries, no_sudo); |
| 1444 | } |
| 1445 | catch (...) |
nothing calls this directly
no test coverage detected