summaryrefslogtreecommitdiff
path: root/recipes-connectivity/lora/lora-network-server
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-connectivity/lora/lora-network-server')
-rw-r--r--recipes-connectivity/lora/lora-network-server/lora-network-server.default2
-rwxr-xr-xrecipes-connectivity/lora/lora-network-server/lora-network-server.init101
-rw-r--r--recipes-connectivity/lora/lora-network-server/lora-network-server.logrotate.conf7
3 files changed, 110 insertions, 0 deletions
diff --git a/recipes-connectivity/lora/lora-network-server/lora-network-server.default b/recipes-connectivity/lora/lora-network-server/lora-network-server.default
new file mode 100644
index 0000000..be7dcd5
--- /dev/null
+++ b/recipes-connectivity/lora/lora-network-server/lora-network-server.default
@@ -0,0 +1,2 @@
+# set to "yes" or "no" to control starting on boot
+ENABLED="yes"
diff --git a/recipes-connectivity/lora/lora-network-server/lora-network-server.init b/recipes-connectivity/lora/lora-network-server/lora-network-server.init
new file mode 100755
index 0000000..099da38
--- /dev/null
+++ b/recipes-connectivity/lora/lora-network-server/lora-network-server.init
@@ -0,0 +1,101 @@
+#!/bin/bash
+
+NAME="lora-network-server"
+ENABLED="yes"
+
+[ -f /etc/default/$NAME ] && source /etc/default/$NAME
+
+run_dir=/var/run/lora
+conf_dir=/var/config/lora
+conf_file=$conf_dir/lora-network-server.conf
+conf_db=$conf_dir/lora-network-server.db
+
+net_server=/opt/lora/lora-network-server
+net_server_log=/var/log/lora-network-server.log
+net_server_pidfile=$run_dir/$NAME.pid
+
+pkt_fwd=/opt/lora/basic_pkt_fwd
+pkt_fwd_log=/var/log/lora-pkt-fwd.log
+pkt_fwd_pidfile=$run_dir/lora-pkt-fwd.pid
+
+lora_us_id="MTAC-LORA-915"
+lora_eu_id="MTAC-LORA-868"
+
+read_card_info() {
+ # product-id of first lora card
+ lora_id=$(mts-io-sysfs show lora/product-id 2> /dev/null)
+ lora_eui=$(mts-io-sysfs show lora/eui 2> /dev/null)
+ # remove all colons
+ lora_eui_raw=${lora_eui//:/}
+}
+
+card_found() {
+ if [ "$lora_id" = "$lora_us_id" ] || [ "$lora_id" = "$lora_eu_id" ]; then
+ echo "Found lora card $lora_id"
+ return 0
+ else
+ return 1
+ fi
+}
+
+do_start() {
+ read_card_info
+
+ if ! [ -f $conf_file ]; then
+ echo "$0: $conf_file missing"
+ exit 1
+ fi
+
+ if ! card_found; then
+ echo "$0: MTAC-LORA not detected"
+ exit 1
+ fi
+
+ echo -n "Starting $NAME: "
+ mkdir -p $run_dir
+ # start network server
+ start-stop-daemon --start --background --make-pidfile \
+ --pidfile $net_server_pidfile --exec $net_server -- \
+ -c $conf_file --lora-eui $lora_eui --lora-path $run_dir --db $conf_db \
+ --noconsole -l $net_server_log
+ sleep 1
+ # start packet forwarder
+ start-stop-daemon --start --background --make-pidfile \
+ --pidfile $pkt_fwd_pidfile --exec $pkt_fwd -- \
+ -c $run_dir -l $pkt_fwd_log
+ echo "OK"
+}
+
+do_stop() {
+ echo -n "Stopping $NAME: "
+ start-stop-daemon --stop --quiet --oknodo --pidfile $net_server_pidfile --retry 15
+ start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5
+ rm -f $net_server_pidfile $pkt_fwd_pidfile
+ echo "OK"
+}
+
+if [ "$ENABLED" != "yes" ]; then
+ echo "$NAME: disabled in /etc/default"
+ exit
+fi
+
+case "$1" in
+ "start")
+ do_start
+ ;;
+ "stop")
+ do_stop
+ ;;
+ "restart")
+ ## Stop the service and regardless of whether it was
+ ## running or not, start it again.
+ do_stop
+ do_start
+ ;;
+ *)
+ ## If no parameters are given, print which are avaiable.
+ echo "Usage: $0 {start|stop|restart}"
+ exit 1
+ ;;
+esac
+
diff --git a/recipes-connectivity/lora/lora-network-server/lora-network-server.logrotate.conf b/recipes-connectivity/lora/lora-network-server/lora-network-server.logrotate.conf
new file mode 100644
index 0000000..67616a0
--- /dev/null
+++ b/recipes-connectivity/lora/lora-network-server/lora-network-server.logrotate.conf
@@ -0,0 +1,7 @@
+/var/log/lora-pkt-fwd.log /var/log/lora-network-server.log {
+ size 512k
+ rotate 4
+ compress
+ copytruncate
+ missingok
+}