Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 2ece399cfd483597bfac4d8da4cc4b5cc7617435 0 parents
@yrashk yrashk authored
3  .gitignore
@@ -0,0 +1,3 @@
+deps
+log
+apps/htoad/ebin
1  apps/htoad/include/htoad.hrl
@@ -0,0 +1 @@
+-compile({parse_transform, lager_transform}).
23 apps/htoad/include/stdlib.hrl
@@ -0,0 +1,23 @@
+-record(init,
+ {
+ }).
+
+-record(htoad,
+ {
+ version
+ }).
+
+-record(host,
+ {
+ name :: undefined | string(),
+ operating_system
+ }).
+
+-record(file,
+ {
+ type = file :: file | dir,
+ path :: undefined | string(),
+ ensure :: undefined | present | absent,
+ mode,
+ content = ""
+ }).
8 apps/htoad/rebar.config
@@ -0,0 +1,8 @@
+{deps,
+ [
+ {lager, ".*", {git, "https://github.com/basho/lager.git", {branch, "master"}}},
+ {esupervisor, ".*", {git, "https://github.com/spawngrid/esupervisor.git", {branch, "master"}}},
+% {seresye, ".*", {git, "https://github.com/afiniate/seresye.git", {branch, "master"}}},
+ {seresye, ".*", {git, "https://github.com/spawngrid/seresye.git", {branch, "alterline"}}}
+ ]
+}.
21 apps/htoad/src/htoad.app.src
@@ -0,0 +1,21 @@
+{application, htoad,
+ [
+ {description, "Hypnotoad Provisioning Tool"},
+ {vsn, git},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ seresye,
+ lager,
+ sasl
+ ]},
+ {mod, { htoad_app, []}},
+ {env, [
+ {modules,
+ [htoad_host,
+ htoad_htoad,
+ htoad_lfs]}
+ ]}
+
+ ]}.
14 apps/htoad/src/htoad.erl
@@ -0,0 +1,14 @@
+-module(htoad).
+-export([start/0]).
+
+start() ->
+ start(htoad).
+
+start(App) ->
+ case application:start(App) of
+ {error, {not_started, Dep}} ->
+ start(Dep),
+ start(App);
+ Other ->
+ Other
+ end.
27 apps/htoad/src/htoad_app.erl
@@ -0,0 +1,27 @@
+-module(htoad_app).
+
+-behaviour(application).
+
+-include_lib("htoad/include/stdlib.hrl").
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ {ok, Pid} = htoad_sup:start_link(),
+ init(),
+ {ok, Pid}.
+
+stop(_State) ->
+ ok.
+
+%% private
+
+init() ->
+ {ok, Modules} = application:get_env(htoad, modules),
+ [ ok = seresye:add_rules(htoad_engine, Module) || Module <- Modules ],
+ seresye:assert(htoad_engine, #init{}).
21 apps/htoad/src/htoad_host.erl
@@ -0,0 +1,21 @@
+-module(htoad_host).
+-include_lib("htoad/include/htoad.hrl").
+-include_lib("htoad/include/stdlib.hrl").
+
+-export([init/2]).
+-rules([init]).
+
+init(Engine, #init{}) ->
+ Engine1 = seresye_engine:assert(Engine, #host{ name = hostname(),
+ operating_system = operating_system() }),
+ lager:debug("Initialized htoad_host"),
+ Engine1.
+
+%% private
+
+hostname() ->
+ {Host, Domain} = {inet_db:gethostname(),inet_db:res_option(domain)},
+ Host ++ "." ++ Domain.
+
+operating_system() ->
+ {os:type(), os:version()}.
20 apps/htoad/src/htoad_htoad.erl
@@ -0,0 +1,20 @@
+-module(htoad_htoad).
+-include_lib("htoad/include/htoad.hrl").
+-include_lib("htoad/include/stdlib.hrl").
+
+-export([init/2]).
+-rules([init]).
+
+init(Engine, #init{}) ->
+ Engine1 = seresye_engine:assert(Engine, #htoad{
+ version = vsn()
+ }),
+ lager:debug("Initialized htoad_htoad"),
+ Engine1.
+
+
+%% private
+
+vsn() ->
+ {ok, Vsn} = application:get_key(htoad, vsn),
+ Vsn.
38 apps/htoad/src/htoad_lfs.erl
@@ -0,0 +1,38 @@
+-module(htoad_lfs).
+-include_lib("htoad/include/htoad.hrl").
+-include_lib("htoad/include/stdlib.hrl").
+
+-export([init/2, ensure_file_present/2,
+ ensure_dir_present/2]).
+-rules([init, ensure_file_present,
+ ensure_dir_present]).
+
+init(Engine, #init{}) ->
+ lager:debug("Initialized htoad_lfs"),
+ Engine.
+
+ensure_file_present(Engine, #file{ ensure = present,
+ type = file
+ } = File) ->
+ file:write_file(File#file.path, File#file.content),
+ lager:debug("Ensured file ~s",[File#file.path]),
+ chmod(File#file.path, File#file.mode),
+ Engine.
+
+ensure_dir_present(Engine, #file{ ensure = present,
+ type = dir
+ } = Dir) ->
+ ok = filelib:ensure_dir(Dir#file.path ++ "/"),
+ lager:debug("Ensured directory ~s",[Dir#file.path]),
+ chmod(Dir#file.path, Dir#file.mode),
+ Engine.
+
+%% private
+chmod(Path, Mode) ->
+ case Mode of
+ undefined ->
+ ok;
+ _ ->
+ file:change_mode(Path, Mode),
+ lager:debug("Ensured ~s mode ~w",[Path, Mode])
+ end.
33 apps/htoad/src/htoad_sup.erl
@@ -0,0 +1,33 @@
+-module(htoad_sup).
+-behaviour(esupervisor).
+-include_lib("esupervisor/include/esupervisor.hrl").
+
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+%% ===================================================================
+%% API functions
+%% ===================================================================
+
+start_link() ->
+ esupervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% ===================================================================
+%% Supervisor callbacks
+%% ===================================================================
+
+
+init([]) ->
+ #one_for_one{
+ children = [
+ #worker{
+ id = htoad_engine,
+ restart = permanent,
+ start_func = {seresye, start, [htoad_engine]}
+ }
+ ]
+ }.
1  rebar.config
@@ -0,0 +1 @@
+{sub_dirs, ["apps/htoad"]}.
Please sign in to comment.
Something went wrong with that request. Please try again.