Merge pull request #29 from davidnewhall/dn2_build_updates

Build Updates
This commit is contained in:
David Newhall II 2019-06-09 21:34:22 -07:00 committed by GitHub
commit d8331a2a06
19 changed files with 210 additions and 295 deletions

View File

@ -1,14 +1,14 @@
/up.conf /up.conf
/unifi-poller /unifi-poller
/*.gz /unifi-poller*.gz
/*.1 /unifi-poller*.1
/*.deb /unifi-poller*.deb
/*.rpm /unifi-poller*.rpm
/*.pkg /unifi-poller*.pkg
/unifi-poller.macos
/unifi-poller.linux
/vendor /vendor
.DS_Store .DS_Store
*~ *~
/package_build /package_build_*
/release /release
/unifi-poller.macos
/unifi-poller.linux

View File

@ -1,58 +1,164 @@
PACKAGE=./cmd/unifi-poller BINARY:=unifi-poller
BINARY=unifi-poller URL=https://github.com/davidnewhall/unifi-poller
VERSION=`git tag -l --merged | tail -n1` MAINT="david at sleepers dot pro"
DESC="This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database."
PACKAGE:=./cmd/$(BINARY)
VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v)
ITERATION:=$(shell git rev-list --count HEAD)
all: man unifi-poller all: man build
# Prepare a release. Called in Travis CI. # Prepare a release. Called in Travis CI.
release: clean test man linux macos rpm deb osxpkg release: clean test $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb $(BINARY)-$(VERSION).pkg
# Prepareing a release!
mkdir -p release mkdir -p release
gzip -9k unifi-poller.linux gzip -9 $(BINARY).linux
gzip -9k unifi-poller.macos gzip -9 $(BINARY).macos
mv unifi-poller.macos.gz unifi-poller.linux.gz release/ mv $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb \
cp *.rpm *.deb *.pkg release/ $(BINARY)-$(VERSION).pkg $(BINARY).macos.gz $(BINARY).linux.gz release/
# Delete all build assets.
clean: clean:
rm -f `echo $(PACKAGE)|cut -d/ -f3`{.macos,.linux,.1,}{,.gz} # Cleaning up.
rm -f `echo $(PACKAGE)|cut -d/ -f3`{_,-}*.{deb,rpm,pkg} rm -f $(BINARY){.macos,.linux,.1,}{,.gz}
rm -rf package_build release rm -f $(BINARY){_,-}*.{deb,rpm,pkg}
rm -rf package_build_* release
build: unifi-poller # Build a man page from a markdown file using ronn.
unifi-poller: man: $(BINARY).1.gz
go build -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE) $(BINARY).1.gz:
# Building man page.
@ronn --version > /dev/null || (echo "Ronn missing. Install ronn: $(URL)/wiki/Ronn" && false)
ronn < "$(PACKAGE)/README.md" | gzip -9 > "$(BINARY).1.gz"
linux: unifi-poller.linux # Binaries
unifi-poller.linux:
GOOS=linux go build -o unifi-poller.linux -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
macos: unifi-poller.macos build: $(BINARY)
unifi-poller.macos: $(BINARY):
GOOS=darwin go build -o unifi-poller.macos -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE) go build -o $(BINARY) -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
linux: $(BINARY).linux
$(BINARY).linux:
# Building linux binary.
GOOS=linux go build -o $(BINARY).linux -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
macos: $(BINARY).macos
$(BINARY).macos:
# Building darwin binary.
GOOS=darwin go build -o $(BINARY).macos -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
# Packages
rpm: clean $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm
$(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm: check_fpm package_build_linux
@echo "Building 'rpm' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
fpm -s dir -t rpm \
--name $(BINARY) \
--rpm-os linux \
--version $(VERSION) \
--iteration $(ITERATION) \
--after-install scripts/after-install.sh \
--before-remove scripts/before-remove.sh \
--license MIT \
--url $(URL) \
--maintainer $(MAINT) \
--description $(DESC) \
--chdir package_build_linux
deb: clean $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb
$(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: check_fpm package_build_linux
@echo "Building 'deb' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
fpm -s dir -t deb \
--name $(BINARY) \
--version $(VERSION) \
--iteration $(ITERATION) \
--after-install scripts/after-install.sh \
--before-remove scripts/before-remove.sh \
--license MIT \
--url $(URL) \
--maintainer $(MAINT) \
--description $(DESC) \
--chdir package_build_linux
osxpkg: clean $(BINARY)-$(VERSION).pkg
$(BINARY)-$(VERSION).pkg: check_fpm package_build_osx
@echo "Building 'osx' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
fpm -s dir -t osxpkg \
--name $(BINARY) \
--version $(VERSION) \
--iteration $(ITERATION) \
--after-install scripts/after-install.sh \
--osxpkg-identifier-prefix com.github.davidnewhall \
--license MIT \
--url $(URL) \
--maintainer $(MAINT) \
--description $(DESC) \
--chdir package_build_osx
# OSX packages use /usr/local because Apple doesn't allow writing many other places.
package_build_osx: man macos
# Building package environment for macOS.
mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY) $@/Library/LaunchAgents
mkdir -p $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY) $@/usr/local/var/log/unifi-poller
# Copying the binary, config file and man page into the env.
cp $(BINARY).macos $@/usr/local/bin/$(BINARY)
cp *.1.gz $@/usr/local/share/man/man1
cp examples/*.conf.example $@/usr/local/etc/$(BINARY)/
cp examples/* $@/usr/local/share/doc/$(BINARY)/
cp init/launchd/com.github.davidnewhall.$(BINARY).plist $@/Library/LaunchAgents/
# Build an environment that can be packaged for linux.
package_build_linux: man linux
# Building package environment for linux.
mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/lib/systemd/system
mkdir -p $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY)
# Copying the binary, config file, unit file, and man page into the env.
cp $(BINARY).linux $@/usr/bin/$(BINARY)
cp *.1.gz $@/usr/share/man/man1
cp examples/*.conf.example $@/etc/$(BINARY)/
cp examples/up.conf.example $@/etc/$(BINARY)/up.conf
cp examples/* $@/usr/share/doc/$(BINARY)/
cp init/systemd/$(BINARY).service $@/lib/systemd/system/
check_fpm:
@fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false)
# Extras
# Run code tests and lint.
test: lint test: lint
# Testing.
go test -race -covermode=atomic $(PACKAGE) go test -race -covermode=atomic $(PACKAGE)
lint: lint:
# Checking lint.
golangci-lint run --enable-all -D gochecknoglobals golangci-lint run --enable-all -D gochecknoglobals
man: unifi-poller.1.gz # Deprecated.
unifi-poller.1.gz: install:
scripts/build_manpages.sh ./ @echo - Local installation with the Makefile is no longer possible.
@echo If you wish to install the application manually, check out the wiki: \
rpm: man linux https://github.com/davidnewhall/unifi-poller/wiki/Installation
scripts/build_linux_packages.sh rpm @echo - Otherwise, build and install a package: make rpm, make deb, make osxpkg
@echo See the Package Install wiki for more info: \
deb: man linux https://github.com/davidnewhall/unifi-poller/wiki/Package-Install
scripts/build_linux_packages.sh deb
osxpkg: man macos
scripts/build_osx_package.sh
install: man
scripts/local_install.sh
# If you installed with `make install` run `make uninstall` before installing a binary package.
# This will remove the package install from macOS, it will not remove a package install from Linux.
uninstall: uninstall:
scripts/local_uninstall.sh @echo " ==> You must run make uninstall as root on Linux. Recommend not running as root on macOS."
[ -x /bin/systemctl ] && /bin/systemctl disable $(BINARY) || true
[ -x /bin/systemctl ] && /bin/systemctl stop $(BINARY) || true
[ -x /bin/launchctl ] && [ -f ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] \
&& /bin/launchctl unload ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true
[ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] \
&& /bin/launchctl unload /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true
rm -rf /usr/local/{etc,bin,share/doc}/$(BINARY)
rm -f ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist
rm -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true
rm -f /etc/systemd/system/$(BINARY).service /usr/local/share/man/man1/$(BINARY).1.gz
[ -x /bin/systemctl ] && /bin/systemctl --system daemon-reload || true
@[ -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] && echo " ==> Unload and delete this file manually:" && echo " sudo launchctl unload /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist" && echo " sudo rm -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist" || true
# Don't run this unless you're ready to debug untested vendored dependencies.
deps: deps:
dep ensure -update dep ensure -update

View File

@ -37,12 +37,6 @@ for making this dashboard; it gave me a fantastic start to making my own.
# What now... # What now...
- Better Linux support and testing
I only, personally, run this on a Mac 10.13.something. I know others are using
Linux and it's working, but I need more feedback. Does the unit file work? Are
you able to stop and start the service? Does the Makefile do the right things?
- Are there other devices that need to be included? - Are there other devices that need to be included?
I have: switch, router, access point. Three total, and the type structs are I have: switch, router, access point. Three total, and the type structs are
@ -55,7 +49,10 @@ Issue and lets discuss.
- Better Installation instructions. - Better Installation instructions.
If you're a nerd you can probably figure it out. I'd still like some pretty If you're a nerd you can probably figure it out. I'd still like some pretty
pictures and maybe even a Twitch VOD. pictures and maybe even a Twitch VOD. Update: The installation has been
simplified tremendously with the
[creation of binary packages](https://github.com/davidnewhall/unifi-poller/wiki/Package-Install).
More to come!
- Radios, Frequencies, Interfaces, vAPs - Radios, Frequencies, Interfaces, vAPs
@ -63,11 +60,6 @@ My access points only seem to have two radios, one interface and vAP per radio.
I'm not sure if the graphs, as-is, provide enough insight into APs with other I'm not sure if the graphs, as-is, provide enough insight into APs with other
configurations. Help me figure that out? configurations. Help me figure that out?
- It possibly loses access to the controller at some point.
I noticed metrics stop updating after a while. I think the new code will help
isolate why this happens. We may need to issue a reconnect and get a new cookie.
# What's it look like? # What's it look like?
Here's a picture of the Client dashboard. Here's a picture of the Client dashboard.

View File

@ -1,9 +1,9 @@
unifi-poller(1) -- Utility to poll Unifi Metrics and drop them into InfluxDB unifi-poller(1) -- Utility to poll UniFi Controller Metrics and store them in InfluxDB
=== ===
## SYNOPSIS ## SYNOPSIS
`unifi-poller -c /usr/local/etc/unifi-poller.conf` `unifi-poller -c /etc/unifi-poller.conf`
## DESCRIPTION ## DESCRIPTION
@ -26,14 +26,16 @@ unifi-poller(1) -- Utility to poll Unifi Metrics and drop them into InfluxDB
## CONFIGURATION ## CONFIGURATION
* Config File Default Location: /usr/local/etc/unifi-poller/up.conf * Config File Default Location: /etc/unifi-poller/up.conf
`Config File Parameters` `Config File Parameters`
`sites` default: ["default"] `sites` default: ["default"]
This list of strings should represent the names of sites on the unifi This list of strings should represent the names of sites on the unifi
controller that will be polled for data. Pass `all` in the list to controller that will be polled for data. Pass `all` in the list to
poll all sites. poll all sites. On startup, the application prints out all site names
found in the controller; they're cryptic, but they have the human-name
next to them. The cryptic names go into the config file `sites` list.
`interval` default: 30s `interval` default: 30s
How often to poll the controller for updated client and device data. How often to poll the controller for updated client and device data.
@ -94,10 +96,10 @@ Example Use: `1m`, `5h`, `100ms`, `17s`, `1s45ms`, `1m3s`
* Garrett Bjerkhoel (original code) ~ 2016 * Garrett Bjerkhoel (original code) ~ 2016
* David Newhall II (rewritten) ~ 4/20/2018 * David Newhall II (rewritten) ~ 4/20/2018
* David Newhall II (still going) ~ 6/7/2019
## LOCATION ## LOCATION
* https://github.com/davidnewhall/unifi-poller * https://github.com/davidnewhall/unifi-poller
* /usr/local/bin/unifi-poller * UniFi Library: https://github.com/golift/unifi
* config-file: /usr/local/etc/unifi-poller/up.conf
* previously: https://github.com/dewski/unifi * previously: https://github.com/dewski/unifi

View File

@ -7,7 +7,7 @@ var Version = "development"
const ( const (
// App defaults in case they're missing from the config. // App defaults in case they're missing from the config.
defaultConfFile = "/usr/local/etc/unifi-poller/up.conf" defaultConfFile = "/etc/unifi-poller/up.conf"
defaultInterval = 30 * time.Second defaultInterval = 30 * time.Second
defaultInfxDb = "unifi" defaultInfxDb = "unifi"
defaultInfxUser = "unifi" defaultInfxUser = "unifi"

View File

@ -139,7 +139,7 @@ func GetConfig(configFile string) (Config, error) {
// PollUnifiController runs forever, polling and pushing. // PollUnifiController runs forever, polling and pushing.
func (c *Config) PollUnifiController(controller *unifi.Unifi, infdb influx.Client) { func (c *Config) PollUnifiController(controller *unifi.Unifi, infdb influx.Client) {
log.Println("[INFO] Everyting checks out! Beginning Poller Routine.") log.Println("[INFO] Everything checks out! Beginning Poller Routine.")
ticker := time.NewTicker(c.Interval.value) ticker := time.NewTicker(c.Interval.value)
for range ticker.C { for range ticker.C {

View File

@ -1,6 +1,6 @@
# Grafana Dashboards & Examples # Grafana Dashboards & Examples
This folder contains 3 grafana dashboards to get you started with the new data pool. This folder contains 4 grafana dashboards to get you started with the new data pool.
Import these into Grafana to quickly visualize data from your devices. Import these into Grafana to quickly visualize data from your devices.
Created with Grafana 6.2. Created with Grafana 6.2.

View File

@ -53,7 +53,7 @@
"gnetId": null, "gnetId": null,
"graphTooltip": 1, "graphTooltip": 1,
"id": null, "id": null,
"iteration": 1559898667753, "iteration": 1559898956053,
"links": [ "links": [
{ {
"icon": "external link", "icon": "external link",
@ -3410,5 +3410,5 @@
"timezone": "", "timezone": "",
"title": "UniFi USW Insights", "title": "UniFi USW Insights",
"uid": "HIKZ98GZz", "uid": "HIKZ98GZz",
"version": 85 "version": 87
} }

View File

@ -1,7 +1,6 @@
# unifi-poller primary configuration file. # # unifi-poller primary configuration file. #
# copy this file to: /usr/local/etc/unifi-poller/up.conf # # commented lines are defaults, uncomment to change. #
# commented lines are defaults, uncomment to change. # ######################################################
##########################################################
# If the controller has more than one site, specify which sites to poll here. # If the controller has more than one site, specify which sites to poll here.
# If only one site, "default" is likely the correct name. # If only one site, "default" is likely the correct name.

View File

@ -15,8 +15,12 @@
<key>KeepAlive</key> <key>KeepAlive</key>
<true/> <true/>
<key>StandardErrorPath</key> <key>StandardErrorPath</key>
<string>/usr/local/var/log/unifi-poller.log</string> <string>/usr/local/var/log/unifi-poller/log</string>
<key>StandardOutPath</key> <key>StandardOutPath</key>
<string>/usr/local/var/log/unifi-poller.log</string> <string>/usr/local/var/log/unifi-poller/log</string>
<key>UserName</key>
<string>nobody</string>
<key>GroupName</key>
<string>nobody</string>
</dict> </dict>
</plist> </plist>

View File

@ -4,7 +4,7 @@ After=network.target
Requires=network.target Requires=network.target
[Service] [Service]
ExecStart=/usr/local/bin/unifi-poller --config=/usr/local/etc/unifi-poller/up.conf ExecStart=/usr/bin/unifi-poller --config=/etc/unifi-poller/up.conf
Restart=always Restart=always
StandardOutput=syslog StandardOutput=syslog
StandardError=syslog StandardError=syslog

View File

@ -1,19 +0,0 @@
#!/bin/bash
# This file is used by osxpkg packages. FPM use.
# Copy the config file into place if it does not exist.
if [ ! -f /usr/local/etc/unifi-poller/up.conf ] && [ -f /usr/local/etc/unifi-poller/up.conf.example ]; then
cp /usr/local/etc/unifi-poller/up.conf.example /usr/local/etc/unifi-poller/up.conf
fi
# Allow admins to change the configuration and write logs.
chgrp -R admin /usr/local/etc/unifi-poller
chmod -R g+wr /usr/local/etc/unifi-poller
# Make sure admins can write logs.
chgrp admin /usr/local/var/log
chmod g=rwx /usr/local/var/log
# This starts it as root. no no no .... not sure how to fix that.
# launchctl load /Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist

View File

@ -1,7 +1,30 @@
#!/bin/bash #!/bin/bash
# This file is used by rpm and deb packages. FPM use. # This file is used by deb, rpm and osx packages.
# FPM adds this as the after-install script.
systemctl daemon-reload if [ "$(uname -s)" = "Darwin" ]; then
systemctl enable unifi-poller # Copy the config file into place if it does not exist.
systemctl restart unifi-poller if [ ! -f /usr/local/etc/unifi-poller/up.conf ] && [ -f /usr/local/etc/unifi-poller/up.conf.example ]; then
cp /usr/local/etc/unifi-poller/up.conf.example /usr/local/etc/unifi-poller/up.conf
fi
# Allow admins to change the configuration and delete the docs.
chgrp -R admin /usr/local/etc/unifi-poller /usr/local/share/doc/unifi-poller
chmod -R g+wr /usr/local/etc/unifi-poller /usr/local/share/doc/unifi-poller
# Make sure admins can delete logs.
chown -R nobody:admin /usr/local/var/log/unifi-poller
chmod 0775 /usr/local/var/log/unifi-poller
chmod -R g+rw /usr/local/var/log/unifi-poller
# Restart the service - this starts the application as user nobody.
launchctl unload /Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist
launchctl load /Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist
elif [ -x "/bin/systemctl" ]; then
# Reload and restart - this starts the application as user nobody.
/bin/systemctl daemon-reload
/bin/systemctl enable unifi-poller
/bin/systemctl restart unifi-poller
fi

View File

@ -6,5 +6,7 @@ if [ "$1" = "upgrade" ] || [ "$1" = "1" ] ; then
exit 0 exit 0
fi fi
systemctl stop unifi-poller if [ -x "/bin/systemctl" ]; then
systemctl disable unifi-poller /bin/systemctl stop unifi-poller
/bin/systemctl disable unifi-poller
fi

View File

@ -1,52 +0,0 @@
#!/bin/bash
# This script builds a deb or rpm package. Run by the Makefile.
# Use: `make rpm` or `make deb`
OUTPUT=$1
BINARY=unifi-poller
VERSION=$(git tag -l --merged | tail -n1 | tr -d v)
if [ "$OUTPUT" != "deb" ] && [ "$OUTPUT" != "rpm" ]; then
echo "first argument must be 'deb' or 'rpm'"
exit 1
fi
fpm -h > /dev/null 2>&1
if [ "$?" != "0" ]; then
echo "fpm missing. Install fpm: https://fpm.readthedocs.io/en/latest/installing.html"
exit 1
fi
echo "Building '${OUTPUT}' package for ${BINARY} version ${VERSION}."
# eh, don't change these.
PREFIX=
BINFIX=/usr
# Make a build environment.
rm -rf package_build
mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY} package_build${BINFIX}/share/man/man1
# Copy the binary, config file and man page into the env.
cp ${BINARY}.linux package_build${BINFIX}/bin/${BINARY}
cp *.1.gz package_build${BINFIX}/share/man/man1
cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/up.conf
# Fix the paths in the systemd unit file before copying it into the emv.
mkdir -p package_build/lib/systemd/system
sed "s#ExecStart.*#ExecStart=${BINFIX}/bin/${BINARY} --config=${PREFIX}/etc/${BINARY}/up.conf#" \
init/systemd/unifi-poller.service > package_build/lib/systemd/system/${BINARY}.service
# Make a package.
fpm -s dir -t ${OUTPUT} \
--name ${BINARY} \
--version ${VERSION} \
--iteration $(git rev-list --all --count) \
--after-install scripts/after-install.sh \
--before-remove scripts/before-remove.sh \
--license MIT \
--url 'https://github.com/davidnewhall/unifi-poller' \
--maintainer 'david at sleepers dot pro' \
--description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \
--chdir package_build

View File

@ -1,16 +0,0 @@
#!/bin/bash
# This file uses ronn to build a man page for unifi-poller.
set -o pipefail
OUTPUT=$1
# This requires the installation of `ronn`: sudo gem install ronn
for f in cmd/*/README.md;do
# Strtip off cmd/ then strip off README to get the man-file name.
PKGNOCMD="${f#cmd/}"
PKG="${PKGNOCMD%/README.md}"
echo "Creating Man Page: ${f} -> ${OUTPUT}${PKG}.1.gz"
ronn < "$f" | gzip -9 > "${OUTPUT}${PKG}.1.gz" || \
echo "If this produces an error. Install ronn; something like: sudo gem install ronn"
done

View File

@ -1,46 +0,0 @@
#!/bin/bash
# This script builds a simple macos Installer pkg. Run by the Makefile.
# Use: `make osxpkg`
OUTPUT=osxpkg
BINARY=unifi-poller
VERSION=$(git tag -l --merged | tail -n1 | tr -d v)
fpm -h > /dev/null 2>&1
if [ "$?" != "0" ]; then
echo "fpm missing. Install fpm: https://fpm.readthedocs.io/en/latest/installing.html"
exit 1
fi
echo "Building '${OUTPUT}' package for ${BINARY} version ${VERSION}."
PREFIX=/usr/local
BINFIX=/usr/local
# Make a build environment.
rm -rf package_build
mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY} package_build${BINFIX}/share/man/man1
mkdir -p package_build${PREFIX}/var/log
# Copy the binary, config file and man page into the env.
cp ${BINARY}.macos package_build${BINFIX}/bin/${BINARY}
cp *.1.gz package_build${BINFIX}/share/man/man1
cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/
# Copy in launch agent.
mkdir -p package_build/Library/LaunchAgents
cp init/launchd/com.github.davidnewhall.unifi-poller.plist package_build/Library/LaunchAgents/
# Make a package.
fpm -s dir -t ${OUTPUT} \
--name ${BINARY} \
--version ${VERSION} \
--iteration $(git rev-list --all --count) \
--after-install scripts/after-install-osx.sh \
--osxpkg-identifier-prefix com.github.davidnewhall \
--license MIT \
--maintainer 'david at sleepers dot pro' \
--url 'https://github.com/davidnewhall/unifi-poller' \
--description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \
--chdir package_build

View File

@ -1,44 +0,0 @@
#!/bin/bash
# This script creates a local installation of unifi-poller.
# Recommend using Makefile to invoke: make install
# Supports Linux (systemd only) and macOS.
BINARY=unifi-poller
echo "Installing unifi-poller. If you get errors, you may need sudo."
# Install binary.
GOBIN=/usr/local/bin go install -ldflags "-w -s" ./...
# Making config folders and installing man page.
mkdir -p /usr/local/etc/${BINARY} /usr/local/share/man/man1
mv *.1.gz /usr/local/share/man/man1
# Installing config file, man page and launch agent or systemd unit file.
if [ ! -f /usr/local/etc/${BINARY}/up.conf ]; then
cp examples/up.conf.example /usr/local/etc/${BINARY}/up.conf
fi
if [ -d ~/Library/LaunchAgents ]; then
cp init/launchd/com.github.davidnewhall.${BINARY}.plist ~/Library/LaunchAgents
fi
if [ -d /etc/systemd/system ]; then
cp init/systemd/${BINARY}.service /etc/systemd/system
fi
# Making systemd happy by telling it to reload.
if [ -x /bin/systemctl ]; then
/bin/systemctl --system daemon-reload
/bin/systemctl start unifi-poller
/bin/systemctl enable unifi-poller
fi
echo "Installation Complete. Edit the config file @ /usr/local/etc/${BINARY}/up.conf"
echo "Then start the daemon with:"
if [ -d ~/Library/LaunchAgents ]; then
echo " launchctl load ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist"
fi
if [ -x /bin/systemctl ]; then
echo " sudo /bin/systemctl restart ${BINARY}"
fi
echo "Examine the log file at: /usr/local/var/log/${BINARY}.log (logs may go elsewhere on linux, check syslog)"

View File

@ -1,36 +0,0 @@
#!/bin/bash
# This script removes a local installation of unifi-poller.
# Recommend using Makefile to invoke: make uninstall
# Supports Linux (systemd only) and macOS.
BINARY=unifi-poller
echo "Uninstall unifi-poller. You may need sudo on Linux. Do not use sudo on macOS."
# Stopping the daemon
if [ -x /bin/systemctl ]; then
/bin/systemctl disable ${BINARY}
/bin/systemctl stop ${BINARY}
fi
if [ -x /bin/launchctl ] && [ -f ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist ]; then
echo Unloading ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist
/bin/launchctl unload ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist || true
fi
if [ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist ]; then
echo Unloading /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist
/bin/launchctl unload /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist || true
echo "Delete this file manually: sudo rm -f /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist"
fi
# Deleting config file, binary, man page, launch agent or unit file.
rm -rf /usr/local/{etc,bin}/${BINARY} /usr/local/share/man/man1/${BINARY}.1.gz
rm -f ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist
rm -f /etc/systemd/system/${BINARY}.service
# Making systemd happy by telling it to reload.
if [ -x /bin/systemctl ]; then
/bin/systemctl --system daemon-reload
fi