I have a .yaws file which invokes the setup/0
function from the authenticate
module I wrote, which I've placed in the ebin
directory. When I call authenticate:setup/0
from the Erlang shell, it creates a table just fine, but when I load something.yaws in the browser, which calls the authenticate:setup/0
function, it returns {aborted,{bad_type,users,disc_copies,nonode@nohost}}
(something.yaws just returns the return value of authenticate:setup/0
embedded in html for debugging purposes).
Here's the setup/0
function:
setup() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(users, [{type, set}, {record_name, user}, {disc_copies, [node()]}, {attributes, record_info(fields, user)}]).
and here's the user
record:
-record(user, {username, hashed_pw, salt}).
(I have tried calling it from the Erlang shell after I've tried it in the browser, so that couldn't have interfered with it.)
If I run yaws --mnesiadir /usr/local/lib/yaws-appmods/mnesia/
, I get
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:true]
Eshell V8.1 (abort with ^G)
1>
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Yaws: Using config file /etc/yaws/yaws.conf
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Yaws: Using global subconfig file /etc/yaws/conf.d/localhost.conf
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Ctlfile : /home/username/.yaws/yaws/default/CTL
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Yaws: Listening to 0.0.0.0:8080 for <1> virtual servers:
- http://localhost:8080 under /usr/share/yaws/www
rd(user, {username, hashed_pw, salt}).
user
2> mnesia:create_schema([node()]), mnesia:start(), mnesia:create_table(users, [{type, set}, {record_name, user}, {disc_copies, [node()]}, {attributes, record_info(fields, user)}]).
{aborted,{bad_type,users,disc_copies,nonode@nohost}}
If I run the same erlang code in the Erlang shell started with erl -mnesia dir '"/usr/local/lib/yaws-appmods/mnesia/"'
, it works just fine.