diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 7526b86f6813d4924fc3b222f90420834a826254..0000000000000000000000000000000000000000 --- a/Dockerfile +++ /dev/null @@ -1,76 +0,0 @@ -FROM erlang:20.2.2 - -RUN apt-get update && apt-get install -y \ - inotify-tools \ - gettext \ - sudo \ - curl \ - mc \ - && rm -rf /var/lib/apt/lists/* - -RUN curl -fsSL https://raw.github.com/synrc/mad/master/mad > mad \ - && chmod +x mad \ - && sudo cp mad /usr/bin/ - -# Add user -RUN useradd -m nynja && echo "nynja:77777" | chpasswd && adduser nynja sudo - - -# Remove host checking -RUN echo "Host \tStrictHostKeyChecking no\n" >> /etc/ssh/config - -USER nynja - -# make sure your domain is accepted -# Create known_hosts -RUN mkdir /home/nynja/.ssh/ -RUN touch /home/nynja/.ssh/known_hosts - -# Copy over private key, and set permissions -RUN chown -R nynja:nynja /home/nynja/.ssh -ADD files/id_rsa /home/nynja/.ssh/ -ADD files/id_rsa.pub /home/nynja/.ssh/ - -#RUN chmod 600 ~/.ssh/id_rsa && \ -# chmod 644 ~/.ssh/id_rsa.pub - -RUN eval $(ssh-agent) && \ - ssh-add ~/.ssh/id_rsa & >/dev/null - -# Add github key -RUN ssh-keyscan github.com >> /home/nynja/.ssh/known_hosts - -WORKDIR /home/nynja - - - -RUN git clone -b cluster ssh://git@github.com/NYNJA-MC/server.git -# - -WORKDIR /home/nynja/server - -RUN rm -f vm.args etc/emq.conf - -RUN mad dep -RUN mad cle comp pla - -CMD ["/home/nynja/server/k8s-start.sh"] - -#VOLUME ["/home/nynja/server/log", "/home/nynja/server/etc"] - -# emqttd will occupy these port: -# - 1883 port for MQTT -# - 8883 port for MQTT(SSL) -# - 8083 for WebSocket/HTTP -# - 8084 for WSS/HTTPS -# - 8080 for mgmt API -# - 18083 for dashboard -# - 4369 for port mapping -# - 6000-6999 for distributed node -EXPOSE 1883 8883 8083 8084 8080 8888 18083 4369 - - - - - - diff --git a/PROJECT.md b/PROJECT.md deleted file mode 100644 index e1402cb23b570071a0f109aa0a55d6663402aeff..0000000000000000000000000000000000000000 --- a/PROJECT.md +++ /dev/null @@ -1,40 +0,0 @@ -Project Log -=========== - -* WIP — [AUTH](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_auth.erl) - — Session dependences (chains) -* WIP — [PRESENSE](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_presense.erl) - — Presences (online/offline) -* WIP — [PRESENSE](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_presense.erl) — Tests for presences -* WIP — [FTP](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_ftp.erl) - [AMAZON](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/amazon_api.erl) - — Upload files -* WIP — [PUBLIC](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_public.erl) — Add rooms -* WIP — [MESSAGE](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_message.erl) — Offline messages -* WIP — [MESSAGE](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_message.erl) — Forward -* WIP — [MESSAGE](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_message.erl) — Edit -* WIP — [MESSAGE](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_message.erl) — Quote -* DONE — [FRIEND](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_friend.erl) - — Roster-roster (P2P) messages exchange -* DONE — [TELESIGN](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/telesign_api.erl) - — Telesign Autoverify (calling) as another mean of registration -* DONE — [MESSAGE](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_message.erl) - — Messages history retrival -* DONE — [AUTH](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_auth.erl) - — Multi-sessions -* DONE — [AUTH](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_auth.erl) - — Sending a verification code in a message if there is another active session -* DONE — [AUTH](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_auth.erl) - — Registration of the new device -* DONE — [PROFILE](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_roster.erl) - — Add contacts sync -* DONE — [ROSTER](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_roster.erl) - — Add contacts via phone contacts and receive a list of users who are (added, requested) -* DONE — [AUTH](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_auth.erl) - — Update the verification codes: they must consist of 6 digits -* DONE — [TELESIGN](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/telesign_api.erl) - — Send 'success' cases to -* DONE — [ROSTER](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_roster.erl) - — Roster (Account): profiles -* DONE — [ROSTER](https://github.com/NYNJA-MC/server/blob/master/apps/roster/src/roster_roster.erl) - — Roster (Account): obtain contacts list/chats list diff --git a/README.md b/README.md index 67ffd9a74ea7959f9f35874b17161d59152abcd3..9cb846b77210a91c0bdb5d858fd29ef21f7bc328 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,25 @@ MQTT API Port: 1883 REST API POrt: 8888 Developers Setup ----------------- +============ +Compile and run +-------------- ``` $ make ===> Verifying dependencies... ... ===> Compiling roster ===> Compiling service +``` +This compiles the code (equivalent to `rebar3 compile` and with +`rebar3 shell` one can start the server locally. Handy for testing +things in the shell. + +Alternatively one can build a developer release to mimic the paths and +config that a release would use with `make local-build` for only +building or +``` $ make console ===> Verifying dependencies... ===> Compiling roster @@ -39,76 +50,40 @@ $ make console ===> Resolving OTP Applications from directories: ... ===> release successfully created! -Exec: /.../erlang/20.3/erts-9.3/bin/erlexec -boot /.../nynja/server/_build/local/rel/server/releases/1.0.0/server -mode embedded -boot_var ERTS_LIB_DIR /.../erlang/20.3/lib -config /.../nynja/server/_build/local/rel/server/releases/1.0.0/sys.config -args_file /.../nynja/server/_build/local/rel/server/releases/1.0.0/vm.args -- console -Root: /.../nynja/server/_build/local/rel/server -/.../nynja/server/_build/local/rel/server -Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:32] [hipe] [kernel-poll:true] -... -Eshell V9.3 (abort with ^G) -(mq@127.0.0.1)1> -> ``` +for building and starting an Erlang shell running the server. +(Note that ^C is disabled to avoid killing the server in +production. Use `q().` to quit the shell. -Open http://127.0.0.1:18083/#/websocket with `admin:public` credentials, Press Connect, Subscribe, Sned and observe statistics http://127.0.0.1:18083/#/overview. +Open http://127.0.0.1:18083/#/websocket with credentials from +`emq_dashboard` in sys.config to observe statistics. Production Setup ----------------- - -$ ps aux | grep beam -$ killall -9 "beam.smp" -$ git clone https://github.com/NYNJA-MC/server && cd server -$ mad up -$ mad dep com pla -$ make start -$ make attach -CTRL+D -$ tail -f log/console.log +-------------- -Create Authorized User ----------------------- +Production runs on a linux machine. We can make distributions locally +by using a docker container. Machinery for doing so is in directory +`build-machine`. +For deploy on production one would use the master branch, but for +deployments on dev or staging environment, one can take an y branch, +for example `development`. ``` -> emq_auth_username:cli(["add","maxim","public"]). -``` - -Then enable `emq_auth_username` plugin in the dashboard http://127.0.0.1:18083/#/plugins -Later you can connect specifying `User Name:` and `Password:` credentials -at http://127.0.0.1:18083/#/websocket - -Creating Single File Bundle ---------------------------- +./build.sh -b development +===> Resolved server-1.1-b9313751 +===> tarball /build-root/server/_build/prod/rel/server/server-1.1-b9313751.tar.gz successfully created! ``` -$ make tar +The release has a MAJOR and MINOR version and then the git hash as a +reference. +This zipped tar file is then to be copied to the environment you want +to deploy it to and with `tar xvf server-1.1-b9313751.tar.gz` in the +directory where the server is installed, it will overwrite/modify the +existing release. + +On this environment you then stop the old server and start the new using: ``` - -User/Device Registration ------------------------- - -TODO: - -Control Panel -------------- - -``` -> emqttd_ctl:run(["plugins","list"]). -Plugin(emq_auth_username, version=2.1.1, description=Authentication, active=false) -Plugin(emq_dashboard, version=2.1.1, description=EMQ Web Dashboard, active=true) -Plugin(emq_modules, version=2.1.1, description=EMQ Modules, active=true) -Plugin(emq_persistence, version=1.1.2, description=Synrc KVS for MQTT, active=true) -ok - -> emqttd_ctl:run(["clients","list"]). -Client(C_1492632081463, clean_sess=true, username=5HT, - peername=127.0.0.1:58225, connected_at=1492632082) -ok - -> emqttd_ctl:run(["help"]). +bin/server stop +(some waiting time) +bin/server start ``` - - -Credits -------- - -* Maxim Sokhatsky -* Ulf Wiger diff --git a/bin/emqttd_ctl b/bin/emqttd_ctl deleted file mode 100755 index 7ceef10c30518078c5c7fc632ce57d90277c94ff..0000000000000000000000000000000000000000 --- a/bin/emqttd_ctl +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/sh -# -*- tab-width:4;indent-tabs-mode:nil -*- -# ex: ts=4 sw=4 et - -set -e - -SCRIPT=$(readlink $0 || true) -if [ -z $SCRIPT ]; then - SCRIPT=$0 -fi; -SCRIPT_DIR="$(cd /home/nynja/server/bin && pwd -P)" -RUNNER_ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd -P)" -REL_NAME="emqttd" -REL_VSN="2.3.9" -ERTS_VSN="9.2" -REL_DIR="$RUNNER_ROOT_DIR" -ERL_OPTS="" -RUNNER_LOG_DIR=$RUNNER_ROOT_DIR/log -RUNNER_LIB_DIR=$RUNNER_ROOT_DIR/deps -RUNNER_ETC_DIR=$RUNNER_ROOT_DIR/etc -RUNNER_DATA_DIR=$RUNNER_ROOT_DIR - -find_erts_dir() { - __erts_dir="$RUNNER_ROOT_DIR/erts-$ERTS_VSN" - if [ -d "$__erts_dir" ]; then - ERTS_DIR="$__erts_dir"; - ROOTDIR="$RUNNER_ROOT_DIR" - else - __erl="$(which erl)" - code="io:format(\"~s\", [code:root_dir()]), halt()." - __erl_root="$("$__erl" -noshell -eval "$code")" - ERTS_DIR="$__erl_root/erts-$ERTS_VSN" - ROOTDIR="$__erl_root" - fi -} - -relx_get_nodename() { - id="longname$(relx_gen_id)-${NAME}" - "$BINDIR/erl" -boot start_clean -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell ${NAME_TYPE} $id -} - -# Control a node -relx_nodetool() { - command="$1"; shift - - ERL_FLAGS="$ERL_FLAGS $PROTO_DIST_ARG" \ - "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ - -setcookie "$COOKIE" "$command" $@ -} - - -[ "x" = "x$EMQ_NODE_NAME" ] || NAME_ARG="-name $EMQ_NODE_NAME" -# Extract the target node name from node.args -if [ -z "$NAME_ARG" ]; then - NODENAME=`egrep '^[ \t]*node.name[ \t]*=[ \t]*' $RUNNER_ETC_DIR/emq.conf 2> /dev/null | tail -1 | cut -d = -f 2-` - if [ -z "$NODENAME" ]; then - echoerr "vm.args needs to have a -name parameter." - echoerr " -sname is not supported." - exit 1 - else - NAME_ARG="-name ${NODENAME# *}" - fi -fi - -# Extract the name type and name from the NAME_ARG for REMSH -NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')" -NAME="$(echo "$NAME_ARG" | awk '{print $2}')" - -[ "x" = "x$EMQ_NODE_COOKIE" ] || COOKIE_ARG="-setcookie $EMQ_NODE_COOKIE" -# Extract the target cookie -if [ -z "$COOKIE_ARG" ]; then - COOKIE=`egrep '^[ \t]*node.cookie[ \t]*=[ \t]*' $RUNNER_ETC_DIR/emq.conf 2> /dev/null | tail -1 | cut -d = -f 2-` - if [ -z "$COOKIE" ]; then - echoerr "vm.args needs to have a -setcookie parameter." - exit 1 - else - COOKIE_ARG="-setcookie $COOKIE" - fi -fi - -# Extract cookie name from COOKIE_ARG -COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')" - -# Support for IPv6 Dist. See: https://github.com/emqtt/emqttd/issues/1460 -PROTO_DIST=`egrep '^[ \t]*node.proto_dist[ \t]*=[ \t]*' $RUNNER_ETC_DIR/emq.conf 2> /dev/null | tail -1 | cut -d = -f 2-` -if [ -z "$PROTO_DIST" ]; then - PROTO_DIST_ARG="" -else - PROTO_DIST_ARG="-proto_dist $PROTO_DIST" -fi - -find_erts_dir -export ROOTDIR="$RUNNER_ROOT_DIR" -export BINDIR="$ERTS_DIR/bin" -cd "$ROOTDIR" - -relx_nodetool rpc emqttd_ctl run $@ - diff --git a/bin/nodetool b/bin/nodetool deleted file mode 100755 index 4d7c4b020bdf53997138fbda346601305dcc712b..0000000000000000000000000000000000000000 --- a/bin/nodetool +++ /dev/null @@ -1,321 +0,0 @@ -#!/usr/bin/env escript -%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ft=erlang ts=4 sw=4 et -%% ------------------------------------------------------------------- -%% -%% nodetool: Helper Script for interacting with live nodes -%% -%% ------------------------------------------------------------------- --mode(compile). - -main(Args) -> - ok = start_epmd(), - %% Extract the args - {RestArgs, TargetNode} = process_args(Args, [], undefined), - - %% process_args() has side-effects (e.g. when processing "-name"), - %% so take care of app-starting business first. - [application:start(App) || App <- [crypto, public_key, ssl]], - - %% any commands that don't need a running node - case RestArgs of - ["mnesia_dir", DataDir, NodeName] -> - create_mnesia_dir(DataDir, NodeName), halt(0); - ["mergeconf", EmqCfg, PluginsEtc, DestDir] -> - mergeconf(EmqCfg, PluginsEtc, DestDir); - ["chkconfig", File] -> - chkconfig(File); - ["chkconfig", "-config", File|_] -> - chkconfig(File); - _ -> - ok - end, - - %% See if the node is currently running -- if it's not, we'll bail - case {net_kernel:hidden_connect_node(TargetNode), net_adm:ping(TargetNode)} of - {true, pong} -> - ok; - {false, pong} -> - io:format(standard_error, "Failed to connect to node ~p .\n", [TargetNode]), - halt(1); - {_, pang} -> - io:format(standard_error, "Node ~p not responding to pings.\n", [TargetNode]), - halt(1) - end, - - case RestArgs of - ["search_for_broken_feeds" | Opts] -> - io:format("Opts: ~p\n", [Opts]), - Res = rpc:call(TargetNode, roster_db, broken_feeds, Opts, 60000), - io:format("All Broken Feeds: ~p\n~p\n",[length(Res), Res]); - ["fix_broken_feeds" | Opts] -> - io:format("Fixed messages: ~p\n", [rpc:call(TargetNode, roster_db, fix_broken_feeds, - Opts, 60000)]); - ["getpid"] -> - io:format("~p\n", [list_to_integer(rpc:call(TargetNode, os, getpid, []))]); - ["ping"] -> - %% If we got this far, the node already responsed to a ping, so just dump - %% a "pong" - io:format("pong\n"); - ["test"] -> - R =case rpc:call(TargetNode, roster_test, test_muc, [], 60000) of - ok -> ok; - E -> E - end, - io:format("~p\n",[R]); - ["backup"] -> - R =case rpc:call(TargetNode, roster_db, backup, [], 600000) of - ok -> ok; - E -> E - end, - io:format("~p\n",[R]); - ["restore" | Files] -> - R =case rpc:call(TargetNode, roster_db, restore, [Files], 600000) of - {ok,Tbs} -> {ok,Tbs}; - E -> E - end, - io:format("~p\n",[R]); - ["stop"] -> - rpc:call(TargetNode, emqttd_plugins, unload, [], 60000), - io:format("~p\n", [rpc:call(TargetNode, init, stop, [], 60000)]); - ["halt"] -> - rpc:call(TargetNode, roster, save_db, ["Mnesia.ekka@127.0.0.1/db"], 60000), - io:format("~p\n", [rpc:call(TargetNode, init, stop, [], 60000)]); - ["restart"] -> - io:format("~p\n", [rpc:call(TargetNode, init, restart, [], 60000)]); - ["reboot"] -> - io:format("~p\n", [rpc:call(TargetNode, init, reboot, [], 60000)]); - ["rpc", Module, Function | RpcArgs] -> - case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), - [RpcArgs], 60000) of - ok -> - ok; - {error, cmd_not_found} -> - halt(1); - {error, Reason} -> - io:format("RPC to ~s error: ~p\n", [TargetNode, Reason]), - halt(1); - {badrpc, Reason} -> - io:format("RPC to ~s failed: ~p\n", [TargetNode, Reason]), - halt(1); - _ -> - halt(1) - end; - ["rpc_infinity", Module, Function | RpcArgs] -> - case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), [RpcArgs], infinity) of - ok -> - ok; - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1); - _ -> - halt(1) - end; - ["rpcterms", Module, Function | ArgsAsString] -> - case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), - consult(lists:flatten(ArgsAsString)), 60000) of - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1); - Other -> - io:format("~p\n", [Other]) - end; - ["eval" | ListOfArgs] -> - % shells may process args into more than one, and end up stripping - % spaces, so this converts all of that to a single string to parse - String = binary_to_list( - list_to_binary( - join(ListOfArgs," ") - ) - ), - - % then just as a convenience to users, if they forgot a trailing - % '.' add it for them. - Normalized = - case lists:reverse(String) of - [$. | _] -> String; - R -> lists:reverse([$. | R]) - end, - - % then scan and parse the string - {ok, Scanned, _} = erl_scan:string(Normalized), - {ok, Parsed } = erl_parse:parse_exprs(Scanned), - - % and evaluate it on the remote node - case rpc:call(TargetNode, erl_eval, exprs, [Parsed, [] ]) of - {value, Value, _} -> - io:format ("~p\n",[Value]); - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1) - end; - Other -> - io:format("Other: ~p\n", [Other]), - io:format("Usage: nodetool {genconfig, chkconfig|getpid|ping|stop|restart|reboot|rpc|rpc_infinity|rpcterms|eval [Terms]} [RPC]\n") - end, - net_kernel:stop(). - -process_args([], Acc, TargetNode) -> - {lists:reverse(Acc), TargetNode}; -process_args(["-setcookie", Cookie | Rest], Acc, TargetNode) -> - erlang:set_cookie(node(), list_to_atom(Cookie)), - process_args(Rest, Acc, TargetNode); -process_args(["-name", TargetName | Rest], Acc, _) -> - ThisNode = append_node_suffix(TargetName, "_maint_"), - {ok, _} = net_kernel:start([ThisNode, longnames]), - process_args(Rest, Acc, nodename(TargetName)); -process_args(["-sname", TargetName | Rest], Acc, _) -> - ThisNode = append_node_suffix(TargetName, "_maint_"), - {ok, _} = net_kernel:start([ThisNode, shortnames]), - process_args(Rest, Acc, nodename(TargetName)); -process_args([Arg | Rest], Acc, Opts) -> - process_args(Rest, [Arg | Acc], Opts). - -start_epmd() -> - [] = os:cmd("\"" ++ epmd_path() ++ "\" -daemon"), - ok. - -epmd_path() -> - ErtsBinDir = filename:dirname(escript:script_name()), - Name = "epmd", - case os:find_executable(Name, ErtsBinDir) of - false -> - case os:find_executable(Name) of - false -> - io:format("Could not find epmd.~n"), - halt(1); - GlobalEpmd -> - GlobalEpmd - end; - Epmd -> - Epmd - end. - -nodename(Name) -> - case re:split(Name, "@", [{return, list}, unicode]) of - [_Node, _Host] -> - list_to_atom(Name); - [Node] -> - [_, Host] = re:split(atom_to_list(node()), "@", [{return, list}, unicode]), - list_to_atom(lists:concat([Node, "@", Host])) - end. - -append_node_suffix(Name, Suffix) -> - case re:split(Name, "@", [{return, list}, unicode]) of - [Node, Host] -> - list_to_atom(lists:concat([Node, Suffix, os:getpid(), "@", Host])); - [Node] -> - list_to_atom(lists:concat([Node, Suffix, os:getpid()])) - end. - -%% For windows??? -create_mnesia_dir(DataDir, NodeName) -> - MnesiaDir = filename:join(DataDir, NodeName), - file:make_dir(MnesiaDir), - io:format("~s", [MnesiaDir]). - -mergeconf(EmqCfg, PluginsEtc, DestDir) -> - filelib:ensure_dir(DestDir),%% support brew on macosx - AppConf = filename:join(DestDir, appconf()), - case file:open(AppConf, [write]) of - {ok, DestFd} -> - CfgFiles = [EmqCfg | cfgfiles(PluginsEtc)], - lists:foreach(fun(CfgFile) -> - {ok, CfgData} = file:read_file(CfgFile), - file:write(DestFd, CfgData), - file:write(DestFd, <<"\n">>) - end, CfgFiles), - file:close(DestFd), - io:format("~s", [AppConf]), - halt(0); - {error, Error} -> - io:format(standard_error, ["Error opening file: ", file:format_error(Error), "\n"], []), - halt(1) - end. - -appconf() -> - {{Y, M, D}, {H, MM, S}} = calendar:local_time(), - lists:flatten( - io_lib:format( - "app.~4..0w.~2..0w.~2..0w.~2..0w.~2..0w.~2..0w.conf", [Y, M, D, H, MM, S])). - -cfgfiles(Dir) -> - [filename:join(Dir, CfgFile) || CfgFile <- filelib:wildcard("*.conf", Dir)]. - -chkconfig(File) -> - case file:consult(File) of - {ok, Terms} -> - case validate(Terms) of - ok -> - halt(0); - {error, Problems} -> - lists:foreach(fun print_issue/1, Problems), - %% halt(1) if any problems were errors - halt(case [x || {error, _} <- Problems] of - [] -> 0; - _ -> 1 - end) - end; - {error, {Line, Mod, Term}} -> - io:format(standard_error, ["Error on line ", file:format_error({Line, Mod, Term}), "\n"], []), - halt(1); - {error, Error} -> - io:format(standard_error, ["Error reading config file: ", file:format_error(Error), "\n"], []), - halt(1) - end. - -%% -%% Given a string or binary, parse it into a list of terms, ala file:consult/0 -%% -consult(Str) when is_list(Str) -> - consult([], Str, []); -consult(Bin) when is_binary(Bin)-> - consult([], binary_to_list(Bin), []). - -consult(Cont, Str, Acc) -> - case erl_scan:tokens(Cont, Str, 0) of - {done, Result, Remaining} -> - case Result of - {ok, Tokens, _} -> - {ok, Term} = erl_parse:parse_term(Tokens), - consult([], Remaining, [Term | Acc]); - {eof, _Other} -> - lists:reverse(Acc); - {error, Info, _} -> - {error, Info} - end; - {more, Cont1} -> - consult(Cont1, eof, Acc) - end. - -%% -%% Validation functions for checking the emqttd.config -%% -validate([Terms]) -> - Results = [ValidateFun(Terms) || ValidateFun <- get_validation_funs()], - Failures = [Res || Res <- Results, Res /= true], - case Failures of - [] -> - ok; - _ -> - {error, Failures} - end. - -%% Some initial and basic checks for the app.config file -get_validation_funs() -> - [ ]. - -print_issue({warning, Warning}) -> - io:format(standard_error, "Warning in emqttd.config: ~s~n", [Warning]); -print_issue({error, Error}) -> - io:format(standard_error, "Error in emqttd.config: ~s~n", [Error]). - -%% string:join/2 copy; string:join/2 is getting obsoleted -%% and replaced by lists:join/2, but lists:join/2 is too new -%% for version support (only appeared in 19.0) so it cannot be -%% used. Instead we just adopt join/2 locally and hope it works -%% for most unicode use cases anyway. -join([], Sep) when is_list(Sep) -> - []; -join([H|T], Sep) -> - H ++ lists:append([Sep ++ X || X <- T]). diff --git a/emqn2o.yaml b/emqn2o.yaml deleted file mode 100644 index a3c9108a1dbd10bcf4ff80da008dadc57e9fd1e7..0000000000000000000000000000000000000000 --- a/emqn2o.yaml +++ /dev/null @@ -1,127 +0,0 @@ ---- - -apiVersion: rbac.authorization.k8s.io/v1beta1 -kind: ClusterRoleBinding -metadata: - name: emqtt-clusterrolebinding -subjects: -- kind: ServiceAccount - name: default - namespace: emqtt -roleRef: - kind: ClusterRole - name: cluster-admin - apiGroup: "" - ---- - -apiVersion: v1 -kind: Service -metadata: - name: ekka - namespace: emqtt - - labels: - app: ekka -spec: - type: NodePort - ports: - - port: 1883 - nodePort: 30001 - protocol: TCP - name: mqtt - - port: 8883 - nodePort: 30002 - protocol: TCP - name: mqttssl - - port: 8080 - nodePort: 30003 - protocol: TCP - name: mgmt - - port: 18083 - nodePort: 30004 - protocol: TCP - name: dashboard - - port: 4369 - nodePort: 30005 - protocol: TCP - name: mapping - - port: 8083 - nodePort: 30006 - protocol: TCP - name: ws - - port: 8084 - nodePort: 30007 - protocol: TCP - name: wss - selector: - app: ekka - ---- - -apiVersion: apps/v1beta1 -kind: StatefulSet -metadata: - name: ekka - namespace: emqtt -spec: - replicas: 1 - serviceName: ekka - template: - metadata: - labels: - app: ekka - spec: - securityContext: - fsGroup: 0 - runAsUser: 0 - containers: - - name: ekka - image: qomputer/one:v1 - imagePullPolicy: Always - volumeMounts: - - name: data-storage - mountPath: /home/nynja/server/Mnesia.ekka@127.0.0.1 - ports: - - containerPort: 1883 - - containerPort: 8883 - - containerPort: 8080 - - containerPort: 8083 - - containerPort: 8084 - - containerPort: 18083 - - containerPort: 8888 - - containerPort: 4369 - readinessProbe: - tcpSocket: - port: 1883 - initialDelaySeconds: 30 - periodSeconds: 40 - env: - - name: EMQ_NAME - value: "ekka" - - name: EMQ_CLUSTER__DISCOVERY - value: "k8s" - - name: EMQ_CLUSTER__K8S__APISERVER - value: "https://kubernetes.default:443" - - name: EMQ_CLUSTER__K8S__NAMESPACE - value: "emqtt" - - name: EMQ_CLUSTER__K8S__SERVICE_NAME - value: "ekka" - - name: EMQ_CLUSTER__K8S__ADDRESS_TYPE - value: "ip" - - name: EMQ_CLUSTER__K8S__APP_NAME - value: "ekka" - - name: EMQ_CLUSTER__NAME - value: "emqcl" - - name: EMQ_CLUSTER__AUTOHEAL - value: "on" - - name: EMQ_CLUSTER__AUTOCLEAN - value: "5m" - lifecycle: - preStop: - exec: - command: ["/bin/bash", "-c", "/home/nynja/server/halt_save.sh"] - volumes: - - name: data-storage - persistentVolumeClaim: - claimName: data-pv-claim diff --git a/halt_save.sh b/halt_save.sh deleted file mode 100755 index 188aea85bd0c327bf7dc50cae8c40a9faefa906c..0000000000000000000000000000000000000000 --- a/halt_save.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - - -CLUSTER_COOKIE=emq_dist_cookie -NODE0="ekka-0" -#LOCAL_IP=$(hostname -i |grep -E -oh '((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])'|head -n 1) - -#if [ "$(hostname)" = "$NODE0" ]; then -# escript bin/nodetool -name ekka@127.0.0.1 -setcookie "777" "halt" -# sleep 7 -#fi - -#find $DB -type f ! -name "schema.DAT" -exec cp -t $DATA "{}" \+ - -escript bin/nodetool -name mq@127.0.0.1 -setcookie $CLUSTER_COOKIE "stop" diff --git a/k8s-start.sh b/k8s-start.sh deleted file mode 100755 index 8133d1703459c2974e62caca822e27363202c968..0000000000000000000000000000000000000000 --- a/k8s-start.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/sh - -## Shell setting -#if [ ! -z "$DEBUG" ]; then -# set -ex -#fi - -## Local IP address setting - -LOCAL_IP=$(hostname -i |grep -E -oh '((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])'|head -n 1) - -## - -export ERL_CLUSTER_COOKIE=emq_dist_cookie -export ERL_NODE_NAME=mq@127.0.0.1 -envsubst < vm.args.dist > vm.args -envsubst < etc/emq.conf.dist > etc/emq.conf -#envsubst < etc/acl.conf.dist > etc/acl.conf - -sleep 3 - -## Nynja Base settings and plugins setting -# Base settings in ~server/etc/emq.conf -# Plugin settings in ~server/etc/plugins - -_EMQ_HOME="/home/nynja/server" - -if [ -z "$PLATFORM_ETC_DIR" ]; then - export PLATFORM_ETC_DIR="$_EMQ_HOME/etc" -fi - -if [ -z "$PLATFORM_LOG_DIR" ]; then - export PLATFORM_LOG_DIR="$_EMQ_HOME/log" -fi - -#if [ -z "$EMQ_NAME" ]; then -# export EMQ_NAME="$(hostname)" -#fi - -#if [ -z "$EMQ_HOST" ]; then -# export EMQ_HOST="$LOCAL_IP" -#fi - -if [ -z "$EMQ_WAIT_TIME" ]; then - export EMQ_WAIT_TIME=600 -fi - -#if [ -z "$EMQ_NODE_NAME" ]; then -# export EMQ_NODE_NAME="$EMQ_NAME@$EMQ_HOST" -#fi - -make start & -#tail -f /home/nynja/server/log/erlang.log.1 & - -# Sleep 5 seconds to wait for the loaded plugins catch up. -sleep 20 - -echo "['$(date -u +"%Y-%m-%dT%H:%M:%SZ")']: nynja start" - -# Wait and ensure emqttd status is running -WAIT_TIME=0 -while [ -z "$($_EMQ_HOME/bin/emqttd_ctl status |grep 'is running'|awk '{print $1}')" ] -do - sleep 1 - echo "['$(date -u +"%Y-%m-%dT%H:%M:%SZ")']:waiting emqttd" - WAIT_TIME=$((WAIT_TIME+1)) - if [ $WAIT_TIME -gt $EMQ_WAIT_TIME ]; then - echo "['$(date -u +"%Y-%m-%dT%H:%M:%SZ")']:timeout error" - exit 1 - fi -done - -# Sleep 5 seconds to wait for the loaded plugins catch up. -sleep 5 - -echo "['$(date -u +"%Y-%m-%dT%H:%M:%SZ")']:emqttd start" - -# Run cluster script - -#if [ -x "./cluster.sh" ]; then -# ./cluster.sh & -#fi - -# Join an exist cluster - -if [ ! -z "$EMQ_JOIN_CLUSTER" ]; then - echo "['$(date -u +"%Y-%m-%dT%H:%M:%SZ")']:emqttd try join $EMQ_JOIN_CLUSTER" - bin/emqttd_ctl cluster join $EMQ_JOIN_CLUSTER & -fi - -# Change admin password - -#if [ ! -z "$EMQ_ADMIN_PASSWORD" ]; then -# echo "['$(date -u +"%Y-%m-%dT%H:%M:%SZ")']:admin password changed to $EMQ_ADMIN_PASSWORD" -# /home/nynja/server/bin/emqttd_ctl admins passwd admin $EMQ_ADMIN_PASSWORD & -#fi - -# monitor emqttd is running, or the docker must stop to let docker PaaS know -# warning: never use infinite loops such as `` while true; do sleep 1000; done`` here -# you must let user know emqtt crashed and stop this container, -# and docker dispatching system can known and restart this container. -IDLE_TIME=0 -while [ $IDLE_TIME -lt 5 ] -do - IDLE_TIME=$((IDLE_TIME+1)) - if [ ! -z "$($_EMQ_HOME/bin/emqttd_ctl status |grep 'is running'|awk '{print $1}')" ]; then - IDLE_TIME=0 - else - echo "['$(date -u +"%Y-%m-%dT%H:%M:%SZ")']:emqttd not running, waiting for recovery in $((25-IDLE_TIME*5)) seconds" - fi - sleep 5 -done - -# If running to here (the result 5 times not is running, thus in 25s emq is not running), exit docker image -# Then the high level PaaS, e.g. docker swarm mode, will know and alert, rebanlance this service - -# tail $(ls /opt/emqttd/log/*) - -escript bin/nodetool -name mq@127.0.0.1 -setcookie $CLUSTER_COOKIE "test" - -echo "['$(date -u +"%Y-%m-%dT%H:%M:%SZ")']:emqttd exit abnormally" -exit 1 - diff --git a/otp.mk b/otp.mk deleted file mode 100644 index de676414c64caa907cef5c53c6e3b1d69d55e67c..0000000000000000000000000000000000000000 --- a/otp.mk +++ /dev/null @@ -1,43 +0,0 @@ -VM := vm.args -SYS := sys.config -ERL_ARGS := -args_file $(VM) -config $(SYS) -NEW_ERL_ARGS := -args_file new.vm.args -config $(SYS) -RUN_DIR ?= . -LOG_DIR ?= ./log -empty := -ROOTS := deps apps -space := $(empty) $(empty) -comma := $(empty),$(empty) -VSN := $(shell git rev-parse HEAD | head -c 6) -DATE := $(shell date "+%Y%m%d-%H%M%S") -ERL_LIBS := $(subst $(space),:,$(ROOTS)) - -clean: - rm -f .applist - mad $@ -compile: - mad $@ -.applist: - mad plan -$(RUN_DIR) $(LOG_DIR): - mkdir -p $(RUN_DIR) & mkdir -p $(LOG_DIR) -attach: - to_erl $(RUN_DIR)/ -console: .applist - ERL_LIBS=$(ERL_LIBS) erl +pc unicode $(ERL_ARGS) -eval '[application:ensure_started(A) || A <- $(shell cat .applist)]' -start: $(RUN_DIR) $(LOG_DIR) .applist - RUN_ERL_LOG_GENERATIONS=1000 RUN_ERL_LOG_MAXSIZE=20000000 \ - ERL_LIBS=$(ERL_LIBS) run_erl -daemon $(RUN_DIR)/ $(LOG_DIR)/ "exec $(MAKE) console" -stop: - @kill -9 $(shell ps ax -o pid= -o command=|grep $(RELEASE)|grep $(COOKIE)|awk '{print $$1}') - -new: - ERL_LIBS=apps erl -name mq2@10.211.55.7 -setcookie emq_dist_cookie -eval "roster_oam:rename_node('mq@127.0.0.1')" - -console-new: .applist - ERL_LIBS=$(ERL_LIBS) erl +pc unicode $(NEW_ERL_ARGS) -eval '[application:ensure_started(A) || A <- $(shell cat .applist)]' -start-new: $(RUN_DIR) $(LOG_DIR) .applist - RUN_ERL_LOG_GENERATIONS=1000 RUN_ERL_LOG_MAXSIZE=20000000 \ - ERL_LIBS=$(ERL_LIBS) run_erl -daemon $(RUN_DIR)/ $(LOG_DIR)/ "exec $(MAKE) console-new" - -.PHONY: compile clean console start console-new start-new stop diff --git a/package.exs b/package.exs deleted file mode 100644 index ed122dab9247237212bd5f1ca89a345059bf16ed..0000000000000000000000000000000000000000 --- a/package.exs +++ /dev/null @@ -1,27 +0,0 @@ -defmodule N2O.Mixfile do - use Mix.Project - - def project do - [app: :mq, - version: "0.4.0", - description: "Voxoz MQ", - package: package, - deps: deps] - end - - def application do - [mod: {:mq, []}] - end - - defp package do - [files: ["apps", "LICENSE", "README.md", "rebar.config", "sys.config", "vm.args"], - licenses: ["APACHE"], - maintainers: ["Andy Martemyanov", "Namdak Tonpa"], - name: :mq, - links: %{"GitHub" => "https://github.com/voxoz/mq"}] - end - - defp deps do - [{:ex_doc, ">= 0.0.0", only: :dev}] - end -end diff --git a/pv.yaml b/pv.yaml deleted file mode 100644 index 63e5d0f84cb104b5e158a88f0541dc0af213bd55..0000000000000000000000000000000000000000 --- a/pv.yaml +++ /dev/null @@ -1,26 +0,0 @@ -apiVersion: v1 -kind: PersistentVolume -metadata: - name: pv0001 -spec: - accessModes: - - ReadWriteOnce - capacity: - storage: 10Gi - storageClassName: "standart" - hostPath: - path: /home/nynja/server/Mnesia.ekka@127.0.0.1/ - type: DirectoryOrCreate ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: data-pv-claim -spec: - volumeName: pv0001 - storageClassName: "standart" - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 5Gi diff --git a/start.sh b/start.sh deleted file mode 100755 index 685e67ade13731c0cf0d59f933b9330322950dbd..0000000000000000000000000000000000000000 --- a/start.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -make start & - -sleep 30 - -escript bin/nodetool -name mq@127.0.0.1 -setcookie emq_dist_cookie "test" - -exit 1 - diff --git a/synrc.stack b/synrc.stack deleted file mode 100644 index 099e1214e665cf768dd346fe7151d10adad8d570..0000000000000000000000000000000000000000 --- a/synrc.stack +++ /dev/null @@ -1,23 +0,0 @@ - - Functors - - COWBOY -> N2O -> WEB - BPE -> ACT - DBS -> TPS - REST - MQS - - Synrc Web Stack - - KVS kvs:add - N2O wf:render - SHEN shen:compile - REST rest:record - MAD mad:compile - ACTIVE active:subscribe - FS fs:subscribe - SH sh:run - OTP.MK make start - AVZ avz:login - FEEDS feeds:publish - MQS mqs:publish diff --git a/vm.args.dist b/vm.args.dist deleted file mode 100644 index cd2012f84c2074f19a56a98aaf6397e9a2f72f55..0000000000000000000000000000000000000000 --- a/vm.args.dist +++ /dev/null @@ -1,19 +0,0 @@ -+W w --kernel net_ticktime 60 --env ERL_CRASH_DUMP log/crash.dump -+e 256000 --env ERL_FULLSWEEP_AFTER 1000 --mnesia dc_dump_limit 10 --mnesia dump_log_write_threshold 700 --mnesia dump_log_time_threshold 400000 -+Q 1048576 -+P 2560000 -+A 32 -+K true --smp auto - --setcookie ${ERL_CLUSTER_COOKIE} --proto_dist inet_tcp --name ${ERL_NODE_NAME} -+zdbbl 32768 -