diff --git a/core/poller/Makefile b/core/poller/Makefile index c71e85e8..36e7dfa0 100644 --- a/core/poller/Makefile +++ b/core/poller/Makefile @@ -12,8 +12,22 @@ build: linux: for p in $(PACKAGES); do GOOS=linux go build -ldflags "-w -s" $${p}; done -install: - go install -ldflags "-w -s" ./... +install: man + @echo "If you get errors, you may need sudo." + GOBIN=/usr/local/bin go install -ldflags "-w -s" ./... + mkdir -p /usr/local/etc/unifi-poller /usr/local/share/man/man1 + test -f /usr/local/etc/unifi-poller/up.conf || cp up.conf.example /usr/local/etc/unifi-poller/up.conf + test -d ~/Library/LaunchAgents && cp startup/launchd/com.github.davidnewhall.unifi-poller.plist ~/Library/LaunchAgents || true + test -d /etc/systemd/system && cp startup/systemd/unifi-poller.service /etc/systemd/system || true + mv *.1.gz /usr/local/share/man/man1 + +uninstall: + @echo "If you get errors, you may need sudo." + test -f ~/Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist && launchctl unload ~/Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist || true + test -f /etc/systemd/system/unifi-poller.service && systemctl stop unifi-poller || true + rm -rf /usr/local/{etc,bin}/unifi-poller /usr/local/share/man/man1/unifi-poller.1.gz + rm -f ~/Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist + rm -f /etc/systemd/system/unifi-poller.service test: lint for p in $(PACKAGES) $(LIBRARYS); do go test -race -covermode=atomic $${p}; done diff --git a/core/poller/cmd/unifi-poller/README.md b/core/poller/cmd/unifi-poller/README.md index 9a2e066f..98d70e30 100644 --- a/core/poller/cmd/unifi-poller/README.md +++ b/core/poller/cmd/unifi-poller/README.md @@ -27,8 +27,8 @@ unifi-poller(1) -- Utility to poll Unifi Metrics and drop them into InfluxDB ## GO DURATION This application uses the Go Time Durations for a polling interval. -The format is an integer followed by a time unit. You may append multiple time units -to add them together. Some valid time units are: +The format is an integer followed by a time unit. You may append +multiple time units to add them together. Some valid time units are: `us` (microsecond) `ns` (nanosecond) diff --git a/core/poller/startup/launchd/com.github.davidnewhall.unifi-poller.plist b/core/poller/startup/launchd/com.github.davidnewhall.unifi-poller.plist new file mode 100644 index 00000000..d8a18294 --- /dev/null +++ b/core/poller/startup/launchd/com.github.davidnewhall.unifi-poller.plist @@ -0,0 +1,22 @@ + + + + + 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 + + diff --git a/core/poller/startup/systemd/unifi-poller.service b/core/poller/startup/systemd/unifi-poller.service new file mode 100644 index 00000000..2b566410 --- /dev/null +++ b/core/poller/startup/systemd/unifi-poller.service @@ -0,0 +1,17 @@ +# untested, feedback welcomed. +[Unit] +Description=Unifi Poller - Ubiquiti Metrics->InfluxDB +After=network.target +Requires=network.target + +[Service] +ExecStart=/usr/local/bin/unifi-poller ---config=/usr/local/etc/unifi-poller/up.conf +Restart=always +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=unifi-poller +Type=simple +User=nobody + +[Install] +WantedBy=multi-user.target