MAC OS Start Service Optimization Advanced Chapter

Source: Internet
Author: User
Tags file system

The start-up service under Mac has three main places to configure:

1, login items, account, System Preferences

2,/system/library/startupitems and/library/startupitems/

3,LAUNCHD system initialization Process configuration.

The first two optimizations are relatively simple, this paper mainly introduces the third more complex launchd configuration optimization.

Launchd is a critical process for initializing the system environment under Mac OS. Similar to Linux under the INIT, RC.

Let's start by looking at how Mac OS x starts:

1,mac firmware Activates, initializes the hardware, and loads the BootX bootloader.

2,bootx load kernel and kernel extensions (kext).

3, the kernel starts the launchd process.

4,launchd according to/system/library/launchagents,/system/library/launchdaemons,/library/launchdaemons, Library/ Launchagents, ~/library/launchagents in the plist configuration, start the service daemon.

After watching Mac OS x start-up principle, we are not difficult to find/system/library/launchagents,/system/library/launchdaemons,/library/launchdaemons, Library /launchagents the Plist property file in five directories is the key to optimizing the system.

Here are some basic concepts to understand:

What are the differences between/system/library and/library and ~/library directories?

The/system/library directory is an apple-developed software store.

The/library directory is a third-party software stored by the system administrator.

~/library/is a third-party software that is stored by users themselves.

The difference between launchdaemons and launchagents?

Launchdaemons is the service (daemon) that the user started before logging in.

Launchagents is the service (daemon) that is started after the user logs on.

The plist file format and the meaning of each field in the five directories mentioned above:

Key Description Required
Label The name of the job Yes
Programarguments Strings to pass to the program when it is executed Yes
UserName The job would be is run as the given user, who necessarily is the one who submitted it to launchd. No
Inetdcompatibility Indicates that the daemon expects to be run as if it were launched by inetd No
Program The path to your executable. This key can save the Programarguments key for flags and arguments. No
OnDemand A Boolean flag that defines if a job runs continuously or not No
RootDirectory The job would be chrooted into another directory No
Serviceipc Whether The daemon can speak IPC to Launchd No
Watchpaths Allows Launchd to start a job based on modifications at a file-system path No
Queuedirectories Similar to Watchpath, a queue would only watch a empty directory for new files No
Startinterval Used to schedule a job this runs on a repeating schedule. Specified as the number of seconds to wait between runs. No
Startcalendarinterval Job scheduling. The syntax is similar to cron. No
Hardresourcelimits Controls restriction of the resources consumed by any job No
Lowpriorityio Tells the kernel that this task is of a low priority when doing file system I/O No
Sockets An array can is used to specify what socket the daemon would listen on for launch on demand No

Do not understand the above ground plist configuration? It doesn't matter, our optimization strategy is to completely uninstall the service, so we don't have to care about the configuration meaning in plist.

To start optimizing the Disable service, we need to use a tool directive provided by Mac OS-launchctl

The LAUNCHCTL directive sets a disable flag for the service, and when Launchd starts, it checks whether the service is disabled to determine whether the service needs to be enabled.

Method of disabling a service 1

Find the Disable flag file/var/db/launchd.db/com.apple.launchd/overrides.plist first, and see if the service you want to disable has been disabled.

Some services have been disabled, but not listed in Overrides.plist. At this point, you also need to check if the plist file for this service has a label field marked as Disable.

After confirming that the service is not disabled, we can disable the service by invoking the following command:

sudo launchctl unload plist file path

sudo launchctl unload-w plist file path

For example, if I want to disable Spotlight, enter

sudo launchctl unload/system/library/launchagents/com.apple.spotlight.plist

sudo launchctl unload-w/system/library/launchagents/com.apple.spotlight.plist

When the service is disabled, restarting the Mac OS can take effect.

Method 2 for disabling services, a more effective and violent approach (recommended)

Uninstall the service first

sudo launchctl unload/system/library/launchagents/com.apple.spotlight.plist

Then the plist file mv to a different directory backup. Reboot. Get. Isn't it simple!

I personally prefer this way of disabling the service, so recommend it.

If the discovery service is disabled and the system or software has an exception, you can restore the service by using the following command:

Method 1:

sudo launchctl load-wf plist file path

Method 2:

The backup plist file mv back to the original folder.

sudo launchctl load plist file path

Note: Disable system-level services with caution, before disabling Google, make sure you are familiar with the role of this service. Doing so may cause the system to fail to start.

The safest thing to do is not to disable it.

Of course, the user Service we can still be assured that disabled, there is a problem at most again to enable Bai.

Here is the list of services I disabled:

/system/library/launchdaemons/com.apple.metadata.mds.plist (prerequisite for disabling Spotlight)

/system/library/launchagents/com.apple.spotlight.plist (Spotlight)

/library/launchdaemons/com.google.keystone.daemon.plist (Google software Update)

/library/launchagents/com.google.keystone.root.agent (Google software Update)

~/library/launchagents/com.google.keystone.agent.plist (Google software Update, the process under the user does not need to add sudo)

~/library/launchagents/com.apple.csconfigdotmaccert-ken.wug@me.com-sharedservices.agent.plist (me.com sharing service, I don't need to)

/system/library/launchdaemons/org.cups.cupsd.plist (printer)

/system/library/launchdaemons/org.cups.cups-lpd.plist (printer)

/system/library/launchdaemons/com.apple.blued.plist (Bluetooth)

/system/library/launchagents/com.apple.airportbasestationagent.plist (Apple Wireless Base station, I don't have this device)

Know the Daemon (service) name, how to find the corresponding plist file?

Copy the process (service) name and then to/system/library/launchagents,/system/library/launchdaemons,/library/launchdaemons, Library/ Launchagents, ~/library/launchagents five directories, search by the following command:

Ll|grep process (Service) name

Like what

Ll|grep blued

It was found in the/system/library/launchdaemons. Next, please follow the instructions above to disable the service.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.