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

Function stop

programs/install/Install.cpp:1204–1243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1202 }
1203
1204 int stop(const fs::path & pid_file, bool force, bool do_not_kill, unsigned max_tries)
1205 {
1206 if (force && do_not_kill)
1207 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Specified flags are incompatible");
1208
1209 int signal = force ? SIGKILL : SIGTERM;
1210 const char * signal_name = force ? "kill" : "terminate";
1211
1212 if (sendSignalAndWaitForStop(pid_file, signal, max_tries, 1000, signal_name))
1213 return 0;
1214
1215 int pid = isRunning(pid_file, /*ignore_file_does_not_exist=*/ false);
1216 if (!pid)
1217 return 0;
1218
1219 if (do_not_kill)
1220 {
1221 fmt::print("Process (pid = {}) is still running. Will not try to kill it.\n", pid);
1222 return 1;
1223 }
1224
1225 /// Send termination signal again, the server will receive it and immediately terminate.
1226 fmt::print("Will send the termination signal again to force the termination (pid = {}).\n", pid);
1227 if (sendSignalAndWaitForStop(pid_file, signal, std::min(10U, max_tries), 1000, signal_name))
1228 return 0;
1229
1230 /// Send kill signal. Total wait is 100 seconds.
1231 constexpr size_t num_kill_check_tries = 1000;
1232 constexpr size_t kill_check_delay_ms = 100;
1233 fmt::print("Will terminate forcefully (pid = {}).\n", pid);
1234 if (sendSignalAndWaitForStop(pid_file, SIGKILL, num_kill_check_tries, kill_check_delay_ms, "kill"))
1235 return 0;
1236
1237 if (!isRunning(pid_file, /*ignore_file_does_not_exist=*/ true))
1238 return 0;
1239
1240 throw Exception(ErrorCodes::CANNOT_KILL,
1241 "The server process still exists after {} tries (delay: {} ms)",
1242 num_kill_check_tries, kill_check_delay_ms);
1243 }
1244}
1245
1246

Callers 15

stopQueueFunction · 0.85
~AsyncReaderMethod · 0.85
runActivityMethod · 0.85
~TCPServerMethod · 0.85
~HTTPServerMethod · 0.85
stopAllMethod · 0.85
~TimerMethod · 0.85
~ActiveDispatcherMethod · 0.85
~ActivityMethod · 0.85
mainEntryClickHouseStopFunction · 0.85

Calls 5

sendSignalAndWaitForStopFunction · 0.85
isRunningFunction · 0.85
ExceptionClass · 0.50
printFunction · 0.50
minFunction · 0.50

Tested by

no test coverage detected