2011-03-23 09:16:02 +00:00
|
|
|
%% @author Bart Van Der Meerssche <bart.vandermeerssche@flukso.net>
|
|
|
|
%% @copyright (C) 2009-2011 Bart Van Der Meerssche
|
|
|
|
%%%
|
|
|
|
%%% This program is free software: you can redistribute it and/or modify
|
|
|
|
%%% it under the terms of the GNU General Public License as published by
|
|
|
|
%%% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
%%% (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
%%% GNU General Public License for more details.
|
|
|
|
%%%
|
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
%%%
|
|
|
|
%% @doc Flukso module spec
|
2010-02-25 17:45:11 +00:00
|
|
|
|
|
|
|
-module(flukso).
|
2011-03-23 09:16:02 +00:00
|
|
|
-author('Bart Van Der Meerssche <bart.vandermeerssche@flukso.net>').
|
|
|
|
|
2010-02-25 17:45:11 +00:00
|
|
|
-export([start/0, start_link/0, stop/0]).
|
|
|
|
|
|
|
|
ensure_started(App) ->
|
|
|
|
case application:start(App) of
|
|
|
|
ok ->
|
|
|
|
ok;
|
|
|
|
{error, {already_started, App}} ->
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
2010-03-14 20:31:10 +00:00
|
|
|
mysql_prepare() ->
|
2011-03-29 07:45:59 +00:00
|
|
|
mysql:prepare(watchdog, <<"INSERT INTO watchdog (uid, type, message, variables, severity, location, hostname, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?)">>),
|
2011-03-22 20:23:55 +00:00
|
|
|
mysql:prepare(permissions, <<"SELECT permissions FROM logger_tokens WHERE meter = ? AND token = ?">>),
|
2011-04-16 21:52:19 +00:00
|
|
|
mysql:prepare(sensor_key, <<"SELECT sha FROM (logger_devices ld INNER JOIN logger_meters lm ON ld.device = lm.device) WHERE lm.meter = ?">>),
|
2011-03-28 20:21:38 +00:00
|
|
|
mysql:prepare(sensor_props, <<"SELECT uid, device, night FROM logger_meters WHERE meter = ?">>),
|
|
|
|
mysql:prepare(sensor_update, <<"UPDATE logger_meters SET access = ?, night = ?, value = ? WHERE meter = ?">>),
|
2011-04-16 21:52:19 +00:00
|
|
|
mysql:prepare(timezone, <<"SELECT timezone FROM users WHERE uid = ?">>),
|
|
|
|
mysql:prepare(device_key, <<"SELECT sha FROM logger_devices WHERE device = ?">>),
|
|
|
|
mysql:prepare(device_props, <<"SELECT sha, upgrade, resets FROM logger_devices WHERE device = ?">>),
|
|
|
|
mysql:prepare(device_update, <<"UPDATE logger_devices SET access = ?, version = ?, upgrade = ?, resets = ?, uptime = ?, memtotal = ?, memfree = ?, memcached = ?, membuffers = ? WHERE device = ?">>).
|
2010-03-14 20:31:10 +00:00
|
|
|
|
2010-02-25 17:45:11 +00:00
|
|
|
%% @spec start_link() -> {ok,Pid::pid()}
|
|
|
|
%% @doc Starts the app for inclusion in a supervisor tree
|
|
|
|
start_link() ->
|
|
|
|
flukso_deps:ensure(),
|
|
|
|
ensure_started(crypto),
|
2010-03-13 13:00:51 +00:00
|
|
|
ensure_started(erlrrd),
|
|
|
|
ensure_started(mysql),
|
2010-03-14 20:31:10 +00:00
|
|
|
mysql_prepare(),
|
2010-02-25 17:45:11 +00:00
|
|
|
ensure_started(webmachine),
|
|
|
|
flukso_sup:start_link().
|
|
|
|
|
|
|
|
%% @spec start() -> ok
|
|
|
|
%% @doc Start the flukso server.
|
|
|
|
start() ->
|
|
|
|
flukso_deps:ensure(),
|
|
|
|
ensure_started(crypto),
|
2010-03-13 13:00:51 +00:00
|
|
|
ensure_started(erlrrd),
|
|
|
|
ensure_started(mysql),
|
2010-03-14 20:31:10 +00:00
|
|
|
mysql_prepare(),
|
2010-02-25 17:45:11 +00:00
|
|
|
ensure_started(webmachine),
|
2010-03-13 13:00:51 +00:00
|
|
|
application:start(flukso).
|
2010-02-25 17:45:11 +00:00
|
|
|
|
|
|
|
%% @spec stop() -> ok
|
|
|
|
%% @doc Stop the flukso server.
|
|
|
|
stop() ->
|
|
|
|
Res = application:stop(flukso),
|
|
|
|
application:stop(webmachine),
|
2010-03-13 13:00:51 +00:00
|
|
|
application:stop(mysql),
|
|
|
|
application:stop(erlrrd),
|
2010-02-25 17:45:11 +00:00
|
|
|
application:stop(crypto),
|
|
|
|
Res.
|