시작된 서비스를 어떻게 중지할 수 있나요?

시작된 서비스를 어떻게 중지할 수 있나요?

라벨이 붙은 서비스가 시작되었습니다 homebrew.mxcl.postgresql.

$ launchctl list homebrew.mxcl.postgresql
{
    "LimitLoadToSessionType" = "Aqua";
    "StandardErrorPath" = "/usr/local/var/log/postgres.log";
    "Label" = "homebrew.mxcl.postgresql";
    "TimeOut" = 30;
    "OnDemand" = false;
    "LastExitStatus" = 0;
    "PID" = 5436;
    "Program" = "/usr/local/opt/postgresql/bin/postgres";
    "ProgramArguments" = (
        "/usr/local/opt/postgresql/bin/postgres";
        "-D";
        "/usr/local/var/postgres";
    );
};

이 서비스를 중단하고 싶습니다! 그러나 명백한 stop명령은 작동하지 않습니다. 대신 새 PID로 서비스를 다시 시작합니다.

$ launchctl stop homebrew.mxcl.postgresql
$ launchctl list homebrew.mxcl.postgresql
{
    "LimitLoadToSessionType" = "Aqua";
    "StandardErrorPath" = "/usr/local/var/log/postgres.log";
    "Label" = "homebrew.mxcl.postgresql";
    "TimeOut" = 30;
    "OnDemand" = false;
    "LastExitStatus" = 0;
    "PID" = 5819;
    "Program" = "/usr/local/opt/postgresql/bin/postgres";
    "ProgramArguments" = (
        "/usr/local/opt/postgresql/bin/postgres";
        "-D";
        "/usr/local/var/postgres";
    );
};

실제로 서비스를 중지하려면 어떻게 해야 합니까?

답변1

중지된 작업은 시작되어야 하는 경우 즉시 다시 시작됩니다. 대신 서비스를 언로드해야 합니다.

launchctl unload homebrew.mxcl.postgresql

영구적으로 비활성화하려면 -w스위치도 지정하십시오.

launchctl unload -w homebrew.mxcl.postgresql

Homebrew의 경우에도 있습니다.홈브류 서비스. 설치하려면:

brew tap homebrew/services

그러면 서비스를 더 쉽게 시작하고 중지할 수 있습니다.

brew services start postgresql
brew services stop postgresql

관련 정보