Marvericksからlaunchd.plistの仕様が変わったようだ

Mac OS X MavericksでApacheのLaunchdの設定を調べた。

 

$cat /System/Library/LaunchDaemons/org.apache.httpd.plist

<?xml version="1.0" encoding="UTF-8"?>

<!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>

<string>org.apache.httpd</string>

<key>EnvironmentVariables</key>

<dict>

<key>XPC_SERVICES_UNAVAILABLE</key>

<string>1</string>

</dict>

<key>ProgramArguments</key>

<array>

<string>/usr/sbin/httpd</string>

<string>-D</string>

<string>FOREGROUND</string>

</array>

<key>OnDemand</key>

<false/>

</dict>

</plist>

となっている。

ここで、

<key>Disabled</key>

<true/>

のように、DisableがtrueになっていてもApacheが起動する理由ではまった。

 

$ man apachectl (の一部)

    -w       Overrides the Disabled key and sets it to false. In previous versions, this option would modify the configuration file. Now the state of the Disabled key is stored elsewhere on-disk.

となっており、以前のバージョンでは同設定ファイルの有効/無効をDisableキーで制御していたが今ではDisableかどうかの情報はplistファイルには保存されなくなっている。

 

$man launchd.plist (の一部)

    Disabled <boolean>

     This optional key is used as a hint to launchctl(1) that it should not submit this job to launchd when loading a job or jobs. The value of this key does NOT reflect the current state of the job on the running system. If you wish to know whether a job is loaded in launchd, reading this key from a configuration file yourself is not a sufficient test. You should query launchd for the presence of the job using the launchctl(1) list subcommand or use the ServiceManagement framework's SMJobCopyDictionary() method.

となっており、loadされているかどうかは

$ sudo launchd list

で調べる必要があるようだ。

 

$ sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

$ sudo launchctl list | grep httpd

445-0x7fb950d262a0.anonymous.httpd

444-org.apache.httpd

となっており、確かにApacheがloadされていることがわかる。

 

ちなみに、Mountain Lionまでは/System/Library/LaunchDaemonsディレクトリにplistファイルを置いて、それをlaunchctl load -w することでDisableキーの値を操作する仕組みになっていた。