[erlang-questions] How to upgrade running applications repeatedly

Bo kosmyq@REDACTED
Thu Jun 7 22:06:59 CEST 2007

Hello All.
I have tried without success to be able to update my running applications.   The code below is a very simple example in which there is a loop, that will always call itself with ?MODULE:loop(L) which according to the documentation should always call the latest version of itself, but this is what happens:

1) I start the app with test1:start().
2) I compile it and send some message to it, everything works
3) I repeat step 2 and the program fails

Erlang seems to have upgraded one version and retains still one old version in step 2), but in step 3) it kicks out the old code and terminates my program.   What I do not understand is why does the running application NOT upgrade itself, as far as I get it, the ?MODULE:loop(L) should cause the program to load its latest version, but it does not, the running application stays in the old version and given that Erlang retains 2 versions in memory whenever a 3rd pops up, it terminates the first version.   The only way around it seems to be that when you REALLY want to upgrade your code, you are required to spawn a new version and pass the current parameters to that loop.   

Question:  Is there a better way to do it ??   Why does ?MODULE:loop(L) not update the running loop, if it doesn't, than this functionality is useless or isn't it (or maybe I miss its working entirely) ??  The only other way seems to be doing it OTP (which at this I would like to avoid) and write all data, that the loop would hold  (this code has been removed from example) to mnesia, but this scheme would complicate everything quite a bit, when I require to process data to/from client sockets.

I want to be able to continously update my application as my development advances on multiple nodes without ever stopping it or disconnecting neither services, processes or clients.

Best regards,
-define(VERSION, "0.0.11A").

stop() ->
    test ! quit.
version() ->
    test ! version.
start() ->
start(L) ->

start_server(L) ->
    process_flag(trap_exit, true),
         spawn(fun() ->
            process_flag(trap_exit, true),
            Val= (catch ?MODULE:server_loop([L])),
            io:format("Server terminated with:~p~n",[Val])

server_loop(L) ->
      version  ->
            io:format("Server Version: ~p~n",[?VERSION]),
      quit  ->
              io:format("Server shutting down=~p~n",[quit]),
              {ok, true}; 
      upgrade  ->
               io:format("Server upgrading ...~n"),
              {ok, true}; 
    Msg ->
            io:format("Server received Msg=~p~n",[Msg]),

Be a better Heartthrob. Get better relationship answers from someone who knows.
Yahoo! Answers - Check it out. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070607/c82421a9/attachment.htm>

More information about the erlang-questions mailing list