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

Function stop

programs/install/Install.cpp:684–743  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

682 }
683
684 int stop(const fs::path & pid_file, bool force)
685 {
686 UInt64 pid = isRunning(pid_file);
687
688 if (!pid)
689 return 0;
690
691 int signal = force ? SIGKILL : SIGTERM;
692 const char * signal_name = force ? "kill" : "terminate";
693
694 if (0 == kill(pid, signal))
695 fmt::print("Sent {} signal to process with pid {}.\n", signal_name, pid);
696 else
697 throwFromErrno(fmt::format("Cannot send {} signal", signal_name), ErrorCodes::SYSTEM_ERROR);
698
699 size_t try_num = 0;
700 constexpr size_t num_tries = 60;
701 for (; try_num < num_tries; ++try_num)
702 {
703 fmt::print("Waiting for server to stop\n");
704 if (!isRunning(pid_file))
705 {
706 fmt::print("Server stopped\n");
707 break;
708 }
709 sleepForSeconds(1);
710 }
711
712 if (try_num == num_tries)
713 {
714 fmt::print("Will terminate forcefully.\n", pid);
715 if (0 == kill(pid, 9))
716 fmt::print("Sent kill signal.\n", pid);
717 else
718 throwFromErrno("Cannot send kill signal", ErrorCodes::SYSTEM_ERROR);
719
720 /// Wait for the process (100 seconds).
721 constexpr size_t num_kill_check_tries = 1000;
722 constexpr size_t kill_check_delay_ms = 100;
723 for (size_t i = 0; i < num_kill_check_tries; ++i)
724 {
725 fmt::print("Waiting for server to be killed\n");
726 if (!isRunning(pid_file))
727 {
728 fmt::print("Server exited\n");
729 break;
730 }
731 sleepForMilliseconds(kill_check_delay_ms);
732 }
733
734 if (isRunning(pid_file))
735 {
736 throw Exception(ErrorCodes::CANNOT_KILL,
737 "The server process still exists after %zu ms",
738 num_kill_check_tries, kill_check_delay_ms);
739 }
740 }
741

Callers 15

mainEntryClickHouseStopFunction · 0.85
stopMethod · 0.85
~HTTPServerMethod · 0.85
stopAllMethod · 0.85
~VWQueueSyncThreadMethod · 0.85
~TraceCollectorMethod · 0.85
~StorageElectorMethod · 0.85
yieldLeadershipMethod · 0.85

Calls 7

isRunningFunction · 0.85
killFunction · 0.85
throwFromErrnoFunction · 0.85
sleepForSecondsFunction · 0.85
sleepForMillisecondsFunction · 0.85
printFunction · 0.50
ExceptionClass · 0.50

Tested by

no test coverage detected