[erlang-questions] restart erlang app service - kills rest of running code

Wes James <>
Thu Oct 20 18:41:27 CEST 2011


I put an erlang VM on a win 7 workstation as a service:

erlsrv add "0esvc" -stopaction "init:stop()." -name  -w
"C:/erldir" -args "-setcookie CHOCOLATECHIP -kernel
inet_dist_listen_min 11111 -s my_app"

I then send a message from my mac to the windows workstation:

my_app:do_send().


and it gets to this point:

case Com of
        net_restart ->
            os:cmd("net stop 0esvc"),

% but then everything stops after the above line - the next line is
not reached since the erlang VM has been stopped.

            os:cmd("net start 0esvc");


I could write a script 0esvc.cmd with

net stop 0esvc
net start 0esvc


instead and call os:cmd("0esvc.cmd");

but is there a way to restart the 0esvc from erlang?

For now I have a second simple service 2esvc that I can send a command
and it restarts the 0esvc.

How about if I write an erlang script that has

timer:sleep(5000),
os:cmd("net start 0esvc");

And I call it:


net_restart ->
    os:cmd("escript restart.erl"),
    os:cmd("net stop 0esvc"),

But then the escript call will block the process from continuing until
os:cmd is done - is there a way to spawn that call off so it can run
later?  But to be spawned the VM needs to be running.

Maybe 0esvc.cmd is the best way to do this.

Why am I restarting the VM?  If I update the code in my_app,
restarting will update it.  I guess, I could just not worry about the
restart and when code is updated, just restart the workstation (one of
50 in a student computer lab).

thanks,

-wes



More information about the erlang-questions mailing list