PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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