summaryrefslogtreecommitdiff
path: root/recipes-connectivity/lora
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2023-04-27 16:57:29 -0500
committerHarsh Sharma <harsh.sharma@multitech.com>2023-05-04 17:18:53 -0500
commit4f29bfe85849d1f4cfad2d70fc1655b9f5dedf36 (patch)
treeb8ac3b280d226145986f7e2bc675b864ac7a93aa /recipes-connectivity/lora
parent281235558092b7a4cfb733a71249e9eebea65b8b (diff)
downloadmeta-mlinux-4f29bfe85849d1f4cfad2d70fc1655b9f5dedf36.tar.gz
meta-mlinux-4f29bfe85849d1f4cfad2d70fc1655b9f5dedf36.tar.bz2
meta-mlinux-4f29bfe85849d1f4cfad2d70fc1655b9f5dedf36.zip
Added monit to pkf init script
Diffstat (limited to 'recipes-connectivity/lora')
-rwxr-xr-xrecipes-connectivity/lora/lora-network-server/lora-network-server.init12
-rwxr-xr-xrecipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init154
2 files changed, 83 insertions, 83 deletions
diff --git a/recipes-connectivity/lora/lora-network-server/lora-network-server.init b/recipes-connectivity/lora/lora-network-server/lora-network-server.init
index 92e3b48..8b03428 100755
--- a/recipes-connectivity/lora/lora-network-server/lora-network-server.init
+++ b/recipes-connectivity/lora/lora-network-server/lora-network-server.init
@@ -114,18 +114,6 @@ read_lora_hw_info() {
fi
}
-setup_mtcdt3() {
- dual_cards_installed=true
- ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd
- ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd_2
-
- lora_eui=$(mts-io-sysfs show lora/eui)
- lora_2_eui=$(mts-io-sysfs show lora-2/eui)
-
- lora_2_hw=$lora_hw
- lora_2_id=$lora_id
-}
-
setup_mtcdt_2g4() {
mts-io-sysfs store lora/reset 0
mts-io-sysfs store lora/boot 0
diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init
index 6aaf26f..e5551d7 100755
--- a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init
+++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init
@@ -2,11 +2,14 @@
NAME="lora-packet-forwarder"
+LOCK="/var/lock/$NAME"
ENABLED="yes"
[ -f /etc/default/$NAME ] && source /etc/default/$NAME
+daemon_start="/usr/sbin/start-stop-daemon --start --background"
+daemon_stop="/usr/sbin/start-stop-daemon --stop --quiet --oknodo"
run_dir=/var/run/lora
opt_conf_dir=/opt/lora
conf_dir=/var/config/lora
@@ -26,21 +29,16 @@ pkt_fwd_2_pidfile=$run_dir/lora-pkt-fwd-2.pid
port1=/sys/devices/platform/mts-io/ap1
port2=/sys/devices/platform/mts-io/ap2
-lora_mtac_id="MTAC-LORA"
lora_1_0_hw="MTAC-LORA-1.0"
lora_1_5_h_hw="MTAC-LORA-1.5"
lora_2_1_hw="MTAC-LORA-2.1"
+lora_2g4_hw="MTAC-LORA-2G4-0.0"
lora_mtac_id="MTAC-LORA"
lora_mtac_id915="MTAC-LORA-915"
lora_mtac_id868="MTAC-LORA-868"
lora_mtac_h_id915="MTAC-LORA-H-915"
lora_mtac_h_id868="MTAC-LORA-H-868"
-mtac_spi_device="/dev/spidev0.0"
-mtac_spi_device_2="spidev32765.2"
-
-# spidev32765.2 spidev32766.2
-
lora_mtac_003_id="MTAC-003"
lora_mtac_003_id868="MTAC-003E00"
lora_mtac_003_id915="MTAC-003U00"
@@ -53,13 +51,7 @@ lora_mtcap3_id="MTCAP3"
lora_mtcap3_id868="MTCAP3-003E00"
lora_mtcap3_id915="MTCAP3-003U00"
-mtcdt3_id="MTCDT3"
-lora_mtcdt3_id="MTCDT3-LORA"
-lora_mtcdt3_id868="MTCDT3-LORA-868"
-lora_mtcdt3_id915="MTCDT3-LORA-915"
-mtcdt3_spi_device="/dev/spidev0.0"
-mtcdt3_spi_device_2="/dev/spidev1.0"
-
+lora_mtac_2g4_id="MTAC-LORA-2G4"
lora_mtac_g_id="MTAC-LORA-G"
lora_mtac_g16_id868="MTAC-LORA-G16-868"
@@ -68,23 +60,37 @@ lora_mtac_g64_id868="MTAC-LORA-G64-868"
lora_mtac_g64_id915="MTAC-LORA-G64-915"
pkt_fwd_options=""
-
+dual_cards_installed=false
gps_path="/dev/gps0"
read_lora_hw_info() {
- hw_id=$(mts-io-sysfs show product-id 2> /dev/null)
+ set +e
+
+ hw_id=$(mts-io-sysfs show hw-version)
# product-id of first lora card
lora_id=$(mts-io-sysfs show lora/product-id 2> /dev/null)
+ if [ $? -ne 0 ]; then
+ lora_id="NONE"
+ fi
lora_eui=$(mts-io-sysfs show lora/eui 2> /dev/null)
+ if [ $? -ne 0 ]; then
+ lora_eui=$(mts-io-sysfs show mac-eth)
+ lora_eui=${lora_eui:0:8}":FF:FF"${lora_eui:8:16}
+ fi
# remove all colons
lora_eui_raw=${lora_eui//:}
lora_hw=$(mts-io-sysfs show lora/hw-version 2> /dev/null)
+ if [ $? -ne 0 ]; then
+ lora_hw="NONE"
+ fi
if [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "LORA-1.5" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-1.5" ]]; then
dual_cards_installed=true
elif [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "MTAC-003" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "MTAC-003" ]]; then
dual_cards_installed=true
+ elif [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "LORA-2G4" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-2G4" ]]; then
+ dual_cards_installed=true
fi
if [[ "$dual_cards_installed" = "true" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-1.5" || $(cat $port2/hw-version) =~ "LORA-2G4" || $(cat $port2/hw-version) =~ "MTAC-003" ]]; then
@@ -96,13 +102,28 @@ read_lora_hw_info() {
lora_2_eui_raw=${lora_2_eui//:}
fi
+ set -e
+
+ # Check USB id for Semtech Card
+ if [[ $(lsusb | grep 05c9:5740) =~ "05c9:5740" ]] && [[ ! "$lora_id" =~ "$lora_mtac_2g4_id" ]]; then
+ lora_id=$lora_mtac_2g4_id
+ lora_hw=$lora_2g4_hw
+ lora_eui=$(mts-io-sysfs show mac-eth)
+ lora_eui=${lora_eui:0:8}":FF:FF"${lora_eui:8:16}
+ LORA_CAPABLE=true
+ # Check USB id for Semtech Card in Bootloader mode
+ elif [[ $(lsusb | grep 0483:df11) =~ "0483:df11" ]]; then
+ echo "Semtech 2g4 MTAC card detected in Bootloader Mode, remove power from Conduit and restore"
+ return 1
+ fi
}
+
hardware_found() {
- if [[ "$hw_id" =~ "$mtcdt3_id" ]]; then
- setup_mtcdt3
- elif [[ "$lora_id" =~ "$lora_mtac_g_id" ]]; then
+ if [[ "$lora_id" =~ "$lora_mtac_g_id" ]]; then
setup_mtcdt_2_1
+ elif [[ "$lora_id" =~ "$lora_mtac_2g4_id" ]]; then
+ setup_mtcdt_2g4
elif [[ "$lora_id" =~ "$lora_mtac_003_id" ]]; then
setup_mtcdt003
elif [[ "$lora_id" =~ "$lora_mtac_id" ]]; then
@@ -114,46 +135,6 @@ hardware_found() {
else
return 1
fi
- return 0
-}
-
-setup_mtcdt3() {
- dual_cards_installed=true
- ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd
- ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd_2
-
- lora_eui=$(mts-io-sysfs show lora/eui)
- lora_2_eui=$(mts-io-sysfs show lora-2/eui)
- lora_eui_raw=${lora_eui//:}
- lora_2_eui_raw=${lora_2_eui//:}
-
- lora_id=$(mts-io-sysfs show lora/product-id)
- lora_2_id=$(mts-io-sysfs show lora-2/product-id)
-
- lora_hw=$(mts-io-sysfs show lora/hw-version)
- lora_2_hw=$(mts-io-sysfs show lora-2/hw-version)
-
- GLOBAL_CONF=/opt/lora/global_conf.json.MTAC_LORA_1_5.US915
-
- if [[ "$lora_id" =~ "868" ]]; then
- GLOBAL_CONF=/opt/lora/global_conf.json.MTAC_LORA_1_5.EU868
- fi
-
- ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd
- ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd_2
-
- opt_conf_file=$opt_conf_dir/global_conf.json
- opt_conf_file_local=$opt_conf_dir/local_conf.json
-
- cp $GLOBAL_CONF $opt_conf_file
-
- if ! [ -f $conf_file ]; then
- mkdir -p /var/config/lora/
- cp $opt_conf_file $conf_file
- cp $opt_conf_file_local $conf_file_local
- cp $opt_conf_file $conf_file_2
- cp $opt_conf_file_local $conf_file_local_2
- fi
}
setup_mtcdt003() {
@@ -386,19 +367,24 @@ do_start() {
#
echo -n "Starting $NAME: "
- /usr/sbin/start-stop-daemon --chdir $run_dir/1 --background --start --make-pidfile \
- --pidfile $pkt_fwd_pidfile --startas /bin/bash -- -c "exec $pkt_fwd $pkt_fwd_options -l $pkt_fwd_log"
+ pkf_exec="exec $pkt_fwd $pkt_fwd_options -l $pkt_fwd_log"
+ $daemon_start --chdir $run_dir/1 --make-pidfile --pidfile $pkt_fwd_pidfile --startas /bin/bash -- -c "$pkf_exec"
+
+ echo "check process lora-pkt-fwd-1 with pidfile $pkt_fwd_pidfile
+ program start = \"$daemon_start --chdir $run_dir/1 --make-pidfile --pidfile $pkt_fwd_pidfile --startas /bin/bash -- -c '$pkf_exec'\"
+ program stop = \"$daemon_stop --pidfile $pkt_fwd_pidfile --retry 5\"" > /etc/monit.d/lora-pkt-fwd-1
if [ "$dual_cards_installed" == "true" ]; then
- /usr/sbin/start-stop-daemon --chdir $run_dir/2 --start --background --make-pidfile \
- --pidfile $pkt_fwd_2_pidfile --startas /bin/bash \
- -- -c "exec $pkt_fwd_2 $pkt_fwd_options -l $pkt_fwd_2_log"
+ pkf_2_exec="exec $pkt_fwd_2 $pkt_fwd_options -l $pkt_fwd_2_log"
+ $daemon_start --chdir $run_dir/2 --make-pidfile --pidfile $pkt_fwd_2_pidfile --startas /bin/bash -- -c "$pkf_2_exec"
+ echo "check process lora-pkt-fwd-2 with pidfile $pkt_fwd_2_pidfile
+ program start = \"$daemon_start --chdir $run_dir/2 --make-pidfile --pidfile $pkt_fwd_2_pidfile --startas /bin/bash -- -c '$pkf_2_exec'\"
+ program stop = \"$daemon_stop --pidfile $pkt_fwd_2_pidfile --retry 5\"" > /etc/monit.d/lora-pkt-fwd-2
fi
- if [[ ! "$hw_id" =~ "$mtcdt3_id" ]]; then
- renice -n -20 -p $(pgrep $(basename $pkt_fwd))
- fi
+ renice -n -20 -p $(pgrep $(basename $pkt_fwd))
+ monit reload
echo "OK"
}
@@ -406,12 +392,36 @@ do_start() {
do_stop() {
echo -n "Stopping $NAME: "
- start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5
- start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_2_pidfile --retry 5
- rm -f $pkt_fwd_pidfile
+
+ if monit summary lora-pkt-fwd-1 > /dev/null 2>&1; then
+ monit unmonitor lora-pkt-fwd-1
+ start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5
+ rm -f $pkt_fwd_pidfile
+ fi
+ if monit summary lora-pkt-fwd-2 > /dev/null 2>&1; then
+ monit unmonitor lora-pkt-fwd-2
+ start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_2_pidfile --retry 5
+ rm -f $pkt_fwd_2_pidfile
+ fi
+ rm -rf /etc/monit.d/lora*
+ monit reload
+
echo "OK"
}
+force_stop() {
+ do_stop
+ rm -fr $LOCK
+}
+
+function try_lock() {
+ if mkdir $LOCK; then
+ trap "rm -fr $LOCK" EXIT
+ else
+ echo "Lora Packet Forwarder lock not acquired, resource in use"
+ exit 1
+ fi
+}
if [ "$ENABLED" != "yes" ]; then
echo "$NAME: disabled in /etc/default"
@@ -421,14 +431,16 @@ fi
case "$1" in
"start")
+ try_lock
do_start
;;
"stop")
- do_stop
+ force_stop
;;
"restart")
- ## Stop the service and regardless of whether it was
+ ## Stop the service and regardless of whether it was
## running or not, start it again.
+ try_lock
do_stop
do_start
;;