Permalink
Browse files

Overhaul release setup and use standard Makefile

- estatsd code is now in a top level src/ directory

- OTP release is built with updated start scripts using erlexec
  instead of run_erl.

- release now includes eper for redbug and lock deps plugin
  • Loading branch information...
1 parent 0c46fff commit 1985f590f0d4a4d39f93c0d6abe2ba5e7159a63c @seth seth committed Nov 27, 2012
View
8 .gitignore
@@ -1,4 +1,6 @@
-apps/estatsd/ebin/*
-deps
+ebin/*
+*.beam
+deps/*
rel/estatsd
-.eunit
+
+
View
94 Makefile
@@ -1,26 +1,94 @@
+DEPS=$(CURDIR)/deps
+
+# The release branch should have a file named USE_REBAR_LOCKED
+use_locked_config = $(wildcard USE_REBAR_LOCKED)
+ifeq ($(use_locked_config),USE_REBAR_LOCKED)
+ rebar_config = rebar.config.lock
+else
+ rebar_config = rebar.config
+endif
+REBAR = rebar -C $(rebar_config)
+
all: compile
-compile:
- @rebar compile
+compile: $(DEPS)
+ @$(REBAR) compile
+compile_skip:
+ @$(REBAR) compile skip_deps=true
+
+# For a release-only project, this won't make much sense, but could be
+# useful for release projects that have their own code
clean:
- @rebar skip_deps=true clean
+ @$(REBAR) clean skip_deps=true
+
+allclean:
+ @$(REBAR) clean
+
+update: compile
+ @cd rel/estatsd;bin/estatsd restart
+
+distclean: relclean
+ @rm -rf deps
+ @$(REBAR) clean
+ @rm -rf rel/apps rel/rebar.config
+
+tags: TAGS
-depclean:
- @rebar clean
+TAGS:
+ find deps -name "*.[he]rl" -print | etags -
+
+# Only do munge_apps if we have files in src/
+all_src_files = $(wildcard src/*)
+ifeq ($(strip $(all_src_files)),)
+munge_apps:
+ @true
+else
+munge_apps:
+ @mkdir -p rel/apps/estatsd
+ @ln -sf `pwd`/ebin rel/apps/estatsd
+ @ln -sf `pwd`/priv rel/apps/estatsd
+ @cp rebar.config rel
+ @echo '{deps_dir, ["../deps"]}.' >> rel/rebar.config
+endif
+
+generate: munge_apps
+ @/bin/echo 'building OTP release package for estatsd'
+ @/bin/echo "using rebar as: $(REBAR)"
+ @cd rel;$(REBAR) generate
+ @rm -rf rel/apps rel/rebar.config
+
+rel: rel/estatsd
+
+devrel: rel
+ @/bin/echo -n Symlinking deps and apps into release
+ @$(foreach dep,$(wildcard deps/*), /bin/echo -n .;rm -rf rel/estatsd/lib/$(shell basename $(dep))-* \
+ && ln -sf $(abspath $(dep)) rel/estatsd/lib;)
+ @rm -rf rel/estatsd/lib/estatsd-*;mkdir -p rel/estatsd/lib/estatsd
+ @ln -sf `pwd`/ebin rel/estatsd/lib/estatsd
+ @ln -sf `pwd`/priv rel/estatsd/lib/estatsd
+ @/bin/echo done.
+ @/bin/echo Run \'make update\' to pick up changes in a running VM.
+
+rel/estatsd: compile generate
relclean:
@rm -rf rel/estatsd
-distclean: clean relclean
+$(DEPS):
+ @echo "Fetching deps as: $(REBAR)"
+ @$(REBAR) get-deps
-rel: compile rel/estatsd
+prepare_release: distclean unlocked_deps rel lock_deps
+ @echo 'release prepared, bumping version'
+ @touch USE_REBAR_LOCKED
+ @$(REBAR) bump-rel-version
-devrel: rel
- @$(foreach dep,$(wildcard deps/*), rm -rf rel/estatsd/lib/$(shell basename $(dep))-* && ln -sf $(abspath $(dep)) rel/estatsd/lib;)
- @rm -rf rel/estatsd/lib/estatsd-*;ln -s $(abspath apps/estatsd) rel/estatsd/lib
+unlocked_deps:
+ @echo 'Fetching deps as: rebar -C rebar.config'
+ @rebar -C rebar.config get-deps
-rel/estatsd:
- @rebar generate
+lock_deps:
+ @rebar lock-deps skip_deps=true
-deploy: relclean rel
+.PHONY: distclean prepare_release lock_deps unlocked_deps update clean compile compile_skip allclean tags relclean devrel rel relclean generate munge_apps
View
13 rebar.config
@@ -2,4 +2,15 @@
%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
-{sub_dirs, ["apps/estatsd", "rel"]}.
+{deps,
+ [
+ {rebar_lock_deps_plugin, ".*",
+ {git, "git://github.com/seth/rebar_lock_deps_plugin.git", "master"}},
+ {eper, ".*",
+ {git, "git://github.com/massemanet/eper.git", {branch, "master"}}}
+ ]}.
+
+%% Plugin usage
+{plugins, [rebar_lock_deps_plugin]}.
+
+{cover_enabled, true}.
View
36 rel/files/estatsd
@@ -8,9 +8,13 @@ RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*}
RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc
RUNNER_LOG_DIR=$RUNNER_BASE_DIR/log
# Note the trailing slash on $PIPE_DIR/
-PIPE_DIR=/tmp/$RUNNER_BASE_DIR/
+PIPE_DIR=$RUNNER_BASE_DIR/pipe_dir/
RUNNER_USER=
+## Set the erlang log size
+export RUN_ERL_LOG_MAXSIZE=10000000
+export RUN_ERL_LOG_ALIVE_FORMAT=%d-%b-%Y::%H:%M:%S
+
# Make sure this script is running as the appropriate user
if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
exec sudo -u $RUNNER_USER -i $0 $@
@@ -53,20 +57,21 @@ NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
# Check the first argument for instructions
case "$1" in
runit)
- # Make sure there is not already a node running
- RES=`$NODETOOL ping`
- if [ "$RES" = "pong" ]; then
- echo "Node is already running!"
- exit 1
- fi
- HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT start"
- export HEART_COMMAND
- mkdir -p $PIPE_DIR
- shift # remove $1
- # no -daemon and no exec for use with runit
- $ERTS_PATH/run_erl $PIPE_DIR $RUNNER_LOG_DIR "$RUNNER_BASE_DIR/bin/$SCRIPT console $@" 2>&1
- ;;
+ BOOTFILE=$SCRIPT
+ # Setup beam-required vars
+ ROOTDIR=$RUNNER_BASE_DIR
+ BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
+ EMU=beam
+ PROGNAME=`echo $0 | sed 's/.*\\///'`
+ CMD="$BINDIR/erlexec -noshell -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -embedded -config $RUNNER_ETC_DIR/sys.config -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
+ export EMU
+ export ROOTDIR
+ export BINDIR
+ export PROGNAME
+ # Start the VM
+ exec $CMD
+ ;;
start)
# Make sure there is not already a node running
RES=`$NODETOOL ping`
@@ -78,7 +83,6 @@ case "$1" in
export HEART_COMMAND
mkdir -p $PIPE_DIR
shift # remove $1
- # no -daemon and no exec for use with runit
$ERTS_PATH/run_erl -daemon $PIPE_DIR $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT console $@" 2>&1
;;
@@ -146,7 +150,7 @@ case "$1" in
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\\///'`
- CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -embedded -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
+ CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -embedded -config $RUNNER_ETC_DIR/sys.config -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
export EMU
export ROOTDIR
export BINDIR
View
0 rel/files/app.config → rel/files/sys.config
File renamed without changes.
View
4 rel/files/vm.args
@@ -17,3 +17,7 @@
## Tweak GC to run more often
-env ERL_FULLSWEEP_AFTER 10
+
+## Increase logfile size to 10M
+-env RUN_ERL_LOG_MAXSIZE 10000000
+
View
56 rel/reltool.config
@@ -1,40 +1,22 @@
-{sys, [
- {lib_dirs, ["../apps"]},
- {rel, "estatsd", "1.0.0",
- [
- kernel,
- stdlib,
- sasl,
- crypto,
- inets,
- estatsd
- ]},
- {rel, "start_clean", "",
- [
- kernel,
- stdlib
- ]},
- {boot_rel, "estatsd"},
- {profile, embedded},
- {excl_sys_filters, ["^bin/.*",
- "^erts.*/bin/(dialyzer|typer)"]},
- {excl_archive_filters, [".*"]},
- {app, eunit, [{incl_cond, include}]},
- {app, sasl, [{incl_cond, include}]},
- {app, crypto, [{incl_cond, include}]},
- {app, inets, [{incl_cond, include}]},
- {app, estatsd, [{incl_cond, include}]}
- ]}.
-
-{target_dir, "estatsd"}.
+{sys,[{lib_dirs,["apps", "../deps"]},
+ {rel,"estatsd","1.0.0",[kernel,stdlib,sasl,crypto,inets,estatsd]},
+ {rel,"start_clean",[],[kernel,stdlib]},
+ {boot_rel,"estatsd"},
+ {profile,embedded},
+ {excl_sys_filters,["^bin/.*","^erts.*/bin/(dialyzer|typer)"]},
+ {excl_archive_filters,[".*"]},
+ {app,sasl,[{incl_cond,include}]},
+ {app,crypto,[{incl_cond,include}]},
+ {app,runtime_tools,[{incl_cond,include}]},
+ {app,eper,[{incl_cond,include}]}]}.
+{target_dir,"estatsd"}.
{overlay_vars, "vars.config"}.
-{overlay, [
- {mkdir, "log/sasl"},
- {copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
- {copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
- {copy, "files/estatsd", "bin/estatsd"},
- {template, "files/app.config", "etc/app.config"},
- {copy, "files/vm.args", "etc/vm.args"}
- ]}.
+{overlay,[{mkdir,"log/sasl"},
+ {mkdir,"etc/keys"},
+ {copy,"files/erl","\{\{erts_vsn\}\}/bin/erl"},
+ {copy,"files/nodetool","\{\{erts_vsn\}\}/bin/nodetool"},
+ {copy,"files/estatsd","bin/estatsd"},
+ {copy,"files/vm.args","etc/vm.args"},
+ {template,"files/sys.config","etc/sys.config"}]}.
View
6 apps/estatsd/src/estatsd.app.src → src/estatsd.app.src
@@ -5,8 +5,10 @@
{registered, []},
{applications, [
kernel,
- stdlib
+ stdlib,
+ crypto,
+ inets
]},
- {mod, { estatsd_app, []}},
+ {mod, {estatsd_app, []}},
{env, []}
]}.
View
0 apps/estatsd/src/estatsd.erl → src/estatsd.erl
File renamed without changes.
View
0 apps/estatsd/src/estatsd.hrl → src/estatsd.hrl
File renamed without changes.
View
0 apps/estatsd/src/estatsd_app.erl → src/estatsd_app.erl
File renamed without changes.
View
0 apps/estatsd/src/estatsd_server.erl → src/estatsd_server.erl
File renamed without changes.
View
0 apps/estatsd/src/estatsd_shp.erl → src/estatsd_shp.erl
File renamed without changes.
View
0 apps/estatsd/src/estatsd_sup.erl → src/estatsd_sup.erl
File renamed without changes.
View
0 apps/estatsd/src/estatsd_udp.erl → src/estatsd_udp.erl
File renamed without changes.

0 comments on commit 1985f59

Please sign in to comment.