diff --git a/.gitignore b/.gitignore index 16ff669..0b0e183 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -statsdaemon +/statsdaemon diff --git a/README.md b/README.md index 46643ce..14acbe8 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,13 @@ Usage of ./statsdaemon: -receive-counter="": Metric name for total metrics recevied per interval -version=false: print version string ``` + +Building a Debian package +========================= +In your terminal, execute: + + ./build-deb.sh <386|amd64> + +where ```` is something like `0.5.0-5`. To compile this on mac you +need to install ``dpkg`` using either Homebrew or Ports. You also need support +for cross compiling Go applications. diff --git a/build-deb.sh b/build-deb.sh new file mode 100755 index 0000000..7880271 --- /dev/null +++ b/build-deb.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Inspired by http://ubuntuforums.org/showthread.php?t=910717. +set -o errexit + +if [ "$#" -ne 2 ]; then + echo "$0 <386|amd64>" + echo + echo "where version is something like 'X.Y-Z'." + exit 1 +fi + +VERSION=$1 +BASEDIR=statsdaemon_$VERSION +ARCH=$2 + +GOOS=linux GOARCH=$ARCH go build statsdaemon.go + +if [ -d $BASEDIR ];then + rm -frv $BASEDIR +fi +cp -r deb $BASEDIR +mkdir -pv $BASEDIR/usr/local/bin +cp -v statsdaemon $BASEDIR/usr/local/bin + +sed "s/VERSION/$VERSION/g" deb/DEBIAN/control | sed "s/ARCH/$ARCH/g" > $BASEDIR/DEBIAN/control + +if [ -e ${BASEDIR}.deb ];then + rm -v ${BASEDIR}.deb +fi +dpkg-deb --build $BASEDIR diff --git a/deb/DEBIAN/control b/deb/DEBIAN/control new file mode 100644 index 0000000..4fc600c --- /dev/null +++ b/deb/DEBIAN/control @@ -0,0 +1,8 @@ +Package: statsdaemon +Version: VERSION +Section: base +Priority: optional +Architecture: ARCH +Maintainer: Jens Rantil +Description: A binary statsd server implemented in Go. +Homepage: https://github.com/bitly/statsdaemon diff --git a/deb/DEBIAN/postinst b/deb/DEBIAN/postinst new file mode 100755 index 0000000..bd6a38d --- /dev/null +++ b/deb/DEBIAN/postinst @@ -0,0 +1,16 @@ +#!/bin/bash +set -o errexit + +USER=statsdaemon +USER_HOME=/tmp + +if [ "$1" = configure ]; then + adduser --system \ + --quiet \ + --home "$USER_HOME" \ + --no-create-home \ + --disabled-password \ + --group "$USER" +fi + +service statsdaemon start || true diff --git a/deb/DEBIAN/postrm b/deb/DEBIAN/postrm new file mode 100755 index 0000000..5cca173 --- /dev/null +++ b/deb/DEBIAN/postrm @@ -0,0 +1,4 @@ +#!/bin/bash +set -o errexit + +deluser statsdaemon || true diff --git a/deb/DEBIAN/preinst b/deb/DEBIAN/preinst new file mode 100755 index 0000000..d856b69 --- /dev/null +++ b/deb/DEBIAN/preinst @@ -0,0 +1,6 @@ +#!/bin/bash +set -o errexit + +if [ -e /etc/init/statsdaemon.conf ]; then + service statsdaemon stop || echo "" +fi diff --git a/deb/DEBIAN/prerm b/deb/DEBIAN/prerm new file mode 100755 index 0000000..d856b69 --- /dev/null +++ b/deb/DEBIAN/prerm @@ -0,0 +1,6 @@ +#!/bin/bash +set -o errexit + +if [ -e /etc/init/statsdaemon.conf ]; then + service statsdaemon stop || echo "" +fi diff --git a/deb/etc/default/statsdaemon b/deb/etc/default/statsdaemon new file mode 100644 index 0000000..c73e896 --- /dev/null +++ b/deb/etc/default/statsdaemon @@ -0,0 +1,3 @@ +# Additional settings for statsdaemon + +STATSDAEMON_OPTS= diff --git a/deb/etc/init/statsdaemon.conf b/deb/etc/init/statsdaemon.conf new file mode 100644 index 0000000..9bb3f16 --- /dev/null +++ b/deb/etc/init/statsdaemon.conf @@ -0,0 +1,18 @@ +# statsdaemon - binary statsd server. + +description "statsdaemon server" + +start on runlevel [2345] +stop on runlevel [!2345] +respawn +respawn limit 360 180 +setuid statsdaemon +setgid statsdaemon + +script + STATSDAEMON_OPTS= + if [ -e /etc/default/statsdaemon ];then + . /etc/default/statsdaemon + fi + exec /usr/local/bin/statsdaemon $STATSDAEMON_OPTS +end script