Skip to content

Commit 8877bc0

Browse files
committed
Graceful shutdown
1 parent 0cc7352 commit 8877bc0

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,26 @@ The [Installation Instructions](doc/Installation.md) describe how to build,
5656
install and configure the server. You can use a Debian package, download the binary
5757
release and run it manually or build the server from source codes.
5858

59+
After the installation you have to:
60+
* Add LoRaWAN gateways you want to use.
61+
* Configure each device you want to use, either as a personalized device (ABP) or
62+
as an over-the-air activated (OTAA) device.
63+
5964
Run the lorawan-server release by:
6065
```bash
6166
cd lorawan-server
6267
bin/lorawan-server
6368
```
6469

70+
Terminate the lorawan-server by:
71+
```bash
72+
bin/lorawanctl stop
73+
```
74+
6575
You can administrate and manage the server via a set of web-pages or via a REST API
6676
as described in the [Administration Guide](doc/Administration.md) and in the
6777
[Adaptive Data Rate (ADR) Guide](doc/ADR.md).
6878

69-
After the installation you have to:
70-
* Add LoRaWAN gateways you want to use.
71-
* Configure each device you want to use, either as a personalized device (ABP) or
72-
as an over-the-air activated (OTAA) device.
73-
7479
### Integration
7580

7681
You can integrate lorawan-server with external applications using the WebSocket

rebar.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
{generate_start_script, false},
4444
{overlay, [
4545
{template, "scripts/lorawan-server", "bin/lorawan-server"},
46+
{copy, "scripts/lorawanctl", "bin/lorawanctl"},
4647
{copy, "scripts/lorawan-daemon", "bin/lorawan-daemon"},
4748
{template, "scripts/lorawan-server.bat", "bin/lorawan-server.bat"},
4849
{template, "scripts/lorawan-service.bat", "bin/lorawan-service.bat"},

scripts/lorawanctl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
SCRIPT=$(readlink $0 || true)
3+
if [ -z $SCRIPT ]; then
4+
SCRIPT=$0
5+
fi
6+
SCRIPT_DIR="$(cd `dirname "$SCRIPT"` && pwd -P)"
7+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd -P)"
8+
if [ -z $LORAWAN_HOME ]; then
9+
LORAWAN_HOME=$ROOT_DIR
10+
fi
11+
12+
cd $LORAWAN_HOME && erl -noinput +Bd -sname loractl -pa $ROOT_DIR/lib/*/ebin -s lorawan_control $@ -s init stop

src/lorawan_app.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ start(_Type, _Args) ->
5252
lorawan_sup:start_link().
5353

5454
stop(_State) ->
55+
ok = cowboy:stop_listener(http),
5556
ok.
5657

5758
% end of file

src/lorawan_control.erl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%
2+
% Copyright (c) 2016-2017 Petr Gotthard <[email protected]>
3+
% All rights reserved.
4+
% Distributed under the terms of the MIT License. See the LICENSE file.
5+
%
6+
-module(lorawan_control).
7+
8+
-export([stop/0]).
9+
10+
stop() ->
11+
invoke(init, stop, []).
12+
13+
invoke(Module, Fun, Params) ->
14+
Node = list_to_atom(string:join(["lorawan", net_adm:localhost()], "@")),
15+
case rpc:call(Node, Module, Fun, Params) of
16+
ok -> ok;
17+
{badrpc, Reason} ->
18+
io:format("~w wommand failed: ~w~n", [Node, Reason])
19+
end.
20+
21+
% end of file

src/lorawan_iface_forwarder.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ handle_info({udp, _Socket, _Host, _Port, _Msg}, State) ->
102102
handle_info({'EXIT', _FromPid, _Reason}, State) ->
103103
{noreply, State}.
104104

105-
terminate(_Reason, _State) ->
106-
ok.
105+
terminate(Reason, _State) ->
106+
lager:debug("packet_forwarder interface terminated: ~w", [Reason]),
107+
ok.
107108

108109
code_change(_OldVsn, State, _Extra) ->
109110
{ok, State}.

0 commit comments

Comments
 (0)