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

Function isRunning

programs/install/Install.cpp:1131–1175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1129 }
1130
1131 int isRunning(const fs::path & pid_file, bool ignore_file_does_not_exist)
1132 {
1133 int pid = 0;
1134
1135 try
1136 {
1137 ReadBufferFromFile in(pid_file.string());
1138 if (tryReadIntText(pid, in))
1139 {
1140 fmt::print("{} file exists and contains pid = {}.\n", pid_file.string(), pid);
1141 }
1142 else
1143 {
1144 fmt::print("{} file exists but damaged, ignoring (the file will be removed).\n", pid_file.string());
1145 (void)fs::remove(pid_file);
1146 }
1147 }
1148 catch (const Exception & e)
1149 {
1150 if (!ignore_file_does_not_exist || e.code() != ErrorCodes::FILE_DOESNT_EXIST)
1151 throw;
1152 }
1153
1154 if (pid)
1155 {
1156 if (0 == kill(pid, 0))
1157 {
1158 fmt::print("The process with pid = {} is running.\n", pid);
1159 }
1160 else if (errno == ESRCH)
1161 {
1162 fmt::print("The process with pid = {} does not exist.\n", pid);
1163 return 0;
1164 }
1165 else
1166 throw ErrnoException(ErrorCodes::CANNOT_KILL, "Cannot obtain the status of pid {} with `kill`", pid);
1167 }
1168
1169 if (!pid)
1170 {
1171 fmt::print("Now there is no clickhouse-server process.\n");
1172 }
1173
1174 return pid;
1175 }
1176
1177 bool sendSignalAndWaitForStop(const fs::path & pid_file, int signal, unsigned max_tries, unsigned wait_ms, const char * signal_name)
1178 {

Callers 3

sendSignalAndWaitForStopFunction · 0.85
stopFunction · 0.85

Calls 6

ErrnoExceptionClass · 0.85
tryReadIntTextFunction · 0.50
printFunction · 0.50
removeFunction · 0.50
stringMethod · 0.45
codeMethod · 0.45

Tested by

no test coverage detected