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

21 views
Skip to first unread message

Wes James

unread,
Oct 20, 2011, 12:41:27 PM10/20/11
to erlang-q...@erlang.org
I put an erlang VM on a win 7 workstation as a service:

erlsrv add "0esvc" -stopaction "init:stop()." -name node@host -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(net_restart,node@host).


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
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Dave Cottlehuber

unread,
Oct 20, 2011, 2:57:42 PM10/20/11
to erlang-q...@erlang.org
On 20 October 2011 18:41, Wes James <comp...@gmail.com> wrote:
> I put an erlang VM on a win 7 workstation as a service:
>
> erlsrv add "0esvc" -stopaction "init:stop()." -name node@host -w
> "C:/erldir" -args "-setcookie CHOCOLATECHIP -kernel
> inet_dist_listen_min 11111 -s my_app"

I don't think stopaction is needed. The vm receives windows service
control messages and responds to them just fine.

> I then send a message from my mac to the windows workstation:
>
> my_app:do_send(net_restart,node@host).
>
>
> 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.

Not surprising considering net.exe tells the OS to stop the VM. Were
you expecting the code to keep running even though the VM is 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?

Why not call init:restart() which does exactly what you need, from
inside the VM?

> 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).

Would erlang's hot code loading allow you to avoid needing to restart
the VM at all in your case?

Finally consider setting the service parameters to auto-restart with:

-onfail restart_always

in your erlsrv service creation.

A+
Dave

Wes James

unread,
Oct 20, 2011, 3:30:03 PM10/20/11
to Dave Cottlehuber, erlang-q...@erlang.org
Hi.

On Thu, Oct 20, 2011 at 12:57 PM, Dave Cottlehuber <da...@muse.net.nz> wrote:
> On 20 October 2011 18:41, Wes James <comp...@gmail.com> wrote:

<snip>

>>
>> but is there a way to restart the 0esvc from erlang?
>
> Why not call init:restart() which does exactly what you need, from

Thank you - that is what I needed. Ran the code, made a change in the
code, set the message to run that command in place of the other two I
had there and the the new changes showed up!

> inside the VM?
>

>Would erlang's hot code loading allow you to avoid needing to restart
>the VM at all in your case?

I could do hot code loading. Maybe I'll look in to that later, but
the above works as I need it for now.

<snip>

Thanks again, Dave!

-wes

Reply all
Reply to author
Forward
0 new messages