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]).
|
||||
|
||||
start(_StartType, _StartArgs) ->
|
||||
case ggs_sup:start() of
|
||||
case ggs_sup:start_link(9000) of
|
||||
{ok, Pid} ->
|
||||
{ok, Pid};
|
||||
Other ->
|
||||
|
|
|
@ -23,6 +23,8 @@ parse(Data) ->
|
|||
[RefID, "__echo", Length, Msg ] ->
|
||||
{Ref, _} = string:to_integer(RefID),
|
||||
{echo, Ref, Length, Msg};
|
||||
["__crash"] ->
|
||||
{crash, 0};
|
||||
[RefID, Command, _, Parameter ] ->
|
||||
{cmd, Command, Parameter};
|
||||
Other ->
|
||||
|
|
|
@ -62,7 +62,8 @@ stop() ->
|
|||
%%-----------------------------------------------------
|
||||
|
||||
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}.
|
||||
|
||||
handle_call(get_count, _From, State) ->
|
||||
|
@ -111,6 +112,8 @@ do_JSCall(Socket, Data, State) ->
|
|||
{echo, RefID, _, MSG} ->
|
||||
send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)),
|
||||
[];
|
||||
{crash, Zero} ->
|
||||
10/Zero;
|
||||
% Set the new state to []
|
||||
Other ->
|
||||
io:format("Got '~p'", [Other]),
|
||||
|
|
|
@ -2,12 +2,17 @@
|
|||
-behaviour(supervisor).
|
||||
|
||||
%% API
|
||||
-export([start_link/1]).
|
||||
-export([start/1, start_link/1]).
|
||||
|
||||
%% Supervisor callbacks
|
||||
-export([init/1]).
|
||||
-define(SERVER, ?MODULE).
|
||||
|
||||
start(Port) ->
|
||||
[FirstArg] = Port,
|
||||
{IntPort, _} = string:to_integer(FirstArg),
|
||||
start_link(IntPort).
|
||||
|
||||
start_link(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
|
||||
|
||||
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