Quantcast
Channel: Busylog.net » by example
Viewing all articles
Browse latest Browse all 19

MAC OSX BOOT sequence ( launchd )

$
0
0
Screen-Shot-2012-07-28-at-9.59.28-PM.png

Os x boot sequence  : what is launched at startup of your Mac can be easily discovered :
System Preferences” -> “Users & Groups” -> “Login Items”

screen shot 2012 07 28 at 9 59 28 pm1 300x237 MAC OSX BOOT sequence ( launchd ) trick osx os x boot sequence by example
Btw not all are there…

#1 MAC Boot sequence

Who knows boot sequence of Linux will find similar MAC OSX startup sequence… really MAC OSX boot sequece is similar to whichever computer OS.
The sequence :
screen shot 2012 07 28 at 9 54 38 pm 1024x768 MAC OSX BOOT sequence ( launchd ) trick osx os x boot sequence by example
In power on step (as you probably figured out) EFI selects the right device to use : you can overwrite this pressing “options” key during startup.
Btw after that BootROM, EFI, Boot Loader and  Kernel have done their work the control passes to launchd.
Launchd is in fact the first process that Kernel starts (PID is 1) and it starts the “user space” boot sequence

 busycrack$ ps aux | grep launchd
root               1   0.0  0.1…0:07.95 /sbin/launchd

So Launchd has in charge to start System and Users daemon/agent basing its task on plist files here :
~/Library/LaunchAgents Per-user agents provided by the user
/Library/LaunchAgents  Per-user agents provided by the administrator
/Library/LaunchDaemons System-wide daemons provided by the administrator  
/System/Library/LaunchAgents    Per-user agents provided by Mac OS X
/System/Library/LaunchDaemons  System wide daemons provided by MAC OS X

For example in my home directory I have:

 

busycrack$ ls -ltra
total 24
-rw-r–r–@  1 busycrack  staff   806 Jul 11 20:59 com.google.keystone.agent.plist
-rw-r–r–   1 busycrack  staff   697 Jul 20 22:25 com.*****.XXXXX.YYYYYYY-1.0.plist
drwx——@ 55 busycrack  staff  1870 Jul 28 18:06 ..
-rw-r–r–   1 busycrack  staff   606 Jul 28 18:40 de.metaquark.appfresh.plist

 

Launchd is controlled by command launchctl … below some notes about launchctl

#a) list all with command “lauchctl list”

 

busycrack$ launchctl list 
-       0       de.metaquark.appfresh
581     –       [0x0-0x4b04b].de.metaquark.appfresh
-       0       com.apple.metadata.mdwrite

 

Where :

PID Last Exit Status Job Label
581  - [0x0-0x4b04b].de.metaquark.appfres
  -   0 de.metaquark.appfresh

#b) get details : ”lauchctl list de.metaquark.appfresh”

 

busycrack$ launchctl list de.metaquark.appfresh
{
        “Label” = “de.metaquark.appfresh”;
        “LimitLoadToSessionType” = “Aqua”;
        “OnDemand” = true;
        “LastExitStatus” = 0;
        “TimeOut” = 30;
        “ProgramArguments” = (
                “/Applications/AppFresh.app/Contents/Resources/AppFreshDaemon”;
                “/Applications/AppFresh.app”;
        );
};

 

#c) list all which is not by apple :launchctl list | grep -v com.apple”

In order to discover not apple deamon generally I do :

 

busycrack$ launchctl list | grep -v com.apple
PID     Status  Label
216     –       com.MadCatz.SmartTechnology
-       97      com.adobe.CS5ServiceManager
-       0       com.google.keystone.user.agent
Note : try also “sudo launchctl bslist | grep -v apple”

 

 

#d) remove : “launchctl remove de.metaquark.appfresh”
#e) disable : “launchctl unload -w ~/Library/LaunchAgents/…”

How disable Deamon/Agent at startup?

You can remove .plist file from directory or you can use launchctl:

 

  launchctl unload -w ~/Library/LaunchAgents/com.google.keystone.agent.plist

 

Teorically this should unload and disable the service adding Disabled Key :

 

less ~/Library/LaunchAgents/com.google.keystone.agent.plist

<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
 <plist version=”1.0″>
 <dict>
 <key>Disabled</key> <====!!!
 <true/>
 <key>Label</key>
 
 

Really what happen is that file com.google.keystone.agent.plist remains unchanged and what change is overrides.plist.

 

-
File overrides.plist is present in : 
1) /private/var/db/launchd.db/com.apple.launchd/overrides.plist
    or in directory :
2) /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
-

 

the target file (1) or 2) ) depends by domain of daemon/agent  if it is System or Per-user.
Note peruser.501 : 501 (com.apple.launchd.peruser.501) is id of user :

 

busycrack$ id
uid=501(busycrack) gid=20(staff) groups=20(staff)…

 

Btw file overrides.plist  reports values which are overriding the values in main <file>.plist :
Example :

 

1.  launchctl load -w ~/Library/LaunchAgents/com.google.keystone.agent.plist
    less /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
<key>com.google.keystone.user.agent</key>
        <dict>
                <key>Disabled</key>
                <false/>
        </dict>
—————————
2.  launchctl unload -w ~/Library/LaunchAgents/com.google.keystone.agent.plist
    less /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
<key>com.google.keystone.user.agent</key>
        <dict>
                <key>Disabled</key>
                <true/>
        </dict>

 

However for this and much more things :
  • man launchd
  • man launchctl

#2 Bonus

2.1) try command :  sudo launchctl bstree -j

Customizing Login and Logout :
2.2) you can check present of login script with command :
defaults read com.apple.loginwindow LoginHook”
Script (if present) which is attached to user login… more details : http://support.apple.com/kb/HT2420

2.3) logout script : defaults read com.apple.loginwindow LogoutHook
Script (if present) which is attached to user logout 

#3 App GUI for lauchdctl

lingon : http://sourceforge.net/projects/lingon/files/latest/download 

screen shot 2012 07 29 at 12 28 05 am MAC OSX BOOT sequence ( launchd ) trick osx os x boot sequence by example

Incoming search terms:

The post MAC OSX BOOT sequence ( launchd ) appeared first on Busylog.net.


Viewing all articles
Browse latest Browse all 19

Trending Articles