Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial check-in

  • Loading branch information...
commit f3514704c61a8483d22fda07a7f8aff74a686760 0 parents
Marcel Neuhausler authored
19 Makefile
@@ -0,0 +1,19 @@
+ERL ?= erl
+APP := cloudrover
+
+.PHONY: deps
+
+all: deps
+ @./rebar compile
+
+deps:
+ @./rebar get-deps
+
+clean:
+ @./rebar clean
+
+distclean: clean
+ @./rebar delete-deps
+
+docs:
+ @erl -noshell -run edoc_run application '$(APP)' '"."' '[]'
35 README
@@ -0,0 +1,35 @@
+Project Skeleton for the cloudrover app.
+
+You should find in this directory:
+
+README : this file
+Makefile : simple make commands
+rebar : the Rebar build tool for Erlang applications
+rebar.config : configuration for Rebar
+start.sh : simple startup script for running cloudrover
+/ebin
+ /cloudrover.app : the Erlang app specification
+/src
+ /cloudrover_app.erl : base module for the Erlang application
+ /cloudrover_sup.erl : OTP supervisor for the application
+ /cloudrover_resource.erl : a simple example Webmachine resource
+/priv
+ /dispatch.conf : the Webmachine URL-dispatching table
+ /www : a convenient place to put your static web content
+
+You probably want to do one of a couple of things at this point:
+
+0. Build the skeleton application:
+ $ make
+ - or -
+ $ ./rebar compile
+
+1. Start up the skeleton application:
+ $ ./start.sh
+
+2. Change the basic application:
+ edit src/cloudrover_resource.erl
+
+3. Add some new resources:
+ edit src/YOUR_NEW_RESOURCE.erl
+ edit priv/dispatch.conf
2  priv/dispatch.conf
@@ -0,0 +1,2 @@
+%%-*- mode: erlang -*-
+{[], cloudrover_resource, []}.
BIN  rebar
Binary file not shown
3  rebar.config
@@ -0,0 +1,3 @@
+%%-*- mode: erlang -*-
+
+{deps, [{webmachine, "1.9.*", {git, "git://github.com/basho/webmachine", "HEAD"}}]}.
18 src/cloudrover.app.src
@@ -0,0 +1,18 @@
+%%-*- mode: erlang -*-
+{application, cloudrover,
+ [
+ {description, "cloudrover"},
+ {vsn, "1"},
+ {modules, []},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ inets,
+ crypto,
+ mochiweb,
+ webmachine
+ ]},
+ {mod, { cloudrover_app, []}},
+ {env, []}
+ ]}.
48 src/cloudrover.erl
@@ -0,0 +1,48 @@
+%% @author author <author@example.com>
+%% @copyright YYYY author.
+
+%% @doc cloudrover startup code
+
+-module(cloudrover).
+-author('author <author@example.com>').
+-export([start/0, start_link/0, stop/0]).
+
+ensure_started(App) ->
+ case application:start(App) of
+ ok ->
+ ok;
+ {error, {already_started, App}} ->
+ ok
+ end.
+
+%% @spec start_link() -> {ok,Pid::pid()}
+%% @doc Starts the app for inclusion in a supervisor tree
+start_link() ->
+ ensure_started(inets),
+ ensure_started(crypto),
+ ensure_started(mochiweb),
+ application:set_env(webmachine, webmachine_logger_module,
+ webmachine_logger),
+ ensure_started(webmachine),
+ cloudrover_sup:start_link().
+
+%% @spec start() -> ok
+%% @doc Start the cloudrover server.
+start() ->
+ ensure_started(inets),
+ ensure_started(crypto),
+ ensure_started(mochiweb),
+ application:set_env(webmachine, webmachine_logger_module,
+ webmachine_logger),
+ ensure_started(webmachine),
+ application:start(cloudrover).
+
+%% @spec stop() -> ok
+%% @doc Stop the cloudrover server.
+stop() ->
+ Res = application:stop(cloudrover),
+ application:stop(webmachine),
+ application:stop(mochiweb),
+ application:stop(crypto),
+ application:stop(inets),
+ Res.
21 src/cloudrover_app.erl
@@ -0,0 +1,21 @@
+%% @author author <author@example.com>
+%% @copyright YYYY author.
+
+%% @doc Callbacks for the cloudrover application.
+
+-module(cloudrover_app).
+-author('author <author@example.com>').
+
+-behaviour(application).
+-export([start/2,stop/1]).
+
+
+%% @spec start(_Type, _StartArgs) -> ServerRet
+%% @doc application start callback for cloudrover.
+start(_Type, _StartArgs) ->
+ cloudrover_sup:start_link().
+
+%% @spec stop(_State) -> ServerRet
+%% @doc application stop callback for cloudrover.
+stop(_State) ->
+ ok.
13 src/cloudrover_resource.erl
@@ -0,0 +1,13 @@
+%% @author author <author@example.com>
+%% @copyright YYYY author.
+%% @doc Example webmachine_resource.
+
+-module(cloudrover_resource).
+-export([init/1, to_html/2]).
+
+-include_lib("webmachine/include/webmachine.hrl").
+
+init([]) -> {ok, undefined}.
+
+to_html(ReqData, State) ->
+ {"<html><body>Hello, new world</body></html>", ReqData, State}.
57 src/cloudrover_sup.erl
@@ -0,0 +1,57 @@
+%% @author author <author@example.com>
+%% @copyright YYYY author.
+
+%% @doc Supervisor for the cloudrover application.
+
+-module(cloudrover_sup).
+-author('author <author@example.com>').
+
+-behaviour(supervisor).
+
+%% External exports
+-export([start_link/0, upgrade/0]).
+
+%% supervisor callbacks
+-export([init/1]).
+
+%% @spec start_link() -> ServerRet
+%% @doc API for starting the supervisor.
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% @spec upgrade() -> ok
+%% @doc Add processes if necessary.
+upgrade() ->
+ {ok, {_, Specs}} = init([]),
+
+ Old = sets:from_list(
+ [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
+ New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
+ Kill = sets:subtract(Old, New),
+
+ sets:fold(fun (Id, ok) ->
+ supervisor:terminate_child(?MODULE, Id),
+ supervisor:delete_child(?MODULE, Id),
+ ok
+ end, ok, Kill),
+
+ [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
+ ok.
+
+%% @spec init([]) -> SupervisorTree
+%% @doc supervisor callback.
+init([]) ->
+ Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
+ {ok, Dispatch} = file:consult(filename:join(
+ [filename:dirname(code:which(?MODULE)),
+ "..", "priv", "dispatch.conf"])),
+ WebConfig = [
+ {ip, Ip},
+ {port, 8000},
+ {log_dir, "priv/log"},
+ {dispatch, Dispatch}],
+ Web = {webmachine_mochiweb,
+ {webmachine_mochiweb, start, [WebConfig]},
+ permanent, 5000, worker, [mochiweb_socket_server]},
+ Processes = [Web],
+ {ok, { {one_for_one, 10, 10}, Processes} }.
3  start.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+cd `dirname $0`
+exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s reloader -s cloudrover
Please sign in to comment.
Something went wrong with that request. Please try again.