Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
statsdaemon
/statsdaemon
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version> <386|amd64>

where ``<version>`` 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.
32 changes: 32 additions & 0 deletions build-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# Inspired by http://ubuntuforums.org/showthread.php?t=910717.

if [ "$#" -ne 2 ]; then
echo "$0 <version> <386|amd64>"
echo
echo "where version is something like 'X.Y-Z'."
exit 1
fi

VERSION=$1
BASEDIR=statsdaemon_$VERSION
ARCH=$2

# Fail early
set -e errexit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean set -o errexit. that's equivalent to set -e. Also, if you use the long-name form, the comment is superfluous


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
7 changes: 7 additions & 0 deletions deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Package: statsdaemon
Version: VERSION
Section: base
Priority: optional
Architecture: ARCH
Maintainer: Jens Rantil <[email protected]>
Description: A binary statsd server implemented in Go.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also include Homepage: in this control file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

16 changes: 16 additions & 0 deletions deb/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -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 || echo ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you intend the || echo "" to prevent the set -o errexit from causing this to be a fatal error for the script. First, you need not supply an empty argument to echo, it's equivalent to no arguments. Second, you can just use true, it's a more direct way of providing an alternate success exit code, without any side-effects.

4 changes: 4 additions & 0 deletions deb/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e errexit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another -e that should be an -o


deluser statsdaemon || echo ""
6 changes: 6 additions & 0 deletions deb/DEBIAN/preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -o errexit

if [ -e /etc/init/statsdaemon.conf ]; then
service statsdaemon stop || echo ""
fi
6 changes: 6 additions & 0 deletions deb/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -o errexit

if [ -e /etc/init/statsdaemon.conf ]; then
service statsdaemon stop || echo ""
fi
3 changes: 3 additions & 0 deletions deb/etc/default/statsdaemon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Additional settings for statsdaemon

STATSDAEMON_OPTS=
18 changes: 18 additions & 0 deletions deb/etc/init/statsdaemon.conf
Original file line number Diff line number Diff line change
@@ -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
setuid statsdaemon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same line twice


script
STATSDAEMON_OPTS=
if [ -e /etc/default/statsdaemon ];then
. /etc/default/statsdaemon
fi
exec /usr/local/bin/statsdaemon $STATSDAEMON_OPTS
end script