From 47a756f7d78138251f9cb7033ec049d48fe272c4 Mon Sep 17 00:00:00 2001 From: JanLehnardt Date: Mon, 22 Jan 2007 15:54:12 +0000 Subject: [PATCH] Add Lucene Indexer Control git-svn-id: http://couchdb.googlecode.com/svn/trunk@113 efc57d8c-411c-0410-91b3-cfdf4dd2bc77 --- CouchProjects/CouchDb/couch_lucene.erl | 66 ++++++++++++++++++++ CouchProjects/CouchDb/couch_server_sup.erl | 99 +++++++++++++++++++++--------- 2 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 CouchProjects/CouchDb/couch_lucene.erl diff --git a/CouchProjects/CouchDb/couch_lucene.erl b/CouchProjects/CouchDb/couch_lucene.erl new file mode 100644 index 0000000..521adb6 --- /dev/null +++ b/CouchProjects/CouchDb/couch_lucene.erl @@ -0,0 +1,66 @@ +%% CouchDb +%% Copyright (C) 2006 Damien Katz +%% +%% This program is free software; you can redistribute it and/or +%% modify it under the terms of the GNU General Public License +%% as published by the Free Software Foundation; either version 2 +%% of the License, or (at your option) any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program; if not, write to the Free Software +%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +-module(couch_lucene). +-behaviour(gen_server). + +-include("couch_db.hrl"). + +-export([start_link/1, timeout/0]). +-export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3,stop/0]). + +-define(ERR_HANDLE, {Port, {exit_status, Status}} -> {stop, {unknown_error, Status}, {unknown_error, Status}, Port}). + +start_link(LuceneExec) -> + gen_server:start_link({local, couch_lucene}, couch_lucene, LuceneExec, []). + +stop() -> + exit(whereis(couch_lucene), close). + +timeout() -> + % in Msecs. maybe need to make this a configurable value + 30000. + +init(LuceneExec) -> + Cmd = + case erlang:system_info(os_type) of + {unix, _} -> + lists:flatten(io_lib:format("~s launched_from_erlang", [LuceneExec])); + {win32, _} -> + lists:flatten(io_lib:format("cmd /c\"~s\" launched_from_erlang", [LuceneExec])) + end, + Port = open_port({spawn, Cmd}, [nouse_stdio]), + {ok, {Cmd, Port}}. + +terminate(_Reason, _Server) -> + ok. + +handle_call(get_exe_cmd, _From, {Cmd, Port}) -> + ok. + + +handle_cast(_Whatever, {Exe, Port}) -> + {noreply, {Exe, Port}}. + +handle_info({Port, {exit_status, Status}}, {Exe, Port}) -> + {stop, {lucene_server_exited, Status}, {Exe, Port}}; + +handle_info(_Whatever, {Exe, Port}) -> + {noreply, {Exe, Port}}. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. diff --git a/CouchProjects/CouchDb/couch_server_sup.erl b/CouchProjects/CouchDb/couch_server_sup.erl index 537eada..b0aa634 100644 --- a/CouchProjects/CouchDb/couch_server_sup.erl +++ b/CouchProjects/CouchDb/couch_server_sup.erl @@ -60,9 +60,11 @@ start_server(IniFilename) -> DbRootDir = couch_util:abs_pathname(couch_util:ini_get_value(Ini, "Couch", "DbRootDir", ".")), HttpConfigFile = couch_util:abs_pathname(couch_util:ini_get_value(Ini, "Couch", "HttpConfigFile", "couch_httpd.conf")), FabricServer = couch_util:abs_pathname(couch_util:ini_get_value(Ini, "Couch", "FabricServer", "FabricServer")), + LuceneServer = couch_util:ini_get_value(Ini, "Couch", "LuceneServer", ""), LogFile = couch_util:abs_pathname(couch_util:ini_get_value(Ini, "Couch", "LogFile", "couchdb.log")), UtilDriverDir = couch_util:abs_pathname(couch_util:ini_get_value(Ini, "Couch", "UtilDriverDir", ".")), + io:format("couch ~s (LogLevel=~s)~n", [couch_server:get_version(), LogLevel]), io:format("~s~n", [ConsoleStartupMsg]), @@ -72,8 +74,8 @@ start_server(IniFilename) -> couch_log:debug("Startup Info:~n\tDbRootDir=~p~n\tHttpConfigFile=~p~n\tFabricServer=~p~n\tLogFile=~p~n\tUtilDriverDir=~p", [DbRootDir, HttpConfigFile, FabricServer, LogFile, UtilDriverDir]), - - StartResult = supervisor:start_link({local, couch_server_sup}, couch_server_sup, {DbRootDir, FabricServer, HttpConfigFile, UtilDriverDir}), + + StartResult = supervisor:start_link({local, couch_server_sup}, couch_server_sup, {DbRootDir, FabricServer, HttpConfigFile, UtilDriverDir, LuceneServer}), case StartResult of {ok,_} -> @@ -94,31 +96,68 @@ get_default_ini() -> {error, enoent} -> {ok, <<>>} % default ini missing, just return a blank end. - -init({DbServerRoot, FabricServer, HttpConfigFile, UtilDriverDir}) -> - {ok, {{one_for_one, 10, 3600}, - [{couch_server, - {couch_server, sup_start_link, [DbServerRoot]}, - permanent, - brutal_kill, - worker, - [couch_server]}, - {couch_util, - {couch_util, start_link, [UtilDriverDir]}, - permanent, - brutal_kill, - worker, - [couch_util]}, - {couch_fabric, - {couch_fabric, start_link, [FabricServer]}, - permanent, - brutal_kill, - worker, - [couch_fabric]}, - {httpd, - {httpd, start_link, [HttpConfigFile]}, - permanent, - 1000, - supervisor, - [httpd]} - ]}}. \ No newline at end of file + +init({DbServerRoot, FabricServer, HttpConfigFile, UtilDriverDir, LuceneServer}) -> + case string:equal(LuceneServer, "") of + true -> + {ok, {{one_for_one, 10, 3600}, + [{couch_server, + {couch_server, sup_start_link, [DbServerRoot]}, + permanent, + brutal_kill, + worker, + [couch_server]}, + {couch_util, + {couch_util, start_link, [UtilDriverDir]}, + permanent, + brutal_kill, + worker, + [couch_util]}, + {couch_fabric, + {couch_fabric, start_link, [FabricServer]}, + permanent, + brutal_kill, + worker, + [couch_fabric]}, + {httpd, + {httpd, start_link, [HttpConfigFile]}, + permanent, + 1000, + supervisor, + [httpd]} + ]}}; + + _ -> + {ok, {{one_for_one, 10, 3600}, + [{couch_server, + {couch_server, sup_start_link, [DbServerRoot]}, + permanent, + brutal_kill, + worker, + [couch_server]}, + {couch_util, + {couch_util, start_link, [UtilDriverDir]}, + permanent, + brutal_kill, + worker, + [couch_util]}, + {couch_fabric, + {couch_fabric, start_link, [FabricServer]}, + permanent, + brutal_kill, + worker, + [couch_fabric]}, + {couch_lucene, + {couch_lucene, start_link, [LuceneServer]}, + permanent, + brutal_kill, + worker, + [couch_lucene]}, + {httpd, + {httpd, start_link, [HttpConfigFile]}, + permanent, + 1000, + supervisor, + [httpd]} + ]}} + end. \ No newline at end of file -- 2.11.4.GIT