diff --git a/.gitignore b/.gitignore index 33dc61bd..f225ae10 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ /unifi-poller*.1 /unifi-poller*.deb /unifi-poller*.rpm -/unifi-poller*.pkg /unifi-poller.macos /unifi-poller.linux /unifi-poller.rb diff --git a/.travis.yml b/.travis.yml index be362792..4ae0bb79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,19 @@ language: go -# so we can build an osx package. -os: osx addons: - homebrew: + apt: packages: + - ruby-dev - rpm - - gnu-tar + - build-essential + - git + - libgnome-keyring-dev + - fakeroot go: - 1.12.x before_install: - mkdir -p $GOPATH/bin # Download the `dep` binary to bin folder in $GOPATH -- curl -sLo $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.5.3/dep-darwin-amd64 +- curl -sLo $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.5.3/dep-linux-amd64 - chmod +x $GOPATH/bin/dep # download super-linter: golangci-lint - curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin latest diff --git a/Makefile b/Makefile index 5669ea21..99f44221 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ BINARY:=unifi-poller URL:=https://github.com/davidnewhall/$(BINARY) MAINT=David Newhall II DESC=This daemon polls a Unifi controller at a short interval and stores the collected measurements in an Influx Database. -OSX_PKG_PREFIX=com.github.davidnewhall GOLANGCI_LINT_ARGS=--enable-all -D gochecknoglobals PACKAGE:=./cmd/$(BINARY) LIBRARY:=./pkg/$(BINARY) @@ -35,7 +34,7 @@ release: clean test $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$( clean: # Cleaning up. rm -f $(BINARY){.macos,.linux,.1,}{,.gz} $(BINARY).rb - rm -f $(BINARY){_,-}*.{deb,rpm,pkg} md2roff v$(VERSION).tar.gz.sha256 + rm -f $(BINARY){_,-}*.{deb,rpm,pkg} md2roff v*.tar.gz.sha256 rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html rm -rf package_build_* release @@ -108,38 +107,9 @@ $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: check_fpm package_build_linux --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 $(OSX_PKG_PREFIX) \ - --license MIT \ - --url $(URL) \ - --maintainer "$(MAINT)" \ - --description "$(DESC)" \ - --chdir package_build_osx - docker: docker build -t $(DOCKER_REPO)/$(BINARY) . -# OSX packages use /usr/local because Apple doesn't allow writing many other places. -package_build_osx: readme 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)/examples $@/usr/local/var/log/$(BINARY) - # 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 LICENSE *.html examples/{*dash.json,up.conf.example} $@/usr/local/share/doc/$(BINARY)/ - # These go to their own folder so the img src in the html pages continue to work. - cp examples/*.png $@/usr/local/share/doc/$(BINARY)/examples - cp init/launchd/$(OSX_PKG_PREFIX).$(BINARY).plist $@/Library/LaunchAgents/ - # Build an environment that can be packaged for linux. package_build_linux: readme man linux # Building package environment for linux. @@ -203,16 +173,16 @@ uninstall: @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/$(OSX_PKG_PREFIX).$(BINARY).plist ] \ - && /bin/launchctl unload ~/Library/LaunchAgents/$(OSX_PKG_PREFIX).$(BINARY).plist || true - [ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/$(OSX_PKG_PREFIX).$(BINARY).plist ] \ - && /bin/launchctl unload /Library/LaunchAgents/$(OSX_PKG_PREFIX).$(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 + [ -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/$(OSX_PKG_PREFIX).$(BINARY).plist - rm -f /Library/LaunchAgents/$(OSX_PKG_PREFIX).$(BINARY).plist || true + 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/$(OSX_PKG_PREFIX).$(BINARY).plist ] && echo " ==> Unload and delete this file manually:" && echo " sudo launchctl unload /Library/LaunchAgents/$(OSX_PKG_PREFIX).$(BINARY).plist" && echo " sudo rm -f /Library/LaunchAgents/$(OSX_PKG_PREFIX).$(BINARY).plist" || 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: diff --git a/init/launchd/com.github.davidnewhall.unifi-poller.plist b/init/launchd/com.github.davidnewhall.unifi-poller.plist deleted file mode 100644 index cffcd1d9..00000000 --- a/init/launchd/com.github.davidnewhall.unifi-poller.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - Label - com.github.davidnewhall.unifi-poller - ProgramArguments - - /usr/local/bin/unifi-poller - -c - /usr/local/etc/unifi-poller/up.conf - - RunAtLoad - - KeepAlive - - StandardErrorPath - /usr/local/var/log/unifi-poller/log - StandardOutPath - /usr/local/var/log/unifi-poller/log - UserName - nobody - GroupName - nobody - - diff --git a/init/systemd/unifi-poller.service b/init/systemd/unifi-poller.service index ab5220ad..97ed57f3 100644 --- a/init/systemd/unifi-poller.service +++ b/init/systemd/unifi-poller.service @@ -1,11 +1,15 @@ +# Sytemd service unit for unifi-poller. + [Unit] -Description=Unifi Poller - Ubiquiti Metrics->InfluxDB +Description=Unifi Poller - Stores Unifi Metrics in InfluxDB After=network.target Requires=network.target [Service] -ExecStart=/usr/bin/unifi-poller --config=/etc/unifi-poller/up.conf -Restart=always +ExecStart=/usr/bin/unifi-poller $DAEMON_OPTS +EnvironmentFile=-/etc/default/unifi-poller +EnvironmentFile=-/etc/sysconfig/unifi-poller +Restart=on-error StandardOutput=syslog StandardError=syslog SyslogIdentifier=unifi-poller