Skip to content

Commit

Permalink
Implement code for the 'etorrentctl' shell script in etorrent_ctl.
Browse files Browse the repository at this point in the history
We know support crude installation and commands like:

etorrentctl start
etorrentctl list
etorrentctl stop (currently with a nodedown artifact we kill later)
  • Loading branch information
jlouis committed Jul 3, 2008
1 parent 9db1758 commit 6a8ee88
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ install:
sed -e "s|%%%BEAMDIR%%%|$(RELEASE_PREFIX)/lib/etorrent-$(VER)/ebin|;" \ sed -e "s|%%%BEAMDIR%%%|$(RELEASE_PREFIX)/lib/etorrent-$(VER)/ebin|;" \
-e "s|%%%CONFIGFILE%%%|$(RELEASE_PREFIX)/lib/etorrent-$(VER)/priv/etorrent.config|;" \ -e "s|%%%CONFIGFILE%%%|$(RELEASE_PREFIX)/lib/etorrent-$(VER)/priv/etorrent.config|;" \
-e "s|%%%ERL_FLAGS%%%|\"$(ERL_FLAGS)\"|" < ./bin/etorrentctl.in > $(BIN_PREFIX)/etorrentctl -e "s|%%%ERL_FLAGS%%%|\"$(ERL_FLAGS)\"|" < ./bin/etorrentctl.in > $(BIN_PREFIX)/etorrentctl
chmod +x $(BIN_PREFIX)/etorrentctl



5 changes: 2 additions & 3 deletions bin/etorrentctl.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ CONFIGFILE=%%%CONFIGFILE%%%
ERL_FLAGS=%%%ERL_FLAGS%%% ERL_FLAGS=%%%ERL_FLAGS%%%


start () { start () {
# TODO: Add noshell and friends
erl ${ERL_FLAGS} -sname ${NODE}@${HOST} -pa ${BEAMDIR} \ erl ${ERL_FLAGS} -sname ${NODE}@${HOST} -pa ${BEAMDIR} \
-config ${CONFIGFILE} -config ${CONFIGFILE} -noshell -noinput -detached \
-s etorrent -s etorrent
} }


Expand All @@ -26,7 +25,7 @@ debug () {
ctl () { ctl () {
erl -noinput -sname etorrentctl@${HOST} \ erl -noinput -sname etorrentctl@${HOST} \
-pa ${BEAMDIR} \ -pa ${BEAMDIR} \
-s etorrent_ctl -run start ${NODE}@${HOST} $@ -s etorrent_ctl start ${NODE}@${HOST} $@
} }


usage () { usage () {
Expand Down
6 changes: 4 additions & 2 deletions lib/etorrent-1.0/src/etorrent.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ start(_Type, _Args) ->
etorrent_sup:start_link(). etorrent_sup:start_link().


stop() -> stop() ->
application:stop(etorrent). application:stop(etorrent),
halt().


stop(_State) -> stop(_State) ->
ok. ok.
Expand Down Expand Up @@ -55,7 +56,8 @@ list() ->
help() -> help() ->
io:format("Available commands:~n", []), io:format("Available commands:~n", []),


Commands = [{"list()", "List torrents in system"}], Commands = [{"list", "List torrents in system"},
{"stop", "Stop the system"}],


lists:foreach(fun({Command, Desc}) -> lists:foreach(fun({Command, Desc}) ->
io:format("~-12.s - ~s~n", [Command, Desc]) io:format("~-12.s - ~s~n", [Command, Desc])
Expand Down
19 changes: 14 additions & 5 deletions lib/etorrent-1.0/src/etorrent_ctl.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ start (Args) ->
case parse_arguments(Args) of case parse_arguments(Args) of
{Node, Commands} -> {Node, Commands} ->
Status = case rpc:call(Node, ?MODULE, process, [Commands]) of Status = case rpc:call(Node, ?MODULE, process, [Commands]) of
{badprc, Reason} -> {badrpc, Reason} ->
io:format("RPC failed on node ~p: ~p~n", io:format("RPC failed on node ~p: ~p~n",
[Node, Reason]), [Node, Reason]),
?STATUS_BADRPC; ?STATUS_BADRPC;
Expand All @@ -40,12 +40,21 @@ start (Args) ->
%%==================================================================== %%====================================================================
%% Internal functions %% Internal functions
%%==================================================================== %%====================================================================
process(["stop"]) -> process([stop]) ->
etorrent:stop(), etorrent:stop(),
?STATUS_OK. ?STATUS_OK;
process([list]) ->
etorrent:list(),
?STATUS_OK;
process([help]) ->
etorrent:help(),
?STATUS_USAGE;
process([_]) ->
etorrent:help(),
?STATUS_USAGE.



parse_arguments([Node | Cmds]) -> parse_arguments([Node | Cmds]) ->
{list_to_atom(Node), {Node,
Cmds}. Cmds}.



0 comments on commit 6a8ee88

Please sign in to comment.