Getting Sphinx Search Running with MediaWiki on OSX
I had a bit of an issue getting Sphinx Search running with MediaWiki in OSX as I found creating a plist to be a harder problem than I anticipated. I followed the standard Mediawiki installation instructions until I got to the point of setting up the daemon.
In OS X it turns out the way to get a daemon to run is to run using launchd. The process to get one of these to run is to create an XML file in /Library/LaunchDaemons (there OS X has it’s own plist files in /Library/LaunchDaemons) and run launchctl to start the daemon.
I created my own daemon file for Sphinx, sphinx, in /Library/LaunchDaemons:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.search.sphinx</string>
<key>UserName</key>
<string>simon</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/searchd</string>
<string>--config</string>
<string>/Users/simon/source/mediawiki/wikinutrition/private/sphinx.conf</string>
</array>
<key>StandardOutPath</key>
<string>/var/log/sphinx/sphinx-startup.log</string>
<key>KeepAlive</key>
<true/>
<key>debug</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
You can see I am running the daemon as myself using the UserName key.
Unfortunately when I went to start this using launchctl load -w /Library/LaunchDaemons/sphinx nothing appeared to happen. No error message, no nothing. When I turned the debug setting on (by adding <key>debug</key><true/>), however, I noticed in /var/log/system.log a number of these messages:
Jun 15 17:13:26 simon-mosk-aoyamas-computer-6 com.apple.launchd[1] (org.search.sphinx): Throttling respawn: Will start in 10 seconds
Googling this led to this discovery from Apple:
Jobs run from launchd should not duplicate launchd functionality; for instance, they should not use chroot(2). Furthermore, they should not do the things normally required of daemon processes, such as detaching from the terminal they are initially attached to. The only things that are strictly prohibited, however, are fork()/exit() combinations (including indirect methods, such as the daemon(3) library call). A server which attempts to run itself as a daemon in this way will seem to have finished running, potentially leading to launchd respawning it, or disabling the service. As launchd does not get stalled waiting for a child that hasn’t yet exited, it’s not necessary to try to prevent it.
Bingo – here is the problem – Sphinx’s searchd starts and forks as it’s a traditional daemon. Thankfully it has a --console option which does not fork, so adding --console to the plist file (inside the <ProgramArguments> array) had me up and running!
The final file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.search.sphinx</string>
<key>UserName</key>
<string>simon</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/searchd</string>
<string>--config</string>
<string>/Users/simon/source/mediawiki/wikinutrition/private/sphinx.conf</string>
<string>--console</string>
</array>
<key>StandardOutPath</key>
<string>/var/log/sphinx/sphinx-startup.log</string>
<key>KeepAlive</key>
<true/>
<key>debug</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Its very tricky to get it working with Launchd. Have you been able to figure out how to rotate the indexes if searchd is runnning via Launchd?
I am getting an error that the PID file can not be found.
Michael
1 Sep 10 at 3:52 am edit_comment_link(__('Edit', 'sandbox'), ' ', ''); ?>
Simon-
Thanks so much for posting this. It was driving me crazy too the miss was just the trick.
–
Daryl
Daryl Richter
5 Jan 11 at 6:51 am edit_comment_link(__('Edit', 'sandbox'), ' ', ''); ?>