forked from ChicagoBoss/cb_admin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ChicagoBoss#8 from jgordor/master
cb_admin 0.7 compat (rebar)
- Loading branch information
Showing
17 changed files
with
247 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ebin/*.beam | ||
ebin/*.app | ||
log/*.log | ||
erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env sh | ||
# | ||
# Chicago Boss Dev Init System | ||
# easy start dev server (most common task) | ||
|
||
cd `dirname $0` | ||
|
||
./init.sh start-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env sh | ||
# | ||
# Chicago Boss Init System | ||
# | ||
# @author: Jose Luis Gordo Romero <jgordor@gmail.com> | ||
# | ||
# ------------------------------------------------------------------- | ||
# The shell commands are automatically generated by the boss rebar | ||
# plugin/driver, all configuration params and paths are in boss.config | ||
# ------------------------------------------------------------------- | ||
|
||
cd `dirname $0` | ||
|
||
case "${1:-''}" in | ||
'start') | ||
# Start Boss in production mode | ||
echo "starting boss in production mode..." | ||
START=$(./rebar boss c=start_cmd|grep -v "==>") | ||
$START | ||
;; | ||
|
||
'start-dev') | ||
# Start Boss in development mode | ||
START_DEV=$(./rebar boss c=start_dev_cmd|grep -v "==>") | ||
$START_DEV | ||
;; | ||
|
||
'stop') | ||
# Stop Boss daemon | ||
echo "stopping boss..." | ||
STOP=$(./rebar boss c=stop_cmd|grep -v "==>") | ||
# After hours of shell quoting problems with the erl command, | ||
# eval with the command quoted works!!! | ||
eval "$STOP" | ||
;; | ||
|
||
'reload') | ||
# Boss hot code reload <-- only the actual node, not the entire cluster | ||
echo "Hot code reload, (WARN: Only this node)" | ||
RELOAD=$(./rebar boss c=reload_cmd|grep -v "==>") | ||
eval "$RELOAD" | ||
;; | ||
|
||
'restart') | ||
# Boss complete restart | ||
echo "Restarting (stop-start) boss..." | ||
$0 stop | ||
$0 start | ||
;; | ||
*) | ||
echo "Chicago Boss Boot System" | ||
echo "Usage: $SELF start|start-dev|stop|reload|restart" | ||
exit 1 | ||
;; | ||
esac |
Empty file.
13 changes: 10 additions & 3 deletions
13
src/init/chicagoboss_admin_news.erl → priv/init/cb_admin_01_news.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% @author Jose Luis Gordo Romero <jgordor@gmail.com> | ||
%%% @doc Chicago Boss rebar plugin | ||
%%% Manage compilation/configuration/scripts stuff the rebar way | ||
%%% @end | ||
%%%------------------------------------------------------------------- | ||
-module(boss_plugin). | ||
|
||
-export([boss/2, | ||
pre_compile/2, | ||
pre_eunit/2]). | ||
|
||
-define(BOSS_CONFIG, "boss.config"). | ||
|
||
%% ==================================================================== | ||
%% Public API | ||
%% ==================================================================== | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @doc boss command | ||
%% @spec boss(_Config, _AppFile) -> ok | {error, Reason} | ||
%% Boss enabled rebar commands, usage: | ||
%% ./rebar boss c=command | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
boss(RebarConf, AppFile) -> | ||
{ok, BossConf} = init(RebarConf, AppFile), | ||
case is_base_dir() of | ||
true -> | ||
Command = rebar_config:get_global(c, "help"), | ||
case boss_rebar:run(Command, RebarConf, BossConf, AppFile) of | ||
{error, command_not_found} -> | ||
io:format("ERROR: boss command not found.~n"), | ||
boss_rebar:help(), | ||
halt(1); | ||
{error, Reason} -> | ||
io:format("ERROR: executing ~s task: ~s~n", [Command, Reason]), | ||
halt(1); | ||
ok -> ok | ||
end; | ||
false -> ok | ||
end. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @doc initializes the rebar boss connector plugin | ||
%% @spec init(Config, AppFile) -> {ok, BossConf} | {error, Reason} | ||
%% Set's the ebin cb_apps and loads the connector | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
init(_RebarConf, AppFile) -> | ||
%% Compile and load the boss_rebar code, this can't be compiled | ||
%% as a normal boss lib without the rebar source dep | ||
%% The load of ./rebar boss: | ||
%% - Rebar itself searchs in rebar.config for {plugin_dir, ["priv/rebar"]}. | ||
%% - Rebar itself compile this plugin and adds it to the execution chain | ||
%% - This plugin compiles and loads the boss_rebar code in ["cb/priv/rebar"], | ||
%% so we can extend/bugfix/tweak the framework without the need of manually | ||
%% recopy code to user apps | ||
BossPath = case boss_config_value(boss, path) of | ||
{error, _} -> | ||
io:format("FATAL: Failed to read boss=>path config in boss.config.~n"), | ||
halt(1); | ||
Val -> Val | ||
end, | ||
RebarErls = rebar_utils:find_files(filename:join([BossPath, "priv", "rebar"]), ".*\\.erl\$"), | ||
|
||
rebar_log:log(debug, "Auto-loading boss rebar modules ~p~n", [RebarErls]), | ||
|
||
lists:map(fun(F) -> | ||
case compile:file(F, [binary]) of | ||
error -> | ||
io:format("FATAL: Failed compilation of ~s module~n", [F]), | ||
halt(1); | ||
{ok, M, Bin} -> | ||
{module, _} = code:load_binary(M, F, Bin), | ||
rebar_log:log(debug, "Loaded ~s~n", [M]) | ||
end | ||
end, RebarErls), | ||
|
||
BossConf = boss_config(), | ||
|
||
%% add all cb_apps defined in boss.config to code path | ||
%% including the deps ebin dirs | ||
[code:add_path(CodePath) || CodePath <- boss_rebar:all_ebin_dirs(BossConf, AppFile)], | ||
|
||
{ok, BossConf}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @doc pre_compile hook | ||
%% @spec pre_compile(_Config, AppFile) -> ok | {error, Reason} | ||
%% Pre compile hook, compile the boss way | ||
%% Compatibility hook, the normal ./rebar compile command works, | ||
%% but only calls the ./rebar boss c=compile and halts (default | ||
%% rebar task never hits) | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
pre_compile(RebarConf, AppFile) -> | ||
{ok, BossConf} = init(RebarConf, AppFile), | ||
case is_base_dir() of | ||
true -> | ||
boss_rebar:run(compile, RebarConf, BossConf, AppFile), | ||
halt(0); | ||
false -> ok | ||
end. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @doc pre_eunit hook | ||
%% @spec pre_eunit(RebarConf, AppFile) -> ok | {error, Reason} | ||
%% Pre eunit hook, .eunit compilation the boss way | ||
%% Compatibility hook, the normal ./rebar eunit command works, | ||
%% but only calls the ./rebar boss c=test_eunit and halts | ||
%% (default rebar task never hits) | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
pre_eunit(RebarConf, AppFile) -> | ||
{ok, BossConf} = init(RebarConf, AppFile), | ||
case is_base_dir() of | ||
true -> | ||
boss_rebar:run(test_eunit, RebarConf, BossConf, AppFile), | ||
halt(0); | ||
false -> ok | ||
end. | ||
|
||
%% =================================================================== | ||
%% Internal functions | ||
%% =================================================================== | ||
|
||
%% Checks if the current dir (rebar execution) is the base_dir | ||
%% Used to prevent run boss tasks in deps directory | ||
is_base_dir() -> | ||
rebar_utils:get_cwd() == rebar_config:get_global(base_dir, undefined). | ||
|
||
%% Gets the boss.config central configuration file | ||
boss_config() -> | ||
{ok, BossConfig} = file:consult(?BOSS_CONFIG), | ||
hd(BossConfig). | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @doc Get Boss config value app, key | ||
%% @spec boss_config_value(App, Key) -> Value | {error, Reason} | ||
%% Searchs in boss config for a given App and Key | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
boss_config_value(App, Key) -> | ||
case lists:keyfind(App, 1, boss_config()) of | ||
false -> | ||
{error, boss_config_app_not_found}; | ||
{App, AppConfig} -> | ||
case lists:keyfind(Key, 1, AppConfig) of | ||
false -> | ||
{error, boss_config_app_setting_not_found}; | ||
{Key, KeyConfig} -> | ||
KeyConfig | ||
end | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{plugin_dir, ["priv/rebar"]}. | ||
{plugins, [boss_plugin]}. | ||
{eunit_compile_opts, [{src_dirs, ["src/test"]}]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
4 changes: 2 additions & 2 deletions
4
src/test/admin_test.erl → src/test/functional/cb_admin_test.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.