Notepad/enter/Coding Tips (Classical)/Terminal Tips/Shells/Computers (operating system)/Apple Macbook/Launchd.md

1.8 KiB

A MacOS specific version of a cron that automates scripts and programs.

In computing, launchd, a unified operating system service management framework, starts, stops and manages daemons, applications, processes, and scripts in macOS. It was introduced with Mac OS X Tiger and is licensed under the Apache License —Wikipedia

Here are some helpful tips;

View Services

sudo launchctl list

without Sudo

$ sudo launchctl list | grep ssh
-	0	com.openssh.sshd

$ launchctl list | grep ssh
3521	0	com.openssh.ssh-agent

Particular Service details

$ sudo launchctl list com.openssh.sshd
{
	"Wait" = false;
	"Sockets" = {
		"Listeners" = (
			file-descriptor-object;
			file-descriptor-object;
		);
	};
	"LimitLoadToSessionType" = "System";
	"StandardErrorPath" = "/dev/null";
	"Label" = "com.openssh.sshd";
	"inetdCompatibility" = true;
	"OnDemand" = true;
	"LastExitStatus" = 0;
	"Program" = "/usr/libexec/sshd-keygen-wrapper";
	"ProgramArguments" = (
		"/usr/sbin/sshd";
		"-i";
	);
};

Stop and start service:

sudo launchctl stop com.openssh.sshd

sudo launchctl start com.openssh.sshd

Service definition via print:

sudo launchctl print system/com.openssh.sshd

Loading Services

# load
sudo launchctl load /System/Library/LaunchDaemons/ssh.plist

# enable
sudo launchctl enable system/com.openssh.sshd

# disable
sudo launchctl disable system/com.openssh.sshd 

# unload
sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist

via Rakesh

A great launchd blog post on here too.