As part of my efforts to write an erlang plugin I did the following to the bin/couchdb script:

1. Add the following near the head of the file:

PLUGINS_DIRECTORY=/usr/local/etc/couchdb/plugins
PLUGIN_INI_FILES=
PLUGIN_ERLANG_PATHS=
for plugin in $PLUGINS_DIRECTORY/*; do
    if test -d $plugin/ebin; then
        PLUGIN_ERLANG_PATHS="$PLUGIN_ERLANG_PATHS $plugin/ebin";
    fi
    if test -f $plugin/config.ini; then
        PLUGIN_INI_FILES="$PLUGIN_INI_FILES $plugin/config.ini";
    fi
done

2. Modify the code that accumulates the ini files:

    if test -n "$INI_FILES"; then
        ini_files="$PLUGIN_INI_FILES $INI_FILES"
    else
        ini_files="$DEFAULT_INI_FILE $LOCAL_INI_FILE $PLUGIN_INI_FILES"
    fi

3. Modify the code that starts couchdb:

    command="`/opt/local/bin/icu-config --invoke` \
/opt/local/bin/erl $interactive_option -smp auto -sasl errlog_type error +K true \ -pa /usr/local/lib/couchdb/erlang/lib/couch-0.9.0a-incubating/ ebin \
            /usr/local/lib/couchdb/erlang/lib/mochiweb-r82/ebin \
            $PLUGIN_ERLANG_PATHS \
        -eval \"application:load(inets)\" \
        -eval \"application:load(crypto)\" \
        -eval \"application:load(couch)\" \
        -eval \"crypto:start()\" \
        -eval \"inets:start()\" \
-eval \"couch_server:start([$start_arguments]), receive done - > done end.\" "


Now I can drop components into /usr/local/etc/couchdb/plugins:

  /usr/local/etc/plugins/
    00test/
      config.ini
      ebin/
        <blah>.beam

Something like this would seem to be the simplest possible mechanism that allows separately packaged components.

Antony Blakey
--------------------------
CTO, Linkuistics Pty Ltd
Ph: 0438 840 787

What can be done with fewer [assumptions] is done in vain with more
  -- William of Ockham (ca. 1285-1349)



Reply via email to