Now we can start the application from the commandline, and still use supervisors.
This commit is contained in:
parent
72e411aee9
commit
af75d731b4
7 changed files with 20 additions and 4 deletions
|
@ -3,7 +3,7 @@
|
||||||
-export([start/2, stop/1]).
|
-export([start/2, stop/1]).
|
||||||
|
|
||||||
start(_StartType, _StartArgs) ->
|
start(_StartType, _StartArgs) ->
|
||||||
case ggs_sup:start() of
|
case ggs_sup:start_link(9000) of
|
||||||
{ok, Pid} ->
|
{ok, Pid} ->
|
||||||
{ok, Pid};
|
{ok, Pid};
|
||||||
Other ->
|
Other ->
|
||||||
|
|
|
@ -23,6 +23,8 @@ parse(Data) ->
|
||||||
[RefID, "__echo", Length, Msg ] ->
|
[RefID, "__echo", Length, Msg ] ->
|
||||||
{Ref, _} = string:to_integer(RefID),
|
{Ref, _} = string:to_integer(RefID),
|
||||||
{echo, Ref, Length, Msg};
|
{echo, Ref, Length, Msg};
|
||||||
|
["__crash"] ->
|
||||||
|
{crash, 0};
|
||||||
[RefID, Command, _, Parameter ] ->
|
[RefID, Command, _, Parameter ] ->
|
||||||
{cmd, Command, Parameter};
|
{cmd, Command, Parameter};
|
||||||
Other ->
|
Other ->
|
||||||
|
|
|
@ -62,7 +62,8 @@ stop() ->
|
||||||
%%-----------------------------------------------------
|
%%-----------------------------------------------------
|
||||||
|
|
||||||
init([Port]) ->
|
init([Port]) ->
|
||||||
{ok, LSock} = gen_tcp:listen(Port, [{active, true}]),
|
{ok, LSock} = gen_tcp:listen(Port, [{active, true},
|
||||||
|
{reuseaddr, true}]),
|
||||||
{ok, #state{port = Port, lsock = LSock}, 0}.
|
{ok, #state{port = Port, lsock = LSock}, 0}.
|
||||||
|
|
||||||
handle_call(get_count, _From, State) ->
|
handle_call(get_count, _From, State) ->
|
||||||
|
@ -111,6 +112,8 @@ do_JSCall(Socket, Data, State) ->
|
||||||
{echo, RefID, _, MSG} ->
|
{echo, RefID, _, MSG} ->
|
||||||
send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)),
|
send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)),
|
||||||
[];
|
[];
|
||||||
|
{crash, Zero} ->
|
||||||
|
10/Zero;
|
||||||
% Set the new state to []
|
% Set the new state to []
|
||||||
Other ->
|
Other ->
|
||||||
io:format("Got '~p'", [Other]),
|
io:format("Got '~p'", [Other]),
|
||||||
|
|
|
@ -2,12 +2,17 @@
|
||||||
-behaviour(supervisor).
|
-behaviour(supervisor).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/1]).
|
-export([start/1, start_link/1]).
|
||||||
|
|
||||||
%% Supervisor callbacks
|
%% Supervisor callbacks
|
||||||
-export([init/1]).
|
-export([init/1]).
|
||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
|
|
||||||
|
start(Port) ->
|
||||||
|
[FirstArg] = Port,
|
||||||
|
{IntPort, _} = string:to_integer(FirstArg),
|
||||||
|
start_link(IntPort).
|
||||||
|
|
||||||
start_link(Port) ->
|
start_link(Port) ->
|
||||||
supervisor:start_link({local, ?SERVER}, ?MODULE, [Port]).
|
supervisor:start_link({local, ?SERVER}, ?MODULE, [Port]).
|
||||||
|
|
||||||
|
|
6
src/start_ggs.erl
Normal file
6
src/start_ggs.erl
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
-module(start_ggs).
|
||||||
|
-export([start/0]).
|
||||||
|
|
||||||
|
start() ->
|
||||||
|
application:start(inets),
|
||||||
|
application:start(ggs).
|
2
start
2
start
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
erl -boot start_sasl -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src -eval "ggs_sup:start_link($1)."
|
erl -boot start_sasl -pa erlang_js/ebin/ -pa ebin -pa src -s start_ggs
|
||||||
|
|
Reference in a new issue