How to change Yaws appmods files?
Asked Answered
A

1

7

I am trying to manage Yast appmod. So:
yaws.conf:

<server localhost>
   port = 8005
   listen = 127.0.0.1
   docroot = /home/ziel/www/CatsScript/src/
   appmods = </, myappmod>
</server> 

from http://yaws.hyber.org/appmods.yaws myappmod.erl:

-module(myappmod2).
-author('[email protected]').

-include("/home/ziel/erlang/yaws/include/yaws_api.hrl").
-compile(export_all).

box(Str) ->
    {'div',[{class,"box"}],
    {pre,[],Str}}.

out(A) ->
     {ehtml,
     [{p,[],
     box(io_lib:format("A#arg.appmoddata = ~p~n"
                       "A#arg.appmod_prepath = ~p~n"
                       "A#arg.querydata = ~p~n",
                       [A#arg.appmoddata,
                        A#arg.appmod_prepath,
                        A#arg.querydata]))}]}.

And it worked when I used it first time. But later when I changed something in myappmod.erl nothing changed in response from server. Than I deleted myappmod.erl, but it still works. What should I do to make some changes?

Arraign answered 3/7, 2012 at 13:19 Comment(2)
Have you recompiled the .erl file?Pink
appmods are normal erlang modules and so they MUST be compiled to reflect the changes.Booted
P
15

When you start Yaws, it eventually references your myappmod2 module, causing the Erlang runtime to load the beam file produced by compiling the module. Once it's loaded, it stays loaded until you either forcibly reload it, such as through the interactive Erlang shell, or by stopping and restarting Yaws and the Erlang runtime. Simply recompiling the module from the outside does not reload it.

If you run Yaws interactively via yaws -i, you can hit "enter" once it starts up to get an interactive Erlang shell. If you change an appmod module and recompile it, make sure you copy the new beam file over the old one and then simply type l(myappmod2). in the interactive shell and then hit enter to reload the myappmod2 module (and don't forget the period after the close parenthesis). That lowercase l is the Erlang shell's load command. You could also compile the module directly in the shell using the c(myappmod2). command, which will compile and load it (assuming no compilation errors).

If you have Yaws running non-interactively, say as a regular background daemon process, you can reload modules into it by running the following command:

yaws --load myappmod2

You can put multiple module names after the --load option if you want to load them all at once. If your Yaws instance has a specific id, make sure you also use the appropriate --id option to identify it.

If you're interested in auto-reloading recompiled modules, you might look into something like the reloader.erl module, which watches for recompiled modules and loads them automatically. I wouldn't recommend it for production use, but it can be handy for development.

Plunger answered 4/7, 2012 at 13:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.