Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script for creating Debian package #32

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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.
30 changes: 30 additions & 0 deletions build-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
# Inspired by http://ubuntuforums.org/showthread.php?t=910717.
set -o errexit

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

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
8 changes: 8 additions & 0 deletions deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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.

Homepage: https://github.com/bitly/statsdaemon
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 || true
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 -o errexit

deluser statsdaemon || true
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
setgid statsdaemon

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