MacでのLighttpdの自動起動(仕掛中)

うまく動かないぃぃ。起動に自動的に実行されるコマンドやら何やらをsudoでトラブルシューティングしながらやっていくのは怖すぎる。

Mac OS Xでサービスを自動起動する方法

launchdを使う方法

どうもlaunchdと言う非常に賢いinitのようなものがあるらしいということで挑戦。下記のどちらかに設定ファイルを置くと起動してくれるらしい。

  • /Library/LaunchDeamons
  • /System/Library/LaunchDeamons *1

設定ファイルは[launchd].plistというシリーズで、書式はみんな大好きXMLらしい。ウホッ。

StartupItemsを使う方法

ちょっと古い、とProfessional Mac OS Xに書いてあった。そういえばJaguarの頃に書いた記憶が。/Library/StartupItems/に
以下のような感じで、一式いれておくみたい。

DarwinPortsから/opt/local/etc/rc.dを使う

DarwinPortsStartupというのを入れるといつものように/opt/local/etc/rc.dを実行してくれるみたいです。ラヴい、のかな?
わたしゃgentooの出なんで、いまいち書式が掴めません。さっきlighttpd.confにpidファイルを指定する方法を見つけたので、最後の手段として採用するかも。

launchdを使いたいけど挫折

/Library/LaunchDeamons に[launchd].plistをおく。[launchd].plistは任意の名前で。いろいろ指定するとlaunchdが予期に計らって起動してくれる。かなり高機能っぽい。詳しくは man launchd.plist(5)。

しかし、

  A daemon or agent launched by launchd MUST NOT do the following in the
  process directly launched by launchd:

   o   fork(2) and have the parent process exit(3) or _exit(2).
   o   Call daemon(3)

  A daemon or agent launched by launchd SHOULD NOT do the following as a
  part of their startup initialization:

   o   Setup the user ID or group ID.
   o   Setup the working directory.
   o   chroot(2)
   o   setsid(2)
   o   Close "stray" file descriptors.
   o   Change stdio(3) to /dev/null.
   o   Setup resource limits with setrusage(2).
   o   Setup priority with setpriority(2).
   o   Ignore the SIGTERM signal.

MUST NOTの項目がもろに当てはまってるっぽい。> lighty
耳年増のひとに-Dオプションで、デーモンにならず、だからたぶんfork()せずに動くみたいだよ、と教えてもらったんですが、その場合もさらに、lighttpd.plistでUserNameを一般ユーザ(つーか"www")指定するとport 80を開けなくて(?)落ちるっぽい。

いまここ。

*1:/System以下は普通はいじるべきではない