run goatcounter on OpenBSD
Written by: Uwe Werler on
Changed:
Tags:
#OpenBSD
#goatcounter
To have some statistics about my blog I decided to install goatcounter , an Open Source web analytics tool with no tracking. I always try to self host my stuff so let’s start.
- First install go to be able to compile goatcounter:
doas pkg_add go
- Then clone the git repo and build it like described at the github page:
git clone https://github.com/zgoat/goatcounter.git
cd goatcounter
go build -tags osusergo,netgo,sqlite_omit_load_extension \
-ldflags="-X zgo.at/goatcounter/v2.Version=$(git log -n1 --format='%h_%cI') -extldflags=-static" \
./cmd/goatcounter
- Copy the binary to /usr/local/bin (at the destination server) and make it executable:
cp goatcounter /usr/local/bin
chmod 755 /usr/local/bin/goatcounter
- Create a user under which goatcounter should run. User names for daemons under OpenBSD usually start with an underscore. To check which uid/gid numbers are not yet assigned for ports check out ports/infrastructure/db/user.list in ports tree. I decided to use the range 950-999 for a not yet assigned uid number:
useradd -k "" -r 950..999 -c "goatcounter user" -s /sbin/nologin -m -d /var/goatcounter _goatcounter
- Create a start script in rc.d for the daemon:
#!/bin/ksh
daemon="/usr/local/bin/goatcounter serve"
daemon_user="_goatcounter"
. /etc/rc.d/rc.subr
rc_bg=YES
rc_reload=NO
pexp="${daemon}.*"
rc_cmd $1
…and make it executable:
chmod 555 /etc/rc.d/goatcounter
- Set the flags for the daemon and enable and start it, for example:
rcctl set goatcounter flags -db 'sqlite+/var/goatcounter/goatcounter.sqlite3 \
-listen :8081 -public-port 443 \
-smtp smtp://localhost:25 \
-email-from goatcounter@your.domain \
-errors mailto:postmaster@your.domain,goatcounter@your.domain \
-tls proxy'
rcctl start goarcounter
- Then generate the necessary settings for your domain:
su - goatcounter -c 'goatcounter db -db="sqlite+/var/goatcounter/goatcounter.sqlite3" \
create site -vhost blog.werler.is -user.email uwe@werler.is'
- Login to the web interface (in this example runnning on port 8081) and set a password for the user.
The service should be ideally hostet under an own domain name with a reverse proxy in front of it. Creating a port could be fun - might be when I’ve some time I’ll try it.