Permalink
Browse files

Adding a full release example, creating boot script, etc

  • Loading branch information...
1 parent a6c4572 commit 32281eb830c27d5db8c62730a9386c2d305c0247 Christian committed with Jan 8, 2011
View
@@ -0,0 +1,4 @@
+*.spec
+*.boot
+*.script
+etc
View
@@ -0,0 +1 @@
+1.0
View
@@ -3,7 +3,7 @@ ERL=erl
.PHONY: all src test clean
all: src
- ./app.escript `git rev-list HEAD --max-count=1` > ebin/iserve.app
+ ./app.escript `cat LATEST_VERSION` > ebin/iserve.app
src:
$(MAKE) -C src
@@ -15,6 +15,9 @@ clean:
$(MAKE) -C src clean
$(MAKE) -C test clean
+examples: all
+ $(MAKE) -C examples/iserve_system
+
test.spec: test.spec.in
cat test.spec.in | sed -e "s,@PATH@,$(PWD)," > $(PWD)/test.spec
cover.spec: cover.spec.in
View
@@ -1,19 +1,13 @@
-h2. Steps to get a simple test up:
+h2. Steps to get a web server up:
# cd iserve
-# make test
-# erl -pa ./test
- application:start(sasl).
- application:start(iserve).
- iserve:add_server(iserve_master, 6464, iserve_test, x).
-# Point your browser to http://localhost:6464/
+# make examples
+# cd examples/iserve_system
+# erl -boot iserve_system
+Finally, point your browser to http://localhost:6464/
-You can add more http listeners, on other ports, served by other callback modules.
-
- iserve:add_server(iserve_master, 6465, iserve_test2, x).
-
-Then point your browser at http://localhost:6465/
+Inspect src/iserve_system_app.erl and src/iserve_system_cb.erl for the source code for this app, and ebin/iserve_system.app for the configuration of it.
View
@@ -1,25 +1,22 @@
#!/usr/bin/env escript
-template() ->
+template(Vsn) ->
{application, iserve,
- [{description, "Web Server"},
- {vsn, "%ISERVE_VSN%"},
+ [{description, "IServe Web Server"},
+ {vsn, Vsn},
{modules, [
iserve_sup,
iserve_app,
iserve_server,
iserve_socket
]},
-
{registered, [ iserve_sup]},
{applications, [kernel, stdlib, sasl]},
- {mod, {iserve_app, []}},
- {env, [{port, 8080}, {callback, iserve_test}]}]}.
+ {mod, {iserve_app, []}},
+ {env, []}
+ ]}.
main([VSN]) ->
- {application, Name, Settings} = template(),
- D1 = dict:from_list(Settings),
- D2 = dict:store(vsn, VSN, D1),
- AppOut = {application, Name, dict:to_list(D2)},
+ AppOut = template(VSN),
io:fwrite('~p.~n', [AppOut]).
@@ -0,0 +1 @@
+*.rel
@@ -0,0 +1,13 @@
+
+
+.PHONY: all src test clean
+all: src
+ ../../rel.escript iserve_system "IServe system" "1.0" > iserve_system.rel
+ erl -pa ebin -noinput -eval 'systools:make_script("iserve_system").' -s erlang halt
+
+src:
+ cd src && erl -make
+
+clean:
+ rm -f ebin/*.beam
+
@@ -0,0 +1 @@
+*.beam
@@ -0,0 +1,8 @@
+{application,iserve_system,
+ [{applications,[kernel,stdlib,sasl,iserve]},
+ {modules,[iserve_system_app, iserve_system_cb]},
+ {mod,{iserve_system_app,[]}},
+ {registered,[]},
+ {env,[{port,6464},{callback,iserve_system_cb}]},
+ {vsn,"1.0"},
+ {description,"Web Server Example"}]}.
@@ -0,0 +1,4 @@
+{['*'],
+ [{outdir,"../ebin"},debug_info]}.
+
+
@@ -0,0 +1,16 @@
+-module(iserve_system_app).
+-behaviour(application).
+
+-export([
+ start/2,
+ stop/1
+ ]).
+
+start(_Type, _StartArgs) ->
+ {ok, Callback} = application:get_env(callback),
+ {ok, Port} = application:get_env(port),
+ {ok, Server} = iserve:add_server(iserve_master, Port, Callback, x),
+ {ok, Server}.
+
+stop(_State) ->
+ ok.
@@ -0,0 +1,30 @@
+-module(iserve_system_cb).
+-export([start/1, iserve_request/2]).
+-include_lib("iserve/include/iserve.hrl").
+
+-behaviour(iserve).
+
+
+start(Port) ->
+ iserve:add_server(iserve_master, Port, ?MODULE, none).
+
+iserve_request(_C, Req) ->
+ error_logger:info_report(
+ lists:zip(record_info(fields, req), tl(tuple_to_list(Req)))),
+
+ Headers = [{'Content-Type', "text/html"}],
+ iserve:reply_ok(Headers, body_ok()).
+
+body_ok() ->
+ <<"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
+<html>
+<head>
+ <title>Welcome to iserve</title>
+</head>
+<body>
+ <h1>Welcome</h1>
+ this is iserve.
+</body>
+</html>
+">>.
+
View
@@ -0,0 +1,19 @@
+#!/usr/bin/env escript
+%%! -pa ebin
+
+release(Name, Vsn, Apps) ->
+ {release, {Name, Vsn}, {erts, erlang:system_info(version)}, Apps}.
+
+appvsn(App) ->
+ application:load(App),
+ {ok, Vsn} = application:get_key(App, vsn),
+ {App, Vsn}.
+
+main([AppStr, AppName, AppVsn]) ->
+ App = list_to_atom(AppStr),
+ application:load(App),
+ {ok, AppMods} = application:get_key(App, applications),
+ Apps = [appvsn(Mod) || Mod <- AppMods ++ [App]],
+ RelOut = release(AppName, AppVsn, Apps),
+ io:fwrite('~p.~n', [RelOut]).
+
View
@@ -1,8 +0,0 @@
-%% -*- mode: Erlang; -*-
-{application, iserve_example,
- [{description, "Web Server Example"},
- {vsn, "1"},
- {modules, [iserve_example]},
- {applications, [iserve]},
- {mod, {iserve_example, []}},
- {env, [{port, 8080}]}]}.
@@ -1,6 +1,6 @@
-module(iserve_test).
-export([start/1, iserve_request/2]).
--include("../include/iserve.hrl").
+-include_lib("iserve/include/iserve.hrl").
-behaviour(iserve).
@@ -1,6 +1,6 @@
-module(iserve_test2).
-export([start/1, iserve_request/2]).
--include("../include/iserve.hrl").
+-include_lib("iserve/include/iserve.hrl").
-behaviour(iserve).
@@ -9,7 +9,7 @@
-export([start/2, iserve_request/2]).
--include("../include/iserve.hrl").
+-include_lib("iserve/include/iserve.hrl").
-include_lib("kernel/include/file.hrl").
-behaviour(iserve).

0 comments on commit 32281eb

Please sign in to comment.