[938994]: src / erl / setup.erl  Maximize  Restore  History

Download this file

68 lines (56 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-module(setup).
-compile(export_all).
-include("schema.hrl").
setup()->
io:format("Configure Cluster Environment~n"),
Mode=read_data("Cluster Instance Mode {server | client | both}: ",[server,client,both]),
Auto=read_data("Cluster Instance Autostart at System Boot {yes | no}: ",[yes,no]),
setup_linux(list_to_atom(Mode),list_to_atom(Auto)).
setup_linux(Mode,Auto)->
setup_db(),
setup_config(mode,Mode),
setup_auto_start(Auto),
ok.
setup_win32(Mode, _Auto)->
[ErtsPath|_]=filelib:wildcard(code:root_dir()++"/erts*"),
setup_db(),
setup_config(mode,Mode),
Node=libnet:local_name(),
R=os:cmd(lists:concat([ErtsPath,"/bin/erlsrv add MHiveService -w ",code:root_dir()," -name ",Node," -d console -args \"-mnesia dir 'data' -setcookie default -config releases/0.0.4.1/sys -boot releases/0.0.4.1/start\""])),
R.
setup_auto_start(AutoStart)->
case AutoStart of
yes->
{ok,Base}=file:get_cwd(),
_Res=libfile:symlink(filename:join(Base,"bin/mectl"),"/etc/rc.d/rc5.d/S75mectl"),
_Res=libfile:symlink(filename:join(Base,"bin/mectl"),"/etc/rc.d/rc5.d/K03mectl");
_->
ok
end,
ok.
setup_db()->
Node=libnet:local_name(),
io:format("Using Local Name ~p~n",[Node]),
net_kernel:start([Node]),
mnesia:create_schema([Node]),
mnesia:start(),
mnesia:wait_for_tables([config],1000),
libdb:create().
setup_config(Key, Val)->
libdb:write(#config{key=Key, val=Val}).
% {atomic, ok} =mnesia:transaction(fun() ->mnesia:write(#config{key=Key, val=Val})end).
% mnesia:dirty_write(#config{key=Key, val=Val}).
read_data(Text,Values)->
{ok, [Data|_]}=io:fread(Text,"~s"),
if length(Values)>0->
case lists:member(list_to_atom(string:to_lower(Data)),Values) of
true->
Data;
false->
print_failure(Data,[yes,no]),
read_data(Text, Values)
end;
true->Data
end.
print_failure(Value, Valid)->
io:format("~nWrong value given ~p, valid values are ~p~n",[Value, Valid]).

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks