Replace some french comments by english ones.
[euphorik.git] / tools / update_server.erl
1 #!/usr/bin/env escript
2
3 % Execute remotly after the files has been copied.
4 % Reload all modules et update the database.
5 % TODO: build the node name from the host name.
6
7 hote() ->
8 '@overnux'.
9
10 % le premier argument est le nom du noeud est peut valoir :
11 % - yaws : noeud de production
12 % - yaws_dev : noeud de pre-production
13 main([Node_name]) when Node_name =:= "yaws"; Node_name =:= "yaws_dev" ->
14 Node = list_to_atom(Node_name ++ atom_to_list(hote())),
15 net_kernel:start([flynux, shortnames]),
16 io:format("reloading modules...~n"),
17 rpc:call(Node, euphorik_daemon, reload_euphorik, []),
18 if Node_name =:= "yaws_dev" -> copy_database(Node);
19 true -> true
20 end,
21 io:format("updating database...~n"),
22 rpc:call(Node, euphorik_bd_admin, update, []);
23 main(_) ->
24 io:format("Usage: update_server.erl <node-name>"),
25 halt(1).
26
27 create_database_directory() ->
28 % Create the directory "var/database" if it doesn't exist.
29 {ok, Files_in_root} = file:list_dir("."),
30 Var_exists = lists:any(fun(Name) -> Name =:= "var" end, Files_in_root),
31 if not Var_exists ->
32 file:make_dir("var");
33 true -> ok
34 end,
35 {ok, Files_in_var} = file:list_dir("var"),
36 Database_exists = lists:any(fun(Name) -> Name =:= "database" end, Files_in_var),
37 if not Database_exists ->
38 file:make_dir("var/database");
39 true -> ok
40 end.
41
42 % Copy the datbase from the production to pre production.
43 copy_database(Node) ->
44 io:format("Copying production database to pre-production node~n"),
45 File = "/tmp/backup_ek_tmp",
46 File2 = "/tmp/backup_ek_tmp2",
47 rpc:call(yaws@overnux, mnesia, backup, [File]),
48 rpc:call(Node, euphorik_bd_admin, change_node_name, [yaws@overnux, yaws_dev@overnux, File, File2]),
49 rpc:call(Node, mnesia, restore, [File2, [{default_op, recreate_tables}]]),
50 rpc:call(yaws@overnux, file, delete, [File]),
51 rpc:call(Node, file, delete, [File2]).