diff --git a/README.md b/README.md new file mode 100644 index 0000000..4975453 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# unifi-linux-utils +A collection of helpful Linux / Unix scripts and utilities for admins of Ubiquiti (UBNT) UniFi products + +## uap-reboot.sh +Remotely reboots a Ubiquiti (UBNT) UniFi access point + +## unifi_ssl_import.sh +Imports SSL certificates (including Let's Encrypt) for the Ubiquiti (UBNT) UniFi Controller on Linux / Unix Systems + +## upgrade_unifi_controller.sh +Automates upgrade of Ubiquiti (UBNT) UniFi Controller software on Linux / Unix Systems + +## UniFi Controller Startup Scripts +###/startup-scripts/UniFi.service +Ubiquiti (UBNT) UniFi controller service file for systemd Linux / Unix systems + +###/startup-scripts/UniFi +Ubiquiti (UBNT) UniFi controller service file for SysV Linux / Unix systems diff --git a/startup-scripts/UniFi b/startup-scripts/UniFi new file mode 100644 index 0000000..82fe2ea --- /dev/null +++ b/startup-scripts/UniFi @@ -0,0 +1,74 @@ +#!/bin/bash +# +# UniFi Start and stop the UBNT UniFi Controller +# chkconfig: 2345 95 20 +# description: UniFi Controller +# pidfile: /var/run/UniFi.pid + +# Script by Steve Jenkins (SteveJenkins.com) +# Last Updated June 15, 2016 + +. /etc/rc.d/init.d/functions + +SERVICE_NAME="UniFi Controller" +PATH_TO_JAVA=/usr/bin/java +PATH_TO_JAR=/opt/UniFi/lib/ace.jar +MEM_LIMIT=1024M +PID_FILE=/var/run/UniFi.pid + +start() { + if [ ! -f $PID_FILE ]; then + echo -n "Starting $SERVICE_NAME: " + $PATH_TO_JAVA -Xmx$MEM_LIMIT -jar $PATH_TO_JAR start &> /dev/null & + echo $! > $PID_FILE + echo_success + echo + else + echo -n "$SERVICE_NAME is already running" + echo_failure + echo + fi +} + +stop() { + if [ -f $PID_FILE ]; then + PID=$(cat $PID_FILE); + echo -n "Stopping $SERVICE_NAME: " + $PATH_TO_JAVA -jar $PATH_TO_JAR stop &> /dev/null & + rm $PID_FILE + echo_success + echo + else + echo -n "$SERVICE_NAME is not running" + echo_failure + echo + fi +} + +case $1 in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + if [ -f $PID_FILE ]; then + PID=$(cat $PID_FILE); + echo "$SERVICE_NAME running as process $PID" + else + echo "$SERVICE_NAME is not running" + fi + ;; +*) + +echo "usage: service UniFi {start|stop|restart|status}" +exit 1 +;; + +esac +exit 0 diff --git a/startup-scripts/UniFi.service b/startup-scripts/UniFi.service new file mode 100644 index 0000000..d0161c2 --- /dev/null +++ b/startup-scripts/UniFi.service @@ -0,0 +1,24 @@ +# UniFi Controller systemd Service File +# by Steve Jenkins +# Last updated July 15, 2016 + +# Instructions: +# 1. Install Java, MongoDB, and UniFi Controller +# 2. Save this file as /etc/systemd/system/UniFi.service +# 3. Create 'ubnt' user on your system +# 4. Run 'systemctl enable UniFi.service' + +[Unit] +Description=Ubiquiti UniFi Controller +After=syslog.target network.target + +[Service] +ExecStart=/usr/bin/java -Xmx1024M -jar /opt/UniFi/lib/ace.jar start +ExecStop=/usr/bin/java -jar /opt/UniFi/lib/ace.jar stop +Type=simple +User=ubnt +WorkingDirectory=/opt/UniFi +SuccessExitStatus=143 + +[Install] +WantedBy=multi-user.target diff --git a/uap-reboot.sh b/uap-reboot.sh new file mode 100644 index 0000000..62b7e46 --- /dev/null +++ b/uap-reboot.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# A simple script for remotely rebooting a Ubiquiti UniFi access point +# Version 1.0 (Dec 15, 2015) +# by Steve Jenkins (http://www.stevejenkins.com/) + +# Requires sshpass (https://sourceforge.net/projects/sshpass/) which +# is probably available via dnf, yum, or apt on your *nix distro. + +# USAGE +# Update the user-configurable settings below, then run ./uap-reboot.sh from +# the command line. To reboot on a schedule, create a cronjob such as: +# 45 3 * * * /usr/local/bin/uap-reboot.sh > /dev/null 2>&1 #Reboot UniFi AP +# The above example will reboot the UniFi access point every morning at 3:45 AM. + +# USER-CONFIGURABLE SETTINGS +username=ubnt +password=ubnt +known_hosts_file=/dev/null +uap_ip=192.168.1.11 + +# SHOULDN'T NEED TO CHANGE ANYTHING PAST HERE +echo "Rebooting UniFi access point at $uap_ip..." + +if sshpass -p $password ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=$known_hosts_file $username@$uap_ip reboot; then + echo "Reboot complete!" 1>&2 + exit 0 +else + echo "Could not reboot UniFi access point. Please check your settings." 1>&2 + exit 1 +fi