From d79c4b9b6733996dfa5364554f85fc9c019bb11e Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Fri, 6 Sep 2013 23:36:15 -0700 Subject: [PATCH] Improvements to upstart job definition file - Don't start at startup, since network interfaces may not be ready. Instead start when the first non-loopback network interface is up. - Use Upstart's setgid / setuid directives to run as _statsd user. - Omit implicit 'stop on shutdown'. - Add a conventional & friendly comment header. - Respawn StatsD on abnormal termination, but give up after 10 tries. - Do not redirect StatsD's output to /var/log/statsd/statsd.log. Instead simply allow Upstart to capture output and save it to /var/log/upstart/statsd.log. --- debian/dirs | 1 - debian/postinst | 3 --- debian/postrm | 6 +----- debian/scripts/start | 11 ----------- debian/statsd.install | 1 - debian/statsd.upstart | 24 ++++++++++++++++-------- 6 files changed, 17 insertions(+), 29 deletions(-) delete mode 100755 debian/scripts/start diff --git a/debian/dirs b/debian/dirs index 4d2c5fca..e69de29b 100644 --- a/debian/dirs +++ b/debian/dirs @@ -1 +0,0 @@ -var/log/statsd diff --git a/debian/postinst b/debian/postinst index 6016c745..e76a74f6 100755 --- a/debian/postinst +++ b/debian/postinst @@ -18,7 +18,4 @@ if [ "$1" = configure ]; then dpkg-statoverride --update --add _statsd _statsd 0755 /var/run/statsd fi - if ! dpkg-statoverride --list /var/log/statsd >/dev/null 2>&1; then - dpkg-statoverride --update --add _statsd _statsd 0755 /var/log/statsd - fi fi diff --git a/debian/postrm b/debian/postrm index bcf023b4..bc97064c 100644 --- a/debian/postrm +++ b/debian/postrm @@ -6,11 +6,7 @@ if [ "$1" = purge ]; then update-rc.d statsd remove >/dev/null || true - rm -rf /var/log/statsd /var/run/statsd - - if dpkg-statoverride --list /var/log/statsd >/dev/null 2>&1; then - dpkg-statoverride --remove /var/log/statsd - fi + rm -rf /var/run/statsd if dpkg-statoverride --list /var/run/statsd >/dev/null 2>&1; then dpkg-statoverride --remove /var/run/statsd diff --git a/debian/scripts/start b/debian/scripts/start deleted file mode 100755 index 07c9549b..00000000 --- a/debian/scripts/start +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -PATH=$PATH:/usr/local/bin:/usr/bin:/bin -NODE_BIN=$(which nodejs||which node) - -if [ ! -x "$NODE_BIN" ]; then - echo "Can't find executable nodejs or node in PATH=$PATH" - exit 1 -fi - -$NODE_BIN /usr/share/statsd/stats.js /etc/statsd/localConfig.js 2>&1 >> /var/log/statsd/statsd.log diff --git a/debian/statsd.install b/debian/statsd.install index bf7fa999..174d59e2 100644 --- a/debian/statsd.install +++ b/debian/statsd.install @@ -3,4 +3,3 @@ lib/*.js /usr/share/statsd/lib backends/*.js /usr/share/statsd/backends lib/*.js /usr/share/statsd/lib debian/localConfig.js /etc/statsd -debian/scripts/start /usr/share/statsd/scripts diff --git a/debian/statsd.upstart b/debian/statsd.upstart index 67b6231e..e007c25c 100644 --- a/debian/statsd.upstart +++ b/debian/statsd.upstart @@ -1,11 +1,19 @@ -description "statsd" -author "etsy" +# statsd - Network daemon for aggregating statistics +# +# This is a network service that receives metric data via UDP from other +# applications. It aggregates this data and flushes it to a storage backend +# (typically Graphite) at regular intervals. +# +description "Network daemon for aggregating statistics" +author "Etsy" -start on startup -stop on shutdown +start on (local-filesystems and net-device-up IFACE!=lo) -script - chdir /usr/share/statsd +setuid _statsd +setgid _statsd - exec sudo -u _statsd /usr/share/statsd/debian/scripts/start -end script +respawn +respawn limit 10 5 + +chdir /usr/share/statsd +exec /usr/bin/nodejs stats.js /etc/statsd/localConfig.js