Skip to content

MacOS: incorrect status when calling Service.Status without root privilege. #400

@cuonglm

Description

@cuonglm

I wrote a service named ctrld, after installing, verifying that the service is running:

$ sudo ./ctrld status
Jul 17 15:27:34.000 NTC Service is running
$ ./ctrld status
Jul 17 15:27:27.000 NTC Service is stopped

Querying the status using launchctl confirms this:

$ sudo launchctl list ctrld
{
	"StandardOutPath" = "/usr/local/var/log/ctrld.out.log";
	"LimitLoadToSessionType" = "System";
	"StandardErrorPath" = "/usr/local/var/log/ctrld.err.log";
	"Label" = "ctrld";
	"OnDemand" = false;
	"LastExitStatus" = 0;
	"PID" = 11444;
	"Program" = "/Users/cuonglm/ctrld";
	"ProgramArguments" = (
		"/Users/cuonglm/ctrld";
		"run";
		"--cd=p2";
		"--iface=auto";
		"--homedir=/etc/controld";
		"--config=/etc/controld/ctrld.toml";
	);
};
$ launchctl list ctrld
Could not find service "ctrld" in domain for port

The problem seems to be this line:

if !strings.Contains(err.Error(), "failed with stderr") {

Specifically, this condition !strings.Contains(err.Error(), "failed with stderr") is the culprit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions