diff options
author | Jason Smith (work) <jhs@iriscouch.com> | 2013-02-12 10:55:57 +0000 |
---|---|---|
committer | Jason Smith (work) <jhs@iriscouch.com> | 2013-02-12 10:55:57 +0000 |
commit | 1166f2848a3a9c6d7cd04d10acc980aea4348842 (patch) | |
tree | 13369b596a35eb5bcfb46ba759bdb08dd7ed7d62 | |
parent | 5f1f41832effe3ec94306ac0f2931d58a91c1888 (diff) | |
download | couchdb-1166f2848a3a9c6d7cd04d10acc980aea4348842.tar.gz |
Run the Node.js helper
-rw-r--r-- | src/couchdb/couch_os_daemons.erl | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/couchdb/couch_os_daemons.erl b/src/couchdb/couch_os_daemons.erl index 9a912c47e..46fedd79c 100644 --- a/src/couchdb/couch_os_daemons.erl +++ b/src/couchdb/couch_os_daemons.erl @@ -32,6 +32,7 @@ -define(PORT_OPTIONS, [stream, {line, 1024}, binary, exit_status, hide]). -define(TIMEOUT, 5000). +-define(NODEJS_EXTRA, "couchjs --extra"). start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). @@ -192,10 +193,25 @@ code_change(_OldVsn, State, _Extra) -> % Port management helpers % +start_port(?NODEJS_EXTRA) -> + Port = couch_config:get("httpd", "port"), + Env = [ {"_couchdb_port",Port} ], + start_port(?NODEJS_EXTRA, Env); + start_port(Command) -> + start_port(Command, []). + +start_port(Command, EnvPairs) -> PrivDir = couch_util:priv_dir(), Spawnkiller = filename:join(PrivDir, "couchspawnkillable"), - Port = open_port({spawn, Spawnkiller ++ " " ++ Command}, ?PORT_OPTIONS), + Opts = case lists:keytake(env, 1, ?PORT_OPTIONS) of + false -> + ?PORT_OPTIONS ++ [ {env,EnvPairs} ]; + {value, {env,OldPairs}, SubOpts} -> + AllPairs = lists:keymerge(1, EnvPairs, OldPairs), + SubOpts ++ [ {env,AllPairs} ] + end, + Port = open_port({spawn, Spawnkiller ++ " " ++ Command}, Opts), {ok, Port}. @@ -260,7 +276,10 @@ handle_log_message(Name, Msg, Level) -> reload_daemons(Table) -> % List of daemons we want to have running. - Configured = lists:sort(couch_config:get("os_daemons")), + % The nodejs helper is mandatory. + Configured1 = lists:sort(couch_config:get("os_daemons")), + Configured = lists:keystore("nodejs_couchdb", 1, Configured1, + {"nodejs_couchdb", ?NODEJS_EXTRA}), % Remove records for daemons that were halted. MSpecHalted = #daemon{name='$1', cmd='$2', status=halted, _='_'}, |