/src/zotonic.erl

https://code.google.com/p/zotonic/ · Erlang · 96 lines · 48 code · 16 blank · 32 comment · 0 complexity · d61a5b825ab67d089b62c85163b0778e MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2009 Marc Worrell
  3. %% @doc Start/stop functions for Zotonic
  4. %% Copyright 2009 Marc Worrell
  5. %%
  6. %% Licensed under the Apache License, Version 2.0 (the "License");
  7. %% you may not use this file except in compliance with the License.
  8. %% You may obtain a copy of the License at
  9. %%
  10. %% http://www.apache.org/licenses/LICENSE-2.0
  11. %%
  12. %% Unless required by applicable law or agreed to in writing, software
  13. %% distributed under the License is distributed on an "AS IS" BASIS,
  14. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. %% See the License for the specific language governing permissions and
  16. %% limitations under the License.
  17. -module(zotonic).
  18. -author('Marc Worrell <marc@worrell.nl>').
  19. -export([start/0, start/1, stop/0, stop/1, status/0, status/1, update/0, update/1, run_tests/0, ensure_started/1]).
  20. -revision("$Id$").
  21. ensure_started(App) ->
  22. case application:start(App) of
  23. ok ->
  24. ok;
  25. {error, {already_started, App}} ->
  26. ok
  27. end.
  28. %% @spec start() -> ok
  29. %% @doc Start the zotonic server.
  30. start() -> start([]).
  31. %% @spec start(_Args) -> ok
  32. %% @doc Start the zotonic server.
  33. start(_Args) ->
  34. zotonic_deps:ensure(),
  35. ensure_started(crypto),
  36. ensure_started(webmachine),
  37. ensure_started(mnesia),
  38. ok = application:start(zotonic).
  39. %% @spec stop() -> ok
  40. %% @doc Stop the zotonic server.
  41. stop() ->
  42. Res = application:stop(zotonic),
  43. application:stop(mnesia),
  44. application:stop(webmachine),
  45. application:stop(crypto),
  46. Res.
  47. %% @spec stop([Node]) -> void()
  48. %% @doc Stop a zotonic server on a specific node
  49. stop([Node]) ->
  50. io:format("Stop:~p~n",[Node]),
  51. case net_adm:ping(Node) of
  52. pong -> rpc:cast(Node, init, stop, []);
  53. pang -> io:format("There is no node with this name~n")
  54. end,
  55. init:stop().
  56. %% @spec status() -> ok
  57. %% @doc Print the status of the current node.
  58. status() ->
  59. status([node()]).
  60. %% @spec status([node()]) -> ok
  61. %% @doc Get server status. Prints the state of sites running.
  62. status([Node]) ->
  63. io:format("~p~n", [rpc:call(Node, z_sites_manager, get_sites_status, [])]),
  64. ok.
  65. %% @spec update() -> ok
  66. %% @doc Update the server. Compiles and loads any new code, flushes caches and rescans all modules.
  67. update() ->
  68. z:m(),
  69. ok.
  70. %% @spec update([Node]) -> ok
  71. %% @doc Update the server on a specific node with new code on disk and flush the caches.
  72. update([Node]) ->
  73. io:format("Update:~p~n",[Node]),
  74. case net_adm:ping(Node) of
  75. pong -> rpc:cast(Node, zotonic, update, []);
  76. pang -> io:format("There is no node with this name~n")
  77. end,
  78. init:stop().
  79. run_tests() ->
  80. z_media_preview_tests:test().