Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rebarified cb_admin (plus other pending changes as mv news to priv)

  • Loading branch information...
commit b8847042a9a6084f2afbfddcff7ebb9bc112814a 1 parent 4ce2441
@jgordor jgordor authored
View
4 .gitignore
@@ -0,0 +1,4 @@
+ebin/*.beam
+ebin/*.app
+log/*.log
+erl_crash.dump
View
16 Makefile
@@ -1,16 +0,0 @@
-ERL=erl
-APP=cb_admin
-
-all:
- $(ERL) -pa ebin/ -pa ../ChicagoBoss/ebin -eval 'boss_load:load_all_modules_and_emit_app_file($(APP), "ebin")' -s init stop -noshell
-
-clean:
- rm -fv ebin/*.beam
- rm -fv ebin/$(APP).app
-
-update_po:
- $(ERL) -pa ebin -pa ../ChicagoBoss/ebin -eval 'boss_load:load_models("ebin")' -eval 'boss_lang:update_po()' -s init stop -noshell
-
-.PHONY: test
-test:
- $(ERL) -pa ../ChicagoBoss/ebin -run boss_web_test -noshell
View
10 README.md
@@ -6,20 +6,19 @@ This is the admin interface for Chicago Boss, which can be configured as a stand
Installation as a standalone server
-----------------------------------
-This isn't very useful, but it's easy. First make sure ChicagoBoss is built in the parent directory; otherwise modify start.sh and start-dev.sh to point to the ChicagoBoss ebin/ directory on your machine.
+Check your boss.config and make sure that the path's are correct (defaults to ../ChicagoBoss and ../chicagoboss_admin).
Then:
- mkdir log
- make
- ./start.sh
+ ./rebar compile
+ ./init.sh start
Then visit http://localhost:8001/
Installation with an existing CB server
---------------------------------------
-First "make" and add the ebin/ directory to the path of your CB startup scripts (start.sh and start-dev.sh).
+First "./rebar compile" and add the app config section to the boss.config of your existing CB server.
Add something like this to your boss.config:
@@ -28,6 +27,7 @@ Add something like this to your boss.config:
...
]},
{cb_admin, [
+ {path, "../chicagoboss_admin"},
{allow_ip_blocks, ["127.0.0.1"]},
{base_url, "/admin"}
]}].
View
3  boss.config
@@ -1,4 +1,6 @@
[{boss, [
+ {path, "../ChicagoBoss"},
+ {vm_cookie, "abc123"},
{applications, [cb_admin]},
{db_host, "localhost"},
{db_port, 1978},
@@ -11,6 +13,7 @@
{session_exp_time, 525600}
]},
{cb_admin, [
+ {path, "../chicagoboss_admin"},
{allow_ip_blocks, ["127.0.0.1"]},
{base_url, "/admin"}
]}].
View
8 init-dev.sh
@@ -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
View
55 init.sh
@@ -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
View
0  log/.gitignore
No changes.
View
13 src/init/chicagoboss_admin_news.erl → priv/init/cb_admin_01_news.erl
@@ -1,9 +1,16 @@
--module(news).
+-module(cb_admin_01_news).
--export([init/0]).
+-export([init/0, stop/1]).
+% This script is first executed at server startup and should
+% return a list of WatchIDs that should be cancelled in the stop
+% function below (stop is executed if the script is ever reloaded).
init() ->
- ok.
+ {ok, []}.
+
+stop(ListOfWatchIDs) ->
+ lists:map(fun boss_news:cancel_watch/1, ListOfWatchIDs).
+
%%%%%%%%%%% Ideas
% boss_news:watch_set("greetings",
% fun(created, NewGreeting) ->
View
155 priv/rebar/boss_plugin.erl
@@ -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.
View
BIN  rebar
Binary file not shown
View
3  rebar.config
@@ -0,0 +1,3 @@
+{plugin_dir, ["priv/rebar"]}.
+{plugins, [boss_plugin]}.
+{eunit_compile_opts, [{src_dirs, ["src/test"]}]}.
View
2  cb_admin.app.src → src/cb_admin.app.src
@@ -1,6 +1,6 @@
{application, cb_admin, [
{description, "Chicago Boss Admin Interface"},
- {vsn, "0.6.8"},
+ {vsn, "0.7.0"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib, crypto, boss]},
View
0  src/test/eunit/.gitignore
No changes.
View
4 src/test/admin_test.erl → src/test/functional/cb_admin_test.erl
@@ -1,8 +1,8 @@
--module(admin_test).
+-module(cb_admin_test).
-compile(export_all).
start() ->
- boss_web_test:get_request("/hello/world", [],
+ boss_web_test:get_request("/admin", [],
[ fun boss_assert:http_ok/1,
fun(Res) -> boss_assert:link_with_text("\"An Evening With Chicago Boss\"", Res) end,
fun(Res) -> boss_assert:link_with_text("chicagoboss.org", Res) end,
View
8 start-dev.sh
@@ -1,8 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-exec erl -pa $PWD/ebin \
- -pa ../ChicagoBoss/ebin \
- -pa ../ChicagoBoss/deps/*/ebin \
- -boss developing_app cb_admin \
- -boot start_sasl -config boss -s reloader -s boss \
- -sname wildbill
View
2  start-server.bat
@@ -1,2 +0,0 @@
-make
-erl -pa ebin -boot start_sasl -config boss -s reloader -s boss
View
14 start.sh
@@ -1,14 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-# For multi-node setups you need to change the -sname argument for every node
-# and also set the master_node config option. The master node runs global
-# services (sessions, message queue, events, and incoming mail) and should
-# be specified as the atom NodeName@NodeHost
-
-# If your server is running in an untrusted environment, you should probably
-# change the cookie too. (All nodes in a cluster must have the same cookie.)
-exec erl -pa $PWD/ebin \
- -pa ../ChicagoBoss/ebin
- -pa ../ChicagoBoss/deps/*/ebin \
- -boot start_sasl -config boss -s boss -setcookie abc123 -detached \
- -sname john
Please sign in to comment.
Something went wrong with that request. Please try again.