Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 116 lines (93 sloc) 3.24 kB
a6d8e2e Added r1392 from Zotonic svn
marc@zoo.local authored
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>').
32661f5 @mworrell Added test for minimal OTP version (now R14B03) Fixes #427
mworrell authored
22
b6f3e9b @arjan Updated edocs documentation.
arjan authored
23 -export([start/0, start/1, stop/0, stop/1, status/0, status/1, update/0, update/1, run_tests/0, ensure_started/1]).
32661f5 @mworrell Added test for minimal OTP version (now R14B03) Fixes #427
mworrell authored
24
25 -compile([{parse_transform, lager_transform}]).
26
27 -define(MIN_OTP_VERSION, "R14B03").
28
a6d8e2e Added r1392 from Zotonic svn
marc@zoo.local authored
29
30 ensure_started(App) ->
31 case application:start(App) of
32 ok ->
33 ok;
34 {error, {already_started, App}} ->
35 ok
36 end.
37
38 %% @spec start() -> ok
39 %% @doc Start the zotonic server.
40 start() -> start([]).
41
42 %% @spec start(_Args) -> ok
43 %% @doc Start the zotonic server.
44 start(_Args) ->
32661f5 @mworrell Added test for minimal OTP version (now R14B03) Fixes #427
mworrell authored
45 ensure_started(lager),
46 test_erlang_version(),
9d626b9 @AtillaE merged with the new gen_smtp based SMTP implementation
AtillaE authored
47 zotonic_deps:ensure(),
a6d8e2e Added r1392 from Zotonic svn
marc@zoo.local authored
48 ensure_started(crypto),
feca872 @arjan Move webmachine -> webzmachine in its own repository.
arjan authored
49 ensure_started(webzmachine),
9d626b9 @AtillaE merged with the new gen_smtp based SMTP implementation
AtillaE authored
50 ensure_started(mnesia),
daa72b2 @mworrell Check result of application:start(zotonic)
mworrell authored
51 ok = application:start(zotonic).
a6d8e2e Added r1392 from Zotonic svn
marc@zoo.local authored
52
53 %% @spec stop() -> ok
54 %% @doc Stop the zotonic server.
55 stop() ->
56 Res = application:stop(zotonic),
9d626b9 @AtillaE merged with the new gen_smtp based SMTP implementation
AtillaE authored
57 application:stop(mnesia),
e6045a4 @arjan Added lager as logging framework
arjan authored
58 application:stop(lager),
feca872 @arjan Move webmachine -> webzmachine in its own repository.
arjan authored
59 application:stop(webzmachine),
a6d8e2e Added r1392 from Zotonic svn
marc@zoo.local authored
60 application:stop(crypto),
61 Res.
62
63
64 %% @spec stop([Node]) -> void()
65 %% @doc Stop a zotonic server on a specific node
66 stop([Node]) ->
32661f5 @mworrell Added test for minimal OTP version (now R14B03) Fixes #427
mworrell authored
67 io:format("Stopping:~p~n",[Node]),
a6d8e2e Added r1392 from Zotonic svn
marc@zoo.local authored
68 case net_adm:ping(Node) of
69 pong -> rpc:cast(Node, init, stop, []);
70 pang -> io:format("There is no node with this name~n")
71 end,
72 init:stop().
73
74
1d897b2 @AlainODea Very basic "zotonic status" implementation
AlainODea authored
75 %% @spec status() -> ok
b6f3e9b @arjan Updated edocs documentation.
arjan authored
76 %% @doc Print the status of the current node.
77 status() ->
78 status([node()]).
79
80 %% @spec status([node()]) -> ok
81 %% @doc Get server status. Prints the state of sites running.
1d897b2 @AlainODea Very basic "zotonic status" implementation
AlainODea authored
82 status([Node]) ->
84f2439 @arjan Prettified the zotonic status commandline script
arjan authored
83 [io:format("~-20s- ~s~n", [Site, Status]) || [Site,Status|_] <- rpc:call(Node, z_sites_manager, get_sites_status, [])],
1d897b2 @AlainODea Very basic "zotonic status" implementation
AlainODea authored
84 ok.
85
a6d8e2e Added r1392 from Zotonic svn
marc@zoo.local authored
86 %% @spec update() -> ok
87 %% @doc Update the server. Compiles and loads any new code, flushes caches and rescans all modules.
88 update() ->
89 z:m(),
90 ok.
91
92
93 %% @spec update([Node]) -> ok
94 %% @doc Update the server on a specific node with new code on disk and flush the caches.
95 update([Node]) ->
96 io:format("Update:~p~n",[Node]),
97 case net_adm:ping(Node) of
98 pong -> rpc:cast(Node, zotonic, update, []);
99 pang -> io:format("There is no node with this name~n")
100 end,
101 init:stop().
102
32661f5 @mworrell Added test for minimal OTP version (now R14B03) Fixes #427
mworrell authored
103
104 test_erlang_version() ->
105 Version = erlang:system_info(otp_release),
106 if
107 Version < ?MIN_OTP_VERSION ->
108 lager:error("Zotonic needs at least Erlang release ~p; this is ~p", [?MIN_OTP_VERSION, Version]),
109 erlang:exit({minimal_otp_version, ?MIN_OTP_VERSION});
110 true ->
111 ok
112 end.
113
f669eff @arjan Made a start with EUnit tests for zotonic.
arjan authored
114 run_tests() ->
115 z_media_preview_tests:test().
Something went wrong with that request. Please try again.