Updating tools (WIP)
[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("rechargement des 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("mise à jour de la BD..~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 % Copy the datbase from the production to pre production.
28 copy_database(Node) ->
29 io:format("Copying production database to pre-production node~n"),
30 File = "/tmp/backup_ek_tmp",
31 File2 = "/tmp/backup_ek_tmp2",
32 rpc:call(yaws@overnux, mnesia, backup, [File]),
33 rpc:call(Node, euphorik_bd_admin, change_node_name, [yaws@overnux, yaws_dev@overnux, File, File2]),
34 rpc:call(Node, mnesia, restore, [File2, [{default_op, recreate_tables}]]),
35 rpc:call(yaws@overnux, file, delete, [File]),
36 rpc:call(Node, file, delete, [File2]).