[erlang-questions] How to stop a detached OTP app?
Ulf Wiger
ulf.wiger@REDACTED
Fri Aug 20 22:36:07 CEST 2010
Or, if you really want to set the controller node name
automatically:
#!/usr/bin/env escript
%% -*- erlang -*-
main([Me, N]) ->
{ok, _} = net_kernel:start([list_to_atom(Me), longnames]),
Res = rpc:call(list_to_atom(N), init, stop, []),
io:fwrite("==> ~p~n", [Res]).
You could complement it with net tick time and cookie settings.
http://www.erlang.org/pipermail/erlang-questions/2008-April/034357.html
BR,
Ulf W
Ulf Wiger wrote:
>
> How about this?
>
> #!/usr/bin/env escript
> %% -*- erlang -*-
> %%! -name ctl
>
> main([N]) ->
> Res = rpc:call(list_to_atom(N), init, stop, []),
> io:fwrite("==> ~p~n", [Res]).
>
> It worked for me.
>
> Call it with e.g. ./stop thenode@REDACTED
>
> BR,
> Ulf W
>
> Armando Di Cianno wrote:
>> I'm most certainly doing something braindead, which is stopping me
>> from being able to nicely stop an OTP app I've written.
>>
>> I've written a script to help me start, stop, and connect to the app
>> for debugging purposes. However, no variation of 'stop' I've tried
>> seems to work.
>>
>> Here's the script:
>> ### start
>> #!/usr/bin/env bash
>>
>> USER="myuser"
>> APP="myapp"
>> HOSTNAME=`hostname -f`
>> NODE="${APP}@${HOSTNAME}"
>> RELEASE_PATH="/usr/local/lib/${APP}"
>> HOME="/var/lib/${APP}"
>> LOG_PATH="/var/log/${APP}"
>>
>> case "$1" in
>> "start")
>> su ${USER} -p -c \
>> "erl -pa ${RELEASE_PATH}/ebin -name ${NODE} -boot ${APP}
>> -mnesia
>> dir '\"${HOME}\"' -sasl sasl_error_logger '{file,
>> \"${LOG_PATH}/erlang.log\"}' -detached"
>> ;;
>> "stop")
>> su ${USER} -p -c \
>> "erl -pa ${RELEASE_PATH}/ebin -name ctl_${NODE} -remsh
>> ${NODE}
>> -eval \"init:stop()\" -noshell"
>> ;;
>> "debug")
>> echo "*** Use Ctrl-C Ctrl-C to exit. ***"
>> su ${USER} -p -c \
>> "erl -pa ${RELEASE_PATH}/ebin -name ctl_${NODE} -remsh
>> ${NODE}"
>> ;;
>> *)
>> echo "Please use 'start', 'stop', or 'debug."
>> exit 1
>> ;;
>> esac
>>
>> exit 0
>> ### end
>>
>> For stopping, I've tried:
>> * erl -pa ${RELEASE_PATH}/ebin -name ctl_${NODE} -remsh ${NODE} -eval
>> "init:stop()"
>> * erl -pa ${RELEASE_PATH}/ebin -name ctl_${NODE} -remsh ${NODE} -s
>> init stop
>> * erl -pa ${RELEASE_PATH}/ebin -name ctl_${NODE} -remsh ${NODE} -s
>> ${APP} -extra stop #where I've added some command arg processing to
>> the app
>> ... and some other variantions.
>>
>> If I connect to the app using the debug mode of my script, and issue
>> init:stop(), everything shuts down nicely.
>>
>> Thanks for any insights into this. Cheers,
>> __armando
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>
>
>
--
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
More information about the erlang-questions
mailing list