Skip to content

Instantly share code, notes, and snippets.

@billimek
Last active January 1, 2021 03:52
Show Gist options
  • Save billimek/1f2377df44f85c61de5f8269590fd81d to your computer and use it in GitHub Desktop.
Save billimek/1f2377df44f85c61de5f8269590fd81d to your computer and use it in GitHub Desktop.
ubiquiti USG bootstrapping

ubiquiti USG bootstrapping

When installing a new ubiquiti USG router device, or when installing a new firmware, the following manual steps will be necessary:

Dyanmic DNS

Cloudflare is not supported out-of-the-box, therefore the following blog post and associated gist reveal what is necessary:

curl https://gist.githubusercontent.com/troyfontaine/7e6f93e32621177fc9a94e823adc52b5/raw/fix_ddns.sh | sudo bash

The necessarey configuration is already persisted in the config.gateway.json file on the controller.

WireGuard

https://github.com/WireGuard/wireguard-vyatta-ubnt has the necessary instructions.

The necessarey configuration is already persisted in the config.gateway.json file on the controller.

Prometheus Node Exporter

curl -OL https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-mips64.tar.gz
tar zxvf node_exporter-0.18.1.linux-mips64.tar.gz
mkdir -p /usr/bin/node-exporter/
sudo cp node_exporter-0.18.1.linux-mips64/node_exporter /usr/bin/node-exporter/node_exporter

/etc/init.d/node_exporter:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          Node exporter
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Description:       Node exporter for prometheus written in Go
### END INIT INFO

DAEMON=/usr/bin/node-exporter/node_exporter
NAME=node_exporter
USER=root
PIDFILE=/var/run/prometheus/$NAME.pid
LOGFILE=/var/log/prometheus/$NAME.log

ARGS="--no-collector.bonding --no-collector.hwmon --no-collector.infiniband --no-collector.ipvs --no-collector.mdadm --no-collector.nfs --no-collector.nfsd --no-collector.zfs --no-collector.xfs --no-collector.bcache --no-collector.cpufreq --no-collector.e
dac"
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

do_start_prepare()
{
    mkdir -p `dirname $PIDFILE` || true
    mkdir -p `dirname $LOGFILE` || true
    chown -R $USER: `dirname $LOGFILE`
    chown -R $USER: `dirname $PIDFILE`
}

do_start_cmd()
{                                                                                                                                                                                                                                                    [33/19543]
    do_start_prepare
    echo -n "Starting daemon: "$NAME
        start-stop-daemon --chuid $USER -C --background --start --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- $ARGS >> $LOGFILE 2>&1
        echo "."
}

do_stop_cmd()
{
    echo -n "Stopping daemon: "$NAME
        start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
        rm $PIDFILE
    echo "."
}

uninstall() {
  echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
  local SURE
  read SURE
  if [ "$SURE" = "yes" ]; then
    stop
    rm -f "$PIDFILE"
    echo "Notice: log file was not removed: '$LOGFILE'" >&2
    update-rc.d -f <NAME> remove
    rm -fv "$0"
  fi
}

status() {
        printf "%-50s" "Checking $NAME..."
    if [ -f $PIDFILE ]; then
        PID=$(cat $PIDFILE)
            if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then
                printf "%s\n" "The process appears to be dead but pidfile still exists"
            else
                echo "Running, the PID is $PID"
            fi
    else
        printf "%s\n" "Service not running"
    fi
}


case "$1" in
  start)
    do_start_cmd
    ;;
  stop)
    do_stop_cmd
    ;;
  status)
    status
    ;;
  uninstall)
    uninstall
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo "Usage: $1 {start|stop|status|restart|uninstall}"
    exit 1
esac

exit 0
update-rc.d node_exporter defaults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment