Skip to content
Browse files

add handler cli param and fix up to actually work

  • Loading branch information...
1 parent d37db25 commit 210fdd51292934dec8db0b1bcca11d798418c103 @mojombo committed May 18, 2009
Showing with 63 additions and 6 deletions.
  1. +47 −0 README.md
  2. +2 −2 ebin/ernie_server_app.app
  3. +3 −3 elib/ernie_server.erl
  4. +4 −1 elib/ernie_server_sup.erl
  5. +7 −0 lib/cli/server.rb
View
47 README.md
@@ -0,0 +1,47 @@
+Ernie
+=====
+
+By Tom Preston-Werner (tom@mojombo.com)
+
+WARNING: This software is alpha and should not be used in production without
+extensive testing. You should not consider this project production ready until
+it is released as 1.0.
+
+
+Description
+-----------
+
+Ernie is a BERT-RPC server implementation that uses an Erlang server to accept incoming connections, and then delegates the request to a Ruby handler via Erlectricity.
+
+
+Installation
+------------
+
+ gem install mojombo-ernie -s http://gems.github.com
+
+
+Contribute
+----------
+
+If you'd like to hack on Ernie, start by forking my repo on GitHub:
+
+http://github.com/mojombo/ernie
+
+To get all of the dependencies, install the gem first. The best way to get
+your changes merged back into core is as follows:
+
+1. Clone down your fork
+1. Create a topic branch to contain your change
+1. Hack away
+1. Add tests and make sure everything still passes by running `rake`
+1. If you are adding new functionality, document it in the README.md
+1. Do not change the version number, I will do that on my end
+1. If necessary, rebase your commits into logical chunks, without errors
+1. Push the branch up to GitHub
+1. Send me (mojombo) a pull request for your branch
+
+
+Copyright
+---------
+
+Copyright (c) 2009 Tom Preston-Werner. See LICENSE for details.
View
4 ebin/ernie_server_app.app
@@ -1,2 +1,2 @@
-{application, smoke_server_app,
- [{mod, {smoke_server_app, []}}]}.
+{application, ernie_server_app,
+ [{mod, {ernie_server_app, []}}]}.
View
6 elib/ernie_server.erl
@@ -2,7 +2,7 @@
-behaviour(gen_server).
%% api
--export([start_link/1, start/1, rpc/1, test/0]).
+-export([start_link/1, start/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@@ -32,10 +32,10 @@ start(Args) ->
%% {stop, Reason}
%% Description: Initiates the server
%%--------------------------------------------------------------------
-init(Port) ->
+init([Port, Handler]) ->
process_flag(trap_exit, true),
error_logger:info_msg("~p starting~n", [?MODULE]),
- Ducky = port_wrapper:wrap("ducky"),
+ Ducky = port_wrapper:wrap(Handler),
{ok, LSock} = try_listen(Port, 500),
spawn(fun() -> loop(LSock, Ducky) end),
{ok, #state{lsock = LSock, ducky = Ducky}}.
View
5 elib/ernie_server_sup.erl
@@ -7,12 +7,15 @@ start_link() ->
init([]) ->
{ok, Port} = application:get_env(ernie_server_app, port),
+ io:format("Using port ~p~n", [Port]),
+ {ok, Handler} = application:get_env(ernie_server_app, handler),
+ io:format("Using handler ~p~n", [Handler]),
case application:get_env(ernie_server_app, pidfile) of
{ok, Location} ->
Pid = os:getpid(),
ok = file:write_file(Location, list_to_binary(Pid));
undefined -> ok
end,
{ok, {{one_for_one, 1, 60},
- [{ernie_server, {ernie_server, start_link, [Port]},
+ [{ernie_server, {ernie_server, start_link, [[Port, Handler]]},
permanent, brutal_kill, worker, [ernie_server]}]}}.
View
7 lib/cli/server.rb
@@ -20,6 +20,12 @@
end.parse!
command = ARGV[0]
+handler = ARGV[1]
+
+unless handler
+ puts "A handler must be specified: ernie /path/to/handler.rb"
+ exit(1)
+end
name = options[:name] || DEFAULT_NODE_NAME
port = options[:port] || 8000
@@ -36,6 +42,7 @@
#{pidfile} \
-setcookie #{cookie_hash(name)} \
-ernie_server_app port #{port} \
+ -ernie_server_app handler '"#{handler}"' \
-run ernie_server_app boot}.squeeze(' ')
puts cmd
exec(cmd)

0 comments on commit 210fdd5

Please sign in to comment.
Something went wrong with that request. Please try again.