Skip to content

Instantly share code, notes, and snippets.

@ABalanuta
Last active November 6, 2017 20:03
Show Gist options
  • Select an option

  • Save ABalanuta/cb11dab8af0056a6d9225e8d69a2b993 to your computer and use it in GitHub Desktop.

Select an option

Save ABalanuta/cb11dab8af0056a6d9225e8d69a2b993 to your computer and use it in GitHub Desktop.

Revisions

  1. ABalanuta revised this gist Nov 6, 2017. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions etc default lora-gateway-bridge
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,16 @@
    UDP_BIND=127.0.0.1:1700

    # mqtt server (e.g. scheme://host:port where scheme is tcp, ssl or ws) (default: "tcp://127.0.0.1:1883")
    MQTT_SERVER=ssl://openchirp.io:1883
    MQTT_SERVER=tls://openchirp.andrew.cmu.edu:1883

    # mqtt prefix
    MQTT_PREFIX="<your_openchirp_device_endpoint>"

    # mqtt server username (optional)
    MQTT_USERNAME=< required >
    MQTT_USERNAME=<your_openchirp_device_id>

    # mqtt server password (optional)
    MQTT_PASSWORD=< required >
    MQTT_PASSWORD=<your_openchirp_device_generated_token>

    # debug=5, info=4, warning=3, error=2, fatal=1, panic=0 (default: 4)
    LOG_LEVEL=4
  2. ABalanuta revised this gist Sep 7, 2017. No changes.
  3. ABalanuta revised this gist Sep 7, 2017. 1 changed file with 4 additions and 19 deletions.
    23 changes: 4 additions & 19 deletions etc init.d lora-gateway-bridge
    Original file line number Diff line number Diff line change
    @@ -54,31 +54,16 @@ case "$1" in
    do_start
    ;;
    stop)
    log_daemon_msg "Stopping $DESC"
    echo "Stopping $DESC"
    do_stop
    ;;
    restart)
    log_daemon_msg "Restarting $DESC"
    echo "Restarting $DESC"
    do_stop
    case "$?" in
    0|1)
    do_start
    case "$?" in
    0) log_end_msg 0 ;;
    1) log_end_msg 1 ;;
    *) log_end_msg 1 ;;
    esac
    ;;
    *)
    log_end_msg 1
    ;;
    esac
    ;;
    status)
    status_of_proc -p "$PID_FILE" "$DAEMON" "$NAME" && exit 0 || exit $?
    do_Start
    ;;
    *)
    echo "Usage: $NAME {start|stop|restart|status}" >&2
    echo "Usage: $NAME {start|stop|restart}" >&2
    exit 3
    ;;
    esac
  4. ABalanuta revised this gist Sep 7, 2017. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
  5. ABalanuta revised this gist Sep 7, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lora-gateway-bridge
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ DAEMON_USER=root
    DAEMON_GROUP=root
    DAEMON=/opt/lora/$NAME
    PID_FILE=/var/run/$NAME.pid
    DEFAULT_FILE=/var/config/lora/$NAME.conf
    DEFAULT_FILE=/etc/default/$NAME

    # check root
    if [ "$UID" != "0" ]; then
  6. ABalanuta revised this gist Sep 7, 2017. 1 changed file with 5 additions and 18 deletions.
    23 changes: 5 additions & 18 deletions lora-gateway-bridge
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,8 @@ set -a

    NAME=lora-gateway-bridge
    DESC="LoRa Gateway Bridge"
    DAEMON_USER=gatewaybridge
    DAEMON_GROUP=gatewaybridge
    DAEMON_USER=root
    DAEMON_GROUP=root
    DAEMON=/opt/lora/$NAME
    PID_FILE=/var/run/$NAME.pid
    DEFAULT_FILE=/var/config/lora/$NAME.conf
    @@ -31,9 +31,6 @@ if [ ! -x $DAEMON ]; then
    exit 5
    fi

    # load functions and settings
    . /lib/lsb/init-functions

    if [ -r /etc/default/rcS ]; then
    . /etc/default/rcS
    fi
    @@ -43,32 +40,22 @@ if [ -f "$DEFAULT_FILE" ]; then
    fi

    function do_start {
    /usr/sbin/start-stop-daemon --start --background --chuid "$DAEMON_USER:$DAEMON_GROUP" --make-pidfile --pidfile "$PID_FILE" --startas /bin/bash -- -c "exec $DAEMON > /var/log/$NAME/$NAME.log 2>&1"
    /usr/sbin/start-stop-daemon --start --background --chuid "$DAEMON_USER:$DAEMON_GROUP" --make-pidfile --pidfile "$PID_FILE" --startas /bin/bash -- -c "exec $DAEMON > /var/log/$NAME.log 2>&1"
    }

    function do_stop {
    /usr/sbin/start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile "$PID_FILE" --name "$NAME"
    retval="$?"
    /usr/sbin/start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile "$PID_FILE"
    sleep 1
    return "$retval"
    }

    case "$1" in
    start)
    log_daemon_msg "Starting $DESC"
    echo "Starting $DESC"
    do_start
    case "$?" in
    0|1) log_end_msg 0 ;;
    2) log_end_msg 1 ;;
    esac
    ;;
    stop)
    log_daemon_msg "Stopping $DESC"
    do_stop
    case "$?" in
    0|1) log_end_msg 0 ;;
    2) log_end_msg 1 ;;
    esac
    ;;
    restart)
    log_daemon_msg "Restarting $DESC"
  7. ABalanuta revised this gist Sep 7, 2017. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions lora-gateway-bridge
    Original file line number Diff line number Diff line change
    @@ -15,9 +15,9 @@ NAME=lora-gateway-bridge
    DESC="LoRa Gateway Bridge"
    DAEMON_USER=gatewaybridge
    DAEMON_GROUP=gatewaybridge
    DAEMON=/usr/bin/$NAME
    DAEMON=/opt/lora/$NAME
    PID_FILE=/var/run/$NAME.pid
    DEFAULT_FILE=/etc/default/$NAME
    DEFAULT_FILE=/var/config/lora/$NAME.conf

    # check root
    if [ "$UID" != "0" ]; then
    @@ -43,11 +43,11 @@ if [ -f "$DEFAULT_FILE" ]; then
    fi

    function do_start {
    start-stop-daemon --start --background --chuid "$DAEMON_USER:$DAEMON_GROUP" --make-pidfile --pidfile "$PID_FILE" --startas /bin/bash -- -c "exec $DAEMON > /var/log/$NAME/$NAME.log 2>&1"
    /usr/sbin/start-stop-daemon --start --background --chuid "$DAEMON_USER:$DAEMON_GROUP" --make-pidfile --pidfile "$PID_FILE" --startas /bin/bash -- -c "exec $DAEMON > /var/log/$NAME/$NAME.log 2>&1"
    }

    function do_stop {
    start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile "$PID_FILE" --name "$NAME"
    /usr/sbin/start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile "$PID_FILE" --name "$NAME"
    retval="$?"
    sleep 1
    return "$retval"
  8. ABalanuta revised this gist Sep 7, 2017. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions lora-gateway-bridge.conf
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    # ip:port to bind the UDP listener to (default: "0.0.0.0:1700")
    UDP_BIND=0.0.0.0:1700
    UDP_BIND=127.0.0.1:1700

    # mqtt server (e.g. scheme://host:port where scheme is tcp, ssl or ws) (default: "tcp://127.0.0.1:1883")
    MQTT_SERVER=tcp://127.0.0.1:1883
    MQTT_SERVER=ssl://openchirp.io:1883

    # mqtt server username (optional)
    MQTT_USERNAME=
    MQTT_USERNAME=< required >

    # mqtt server password (optional)
    MQTT_PASSWORD=
    MQTT_PASSWORD=< required >

    # debug=5, info=4, warning=3, error=2, fatal=1, panic=0 (default: 4)
    LOG_LEVEL=4
  9. ABalanuta revised this gist Sep 7, 2017. No changes.
  10. ABalanuta revised this gist Sep 7, 2017. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions lora-gateway-bridge.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # ip:port to bind the UDP listener to (default: "0.0.0.0:1700")
    UDP_BIND=0.0.0.0:1700

    # mqtt server (e.g. scheme://host:port where scheme is tcp, ssl or ws) (default: "tcp://127.0.0.1:1883")
    MQTT_SERVER=tcp://127.0.0.1:1883

    # mqtt server username (optional)
    MQTT_USERNAME=

    # mqtt server password (optional)
    MQTT_PASSWORD=

    # debug=5, info=4, warning=3, error=2, fatal=1, panic=0 (default: 4)
    LOG_LEVEL=4

    # skip the CRC status-check of received packets
    # SKIP_CRC_CHECK=true
  11. ABalanuta revised this gist Sep 7, 2017. No changes.
  12. ABalanuta revised this gist Sep 7, 2017. No changes.
  13. ABalanuta created this gist Sep 7, 2017.
    97 changes: 97 additions & 0 deletions lora-gateway-bridge
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,97 @@
    #!/usr/bin/env bash
    ### BEGIN INIT INFO
    # Provides: lora-gateway-bridge
    # Required-Start: $all
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: LoRa Gateway Bridge abstracts the packet_forwarder protocol into JSON over MQTT
    ### END INIT INFO

    # set variables for exporting (needed for DEFAULT_FILE)
    set -a

    NAME=lora-gateway-bridge
    DESC="LoRa Gateway Bridge"
    DAEMON_USER=gatewaybridge
    DAEMON_GROUP=gatewaybridge
    DAEMON=/usr/bin/$NAME
    PID_FILE=/var/run/$NAME.pid
    DEFAULT_FILE=/etc/default/$NAME

    # check root
    if [ "$UID" != "0" ]; then
    echo "You must be root to run this script"
    exit 1
    fi

    # check daemon
    if [ ! -x $DAEMON ]; then
    echo "Executable $DAEMON does not exist"
    exit 5
    fi

    # load functions and settings
    . /lib/lsb/init-functions

    if [ -r /etc/default/rcS ]; then
    . /etc/default/rcS
    fi

    if [ -f "$DEFAULT_FILE" ]; then
    . "$DEFAULT_FILE"
    fi

    function do_start {
    start-stop-daemon --start --background --chuid "$DAEMON_USER:$DAEMON_GROUP" --make-pidfile --pidfile "$PID_FILE" --startas /bin/bash -- -c "exec $DAEMON > /var/log/$NAME/$NAME.log 2>&1"
    }

    function do_stop {
    start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile "$PID_FILE" --name "$NAME"
    retval="$?"
    sleep 1
    return "$retval"
    }

    case "$1" in
    start)
    log_daemon_msg "Starting $DESC"
    do_start
    case "$?" in
    0|1) log_end_msg 0 ;;
    2) log_end_msg 1 ;;
    esac
    ;;
    stop)
    log_daemon_msg "Stopping $DESC"
    do_stop
    case "$?" in
    0|1) log_end_msg 0 ;;
    2) log_end_msg 1 ;;
    esac
    ;;
    restart)
    log_daemon_msg "Restarting $DESC"
    do_stop
    case "$?" in
    0|1)
    do_start
    case "$?" in
    0) log_end_msg 0 ;;
    1) log_end_msg 1 ;;
    *) log_end_msg 1 ;;
    esac
    ;;
    *)
    log_end_msg 1
    ;;
    esac
    ;;
    status)
    status_of_proc -p "$PID_FILE" "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
    *)
    echo "Usage: $NAME {start|stop|restart|status}" >&2
    exit 3
    ;;
    esac