-#!/usr/bin/env escript\r
-% coding: utf-8\r
-% Copyright 2008 Grégory Burri\r
-%\r
-% This file is part of Euphorik.\r
-%\r
-% Euphorik is free software: you can redistribute it and/or modify\r
-% it under the terms of the GNU General Public License as published by\r
-% the Free Software Foundation, either version 3 of the License, or\r
-% (at your option) any later version.\r
-%\r
-% Euphorik is distributed in the hope that it will be useful,\r
-% but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-% GNU General Public License for more details.\r
-%\r
-% You should have received a copy of the GNU General Public License\r
-% along with Euphorik. If not, see <http://www.gnu.org/licenses/>.\r
-\r
-% This file replace the old one 'tools.rb' written in a crapy language ;)\r
-% TODO :\r
-% - création de unit tests (voir eunit) et validation avant la mise en prod\r
-\r
-\r
-main(Args) ->\r
- file:set_cwd(".."),\r
- case Args of\r
- ["prod"] -> in_prod("gburri@euphorik.ch:/var/www/euphorik");\r
- ["pre"] -> in_preprod("gburri@euphorik.ch:/var/www/euphorik_preprod", "var/www/euphorik");\r
- ["js"] -> verif_js();\r
- ["version"] -> update_version();\r
- _ ->\r
- io:format(\r
- "Usage : ~s (prod | pre | js | version)~n"\r
- " prod : in production~n"\r
- " pre : in preproduction, data are copied from production~n"\r
- " js : check the JavaScript files~n"\r
- " version : update the version into somes files from the VERSION file",\r
- [escript:script_name()]\r
- )\r
- end.\r
-\r
-\r
-% A simple fonction to log message.\r
-log(Str) ->\r
- io:format("===== ~s =====~n", [Str]).\r
-\r
-\r
-% Execute an OS commande and print the result to stdout.\r
-cmd(Commande_str) ->\r
- cmd(Commande_str, []).\r
-cmd(Commande_str, Params) ->\r
- io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Commande_str, Params)))]).\r
-\r
-\r
--record(uri, {\r
- host,\r
- path % in absolute\r
-}).\r
-\r
-\r
-% Create an uri record from an uri string.\r
-create_uri(Uri_str) ->\r
- [Host, Path] = string:tokens(Uri_str, ":"),\r
- #uri{host = Host, path = Path}.\r
-\r
-\r
-% Update the version into somes files from the VERSION file.\r
-update_version() ->\r
- log("Update the version tag"),\r
- todo.\r
-\r
-\r
-% Check the JavaScript files.\r
-verif_js() ->\r
- todo.\r
-\r
-\r
-% Start the production processus.\r
-in_prod(Uri) ->\r
- compile_server_part(Uri),\r
- make_var_directory(Uri),\r
- copy_files(Uri),\r
- define_files_rights(Uri),\r
- update_server().\r
-\r
-\r
-% Start the pre-production processus.\r
-in_preprod(Uri, data_path) ->\r
- compile_server_part(Uri),\r
- make_var_directory(Uri),\r
- copy_files(Uri),\r
- define_files_rights(Uri),\r
- start_server(),\r
- update_server().\r
-\r
-\r
-% Compile the Erlang modules.\r
-compile_server_part(Uri) ->\r
- todo.\r
-\r
-\r
-% Create the 'var' folder if it doesn't exist.\r
-make_var_directory(Uri) ->\r
- todo.\r
-\r
-\r
-% Copy files from developpement env to production server.\r
-copy_files(Uri) ->\r
- copy_static_part(Uri),\r
- copy_packed_js(Uri).\r
-\r
-\r
-% Copy all static files like modules, styles, pages, etc.\r
-copy_static_part(Uri) ->\r
- %~ creer_rep('modules')\r
- %~ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules")\r
- %~ system("rsync -r modules/include #{@uri}:#{@rep}/modules")\r
- todo.\r
-\r
-\r
-% Minify and pack JavaScript in one file then copy it to ther server.\r
-copy_packed_js(Uri) ->\r
- todo.\r
-\r
-\r
-% Define the rights for the copied folder et files.\r
-define_files_rights(Uri) ->\r
- todo.\r
-\r
-\r
-% Start the server if it not already started (in preproduction case only).\r
-start_server() ->\r
- todo.\r
-\r
-\r
-% Run a erlang script to\r
-update_server() ->\r
- todo.\r
-\r
+#!/usr/bin/env escript
+
+% TODO :
+% * Create some unit tests with eunit before releasing in production.
+
+main(Args) ->
+ file:set_cwd(".."),
+ case Args of
+ ["build"] -> build();
+ ["run"] -> run_debug();
+ ["pre"] -> in_preprod("gburri@euphorik.ch:/var/www/euphorik_preprod", "var/www/euphorik");
+ ["prod"] -> in_prod("gburri@euphorik.ch:/var/www/euphorik");
+ ["js"] -> verif_js();
+ ["version"] -> update_version();
+ _ ->
+ io:format(
+ "Usage : ~s (build | run | pre | prod | js | version)~n"
+ " prod : in production~n"
+ " pre : in preproduction, data are copied from production~n"
+ " js : check the JavaScript files~n"
+ " version : update the version into somes files from the VERSION file~n",
+ [escript:script_name()]
+ )
+ end.
+
+% A simple fonction to log message.
+log(Str) ->
+ io:format("===== ~s =====~n", [Str]).
+
+% Execute an OS command and print the result to stdout.
+cmd(Command) ->
+ cmd(Command, []).
+cmd(Command, Params) ->
+ cmd(Command, Params, ".").
+cmd(Command, Params, Dir) ->
+ InitialDir = file:get_cwd(),
+ file:set_cwd(Dir),
+ io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Command, Params)))]),
+ file:set_cwd(InitialDir).
+
+-record(uri, {
+ host,
+ path % in absolute
+ }).
+
+% Create an uri record from an uri string.
+create_uri(Uri_str) ->
+ [Host, Path] = string:tokens(Uri_str, ":"),
+ #uri{host = Host, path = Path}.
+
+build() ->
+ % Create the directory "var/database" if it doesn't exist.
+ {ok, Files_in_root} = file:list_dir("."),
+ Var_exists = lists:any(fun(Name) -> Name =:= "var" end, Files_in_root),
+ if not Var_exists ->
+ file:make_dir("var");
+ true -> ok
+ end,
+ {ok, Files_in_var} = file:list_dir("var"),
+ Database_exists = lists:any(fun(Name) -> Name =:= "database" end, Files_in_var),
+ if not Database_exists ->
+ file:make_dir("var/database");
+ true -> ok
+ end,
+ % Build all the Erlang modules.
+ cmd("make", [], "modules").
+
+% Update the version into somes files from the VERSION file.
+update_version() ->
+ log("Update the version tag"),
+ todo.
+
+% Check the JavaScript files.
+verif_js() ->
+ todo.
+
+run_debug() ->
+ build(),
+ todo.
+
+% Start the production processus.
+in_prod(Uri) ->
+ compile_server_part(Uri),
+ make_var_directory(Uri),
+ copy_files(Uri),
+ define_files_rights(Uri),
+ update_server().
+
+% Start the pre-production processus.
+in_preprod(Uri, data_path) ->
+ compile_server_part(Uri),
+ make_var_directory(Uri),
+ copy_files(Uri),
+ define_files_rights(Uri),
+ start_server(),
+ update_server().
+
+% Compile the Erlang modules.
+compile_server_part(Uri) ->
+ todo.
+
+% Create the 'var' folder if it doesn't exist.
+make_var_directory(Uri) ->
+ todo.
+
+% Copy files from developpement env to production server.
+copy_files(Uri) ->
+ copy_static_part(Uri),
+ copy_packed_js(Uri).
+
+% Copy all static files like modules, styles, pages, etc.
+copy_static_part(Uri) ->
+ %~ creer_rep('modules')
+ %~ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules")
+ %~ system("rsync -r modules/include #{@uri}:#{@rep}/modules")
+ todo.
+
+% Minify and pack JavaScript in one file then copy it to ther server.
+copy_packed_js(Uri) ->
+ todo.
+
+% Define the rights for the copied folder et files.
+define_files_rights(Uri) ->
+ todo.
+
+% Start the server if it not already started (in preproduction case only).
+start_server() ->
+ cmd("yaws --conf ./yaws.conf --sname yaws_dev --mnesiadir \"../var/database/\" -I debian_yaws_dev").
+
+% Run a erlang script to
+update_server() ->
+ todo.
#!/usr/bin/env escript
-% coding: utf-8
-% Executé sur le serveur après la copie des fichiers lors de la mise en production.
-% Recharge les modules de euphorik et met à jour la BD.
-% TODO : construire le nom du noeud en fonction du nom de l'host
+% Execute remotly after the files has been copied.
+% Reload all modules et update the database.
+% TODO: build the node name from the host name.
hote() ->
'@overnux'.
% le premier argument est le nom du noeud est peut valoir :
% - yaws : noeud de production
% - yaws_dev : noeud de pre-production
-main([Nom_node]) when Nom_node =:= "yaws"; Nom_node =:= "yaws_dev" ->
- Node = list_to_atom(Nom_node ++ atom_to_list(hote())),
+main([Node_name]) when Node_name =:= "yaws"; Node_name =:= "yaws_dev" ->
+ Node = list_to_atom(Node_name ++ atom_to_list(hote())),
net_kernel:start([flynux, shortnames]),
io:format("rechargement des modules..~n"),
rpc:call(Node, euphorik_daemon, reload_euphorik, []),
- if Nom_node =:= "yaws_dev" -> copier_bd(Node);
+ if Node_name =:= "yaws_dev" -> copy_database(Node);
true -> true
end,
io:format("mise à jour de la BD..~n"),
rpc:call(Node, euphorik_bd_admin, update, []);
main(_) ->
- io:format("Usage : mise_en_prod.erl <node>"),
+ io:format("Usage: update_server.erl <node-name>"),
halt(1).
-% Copie la bd du noeud de production
-copier_bd(Node) ->
- io:format("Copie de la BD de production vers le noeude pre-production~n"),
- Fichier = "/tmp/backup_ek_tmp",
- Fichier2 = "/tmp/backup_ek_tmp2",
- rpc:call(yaws@overnux, mnesia, backup, [Fichier]),
- rpc:call(Node, euphorik_bd_admin, change_node_name, [yaws@overnux, yaws_dev@overnux, Fichier, Fichier2]),
- rpc:call(Node, mnesia, restore, [Fichier2, [{default_op, recreate_tables}]]),
- rpc:call(yaws@overnux, file, delete, [Fichier]),
- rpc:call(Node, file, delete, [Fichier2]).
+% Copy the datbase from the production to pre production.
+copy_database(Node) ->
+ io:format("Copying production database to pre-production node~n"),
+ File = "/tmp/backup_ek_tmp",
+ File2 = "/tmp/backup_ek_tmp2",
+ rpc:call(yaws@overnux, mnesia, backup, [File]),
+ rpc:call(Node, euphorik_bd_admin, change_node_name, [yaws@overnux, yaws_dev@overnux, File, File2]),
+ rpc:call(Node, mnesia, restore, [File2, [{default_op, recreate_tables}]]),
+ rpc:call(yaws@overnux, file, delete, [File]),
+ rpc:call(Node, file, delete, [File2]).