service icon indicating copy to clipboard operation
service copied to clipboard

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

Open cuonglm opened this issue 1 year ago • 0 comments

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:

https://github.com/kardianos/service/blob/becf2eb62b83ed01f5e782cb8da7bb739ded2bb5/service_darwin.go#L219

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

cuonglm avatar Jul 17 '24 08:07 cuonglm