Add launch files and make install.

This commit is contained in:
DN2 2018-04-22 17:11:10 -07:00
parent 5a0f149d26
commit f8cd768b5c
4 changed files with 57 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.github.davidnewhall.unifi-poller</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/unifi-poller</string>
<string>-c</string>
<string>/usr/local/etc/unifi-poller/up.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/unifi-poller.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/unifi-poller.log</string>
</dict>
</plist>

View File

@ -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