#!/bin/bash NAME="lora-packet-forwarder" ENABLED="yes" START_STOP_DAEMON="/usr/sbin/start-stop-daemon" [ -f /etc/default/$NAME ] && source /etc/default/$NAME run_dir=/var/run/lora pkt_fwd=/opt/lora/lora_pkt_fwd pkt_fwd_pidfile=$run_dir/lora-pkt-fwd-1.pid log_file=/var/log/lora-pkt-fwd.log do_start() { echo "Starting $NAME: " eui=$(mts-io-sysfs show lora/eui) # Remove colons clean_eui="${eui//:/}" echo "Setting gateway_id in global_conf.json to $clean_eui" sed -i "s/\"gateway_ID\": \".*\"/\"gateway_ID\": \"$clean_eui\"/" global_conf.json mkdir -p $run_dir # start packet forwarder $START_STOP_DAEMON --start --background --make-pidfile \ --pidfile $pkt_fwd_pidfile --startas /bin/bash --chdir "/opt/lora/" \ -- -c "exec $pkt_fwd > $log_file 2>&1" renice -n -20 -p $(pgrep $(basename $pkt_fwd)) echo "OK" } do_stop() { echo -n "Stopping $NAME: " $START_STOP_DAEMON --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5 rm -f $pkt_fwd_pidfile echo "OK" } if [ "$ENABLED" != "yes" ]; then echo "$NAME: disabled in /etc/default/$NAME" 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