From 44692de7c7d87486129a186189c3cfaccd3d5000 Mon Sep 17 00:00:00 2001 From: clarsen Date: Thu, 6 Jun 2013 20:54:46 -0400 Subject: [PATCH] Add files necessary to compile a Debian package Add default logging and TSD configs for Debian installs Add "debian" compile option to build a debian package Modify tsdb.in with a config path variable Modify tsdb.in to add the config path and other directories to the classpath when distributed via package Signed-off-by: Chris Larsen --- Makefile.am | 32 ++++++++ build-aux/deb/control/conffiles | 3 + build-aux/deb/control/control | 10 +++ build-aux/deb/control/postinst | 41 +++++++++++ build-aux/deb/control/postrm | 33 +++++++++ build-aux/deb/control/prerm | 10 +++ build-aux/deb/init.d/opentsdb | 127 ++++++++++++++++++++++++++++++++ build-aux/deb/logback.xml | 45 +++++++++++ build-aux/deb/opentsdb.conf | 63 ++++++++++++++++ tsdb.in | 15 ++++ 10 files changed, 379 insertions(+) create mode 100644 build-aux/deb/control/conffiles create mode 100644 build-aux/deb/control/control create mode 100644 build-aux/deb/control/postinst create mode 100644 build-aux/deb/control/postrm create mode 100644 build-aux/deb/control/prerm create mode 100644 build-aux/deb/init.d/opentsdb create mode 100644 build-aux/deb/logback.xml create mode 100644 build-aux/deb/opentsdb.conf diff --git a/Makefile.am b/Makefile.am index 74b24e3f23..fe5cf21459 100644 --- a/Makefile.am +++ b/Makefile.am @@ -234,6 +234,7 @@ edit_tsdb_script := srcdir=''; test -f ./$$script.in || srcdir=$(srcdir)/; \ sed -e "s:@pkgdatadir[@]:$$pkgdatadir:g" \ -e "s:@abs_srcdir[@]:$$abs_srcdir:g" \ -e "s:@abs_builddir[@]:$$abs_builddir:g" \ + -e "s:@configdir[@]:$$configdir:g" \ $${srcdir}$$script.in >$$script.tmp tsdb: $(srcdir)/tsdb.in @@ -513,5 +514,36 @@ $(RPM): opentsdb.spec done if test -d noarch; then rmdir noarch; fi +debian: dist staticroot + $(mkdir_p) $(distdir)/debian + $(mkdir_p) $(distdir)/debian/DEBIAN + $(mkdir_p) $(distdir)/debian/etc/init.d + $(mkdir_p) $(distdir)/debian/etc/opentsdb + $(mkdir_p) $(distdir)/debian/usr/share/opentsdb/bin + $(mkdir_p) $(distdir)/debian/usr/share/opentsdb/lib + $(mkdir_p) $(distdir)/debian/usr/share/opentsdb/plugins + $(mkdir_p) $(distdir)/debian/usr/share/opentsdb/static + $(mkdir_p) $(distdir)/debian/usr/share/opentsdb/tools + cp $(top_srcdir)/build-aux/deb/logback.xml $(distdir)/debian/etc/opentsdb + cp $(top_srcdir)/build-aux/deb/opentsdb.conf $(distdir)/debian/etc/opentsdb + cp $(srcdir)/src/mygnuplot.sh $(distdir)/debian/usr/share/opentsdb/bin + script=tsdb; pkgdatadir='/usr/share/opentsdb'; configdir='/etc/opentsdb'; \ + abs_srcdir=''; abs_builddir=''; $(edit_tsdb_script) + cat tsdb.tmp >"$(distdir)/debian/usr/share/opentsdb/bin/tsdb" + rm -f tsdb.tmp + chmod 755 $(distdir)/debian/usr/share/opentsdb/bin/tsdb + cp $(top_srcdir)/build-aux/deb/control/* $(distdir)/debian/DEBIAN + sed -e "s:@version[@]:$(PACKAGE_VERSION):g" \ + $(distdir)/debian/DEBIAN/control >$(distdir)/debian/DEBIAN/control.tmp + mv $(distdir)/debian/DEBIAN/control.tmp $(distdir)/debian/DEBIAN/control + chmod 755 $(distdir)/debian/DEBIAN/* + cp $(top_srcdir)/build-aux/deb/init.d/opentsdb $(distdir)/debian/etc/init.d + cp $(jar) $(distdir)/debian/usr/share/opentsdb/lib + cp -r staticroot/* $(distdir)/debian/usr/share/opentsdb/static + `for dep_jar in $(tsdb_DEPS); do cp $$dep_jar \ + $(distdir)/debian/usr/share/opentsdb/lib; done;` + cp $(top_srcdir)/tools/* $(distdir)/debian/usr/share/opentsdb/tools + dpkg -b $(distdir)/debian $(distdir)/optsdb-$(PACKAGE_VERSION)_all.deb + .PHONY: jar doc check gwtc gwtdev printdeps staticroot gwttsd rpm include third_party/include.mk diff --git a/build-aux/deb/control/conffiles b/build-aux/deb/control/conffiles new file mode 100644 index 0000000000..f08ae4ec8a --- /dev/null +++ b/build-aux/deb/control/conffiles @@ -0,0 +1,3 @@ +/etc/init.d/opentsdb +/etc/opentsdb/opentsdb.conf +/etc/opentsdb/logback.xml diff --git a/build-aux/deb/control/control b/build-aux/deb/control/control new file mode 100644 index 0000000000..c9a2610dd1 --- /dev/null +++ b/build-aux/deb/control/control @@ -0,0 +1,10 @@ +Package: opentsdb +Version: @version@ +Architecture: all +Maintainer: Chris Larsen +Depends: libc6, adduser +Suggest: gnuplot, java7-runtime-headless | java6-runtime-headless | java7-runtime | java6-runtime +Section: database +Priority: optional +Homepage: http://www.opentsdb.net/ +Description: Time Series Daemon from OpenTSDB for storing and accessing time series data diff --git a/build-aux/deb/control/postinst b/build-aux/deb/control/postinst new file mode 100644 index 0000000000..a0eb28e478 --- /dev/null +++ b/build-aux/deb/control/postinst @@ -0,0 +1,41 @@ +#!/bin/sh +set -e + +case "$1" in + configure) + [ -z "$TSD_USER" ] && TSD_USER="opentsdb" + [ -z "$TSD_GROUP" ] && TSD_GROUP="opentsdb" + if ! getent group "$TSD_GROUP" > /dev/null 2>&1 ; then + addgroup --system "$TSD_GROUP" --quiet + fi + if ! id $TSD_USER > /dev/null 2>&1 ; then + adduser --system --home /usr/share/opentsdb --no-create-home \ + --ingroup "$TSD_GROUP" --disabled-password --shell /bin/false \ + "$TSD_USER" + fi + + # Set user permissions on /tmp/opentsdb and /var/log/opentsdb + mkdir -p /tmp/opentsdb /var/log/opentsdb + chown -R $TSD_USER:$TSD_GROUP /tmp/opentsdb /var/log/opentsdb + chmod 755 /tmp/opentsdb /var/log/opentsdb + + # configuration files should not be modifiable by opentsdb user, as this can be a security issue + chown -Rh root:root /etc/opentsdb/* + chmod 755 /etc/opentsdb + chmod 644 /etc/opentsdb/* + ;; +esac + + +if [ -e "/etc/init.d/opentsdb" ]; then + chmod 755 /etc/init.d/opentsdb + update-rc.d opentsdb defaults 95 10 >/dev/null + +# don't start automatically, the user will almost always need to tweak their config +# if [ -e "`which invoke-rc.d 2>/dev/null`" ]; then +# invoke-rc.d opentsdb start || true +# else +# /etc/init.d/opentsdb start || true +# fi +fi + diff --git a/build-aux/deb/control/postrm b/build-aux/deb/control/postrm new file mode 100644 index 0000000000..8cd9f45e92 --- /dev/null +++ b/build-aux/deb/control/postrm @@ -0,0 +1,33 @@ +#!/bin/sh +set -e + +case "$1" in + remove) + # Remove logs + rm -rf /var/log/opentsdb + + # remove **only** empty data dir + rmdir -p --ignore-fail-on-non-empty /tmp/opentsdb + ;; + + purge) + # Remove service + update-rc.d opentsdb remove >/dev/null || true + + # Remove logs and data + rm -rf /var/log/opentsdb /tmp/opentsdb + + # Remove user/group + deluser opentsdb || true + delgroup opentsdb || true + ;; + + upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + # Nothing to do here + ;; + + *) + echo "$0 called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac diff --git a/build-aux/deb/control/prerm b/build-aux/deb/control/prerm new file mode 100644 index 0000000000..cdf0dba329 --- /dev/null +++ b/build-aux/deb/control/prerm @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +if [ -x "/etc/init.d/opentsdb" ]; then + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d opentsdb stop || true + else + /etc/init.d/opentsdb stop || true + fi +fi \ No newline at end of file diff --git a/build-aux/deb/init.d/opentsdb b/build-aux/deb/init.d/opentsdb new file mode 100644 index 0000000000..2d19061a32 --- /dev/null +++ b/build-aux/deb/init.d/opentsdb @@ -0,0 +1,127 @@ +#!/bin/sh -e +# +# Modified from original source: Elastic Search +# https://github.com/elasticsearch/elasticsearch +# Thank you to the Elastic Search authors +# +### BEGIN INIT INFO +# Provides: opentsdb +# Required-Start: $network $named +# Required-Stop: $network $named +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts OpenTSDB TSD +# Description: Starts an OpenTSDB time series daemon +### END INIT INFO + +PATH=/bin:/usr/bin:/sbin:/usr/sbin +NAME=opentsdb +TSD_USER=opentsdb +TSD_GROUP=opentsdb + +# Maximum number of open files +MAX_OPEN_FILES=65535 + +. /lib/lsb/init-functions + +# The first existing directory is used for JAVA_HOME +# (if JAVA_HOME is not defined in $DEFAULT) +JDK_DIRS="/usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-7-openjdk \ + /usr/lib/jvm/java-7-openjdk-amd64/ /usr/lib/jvm/java-7-openjdk-i386/ \ + /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-6-openjdk \ + /usr/lib/jvm/java-6-openjdk-amd64 /usr/lib/jvm/java-6-openjdk-i386" + +# Look for the right JVM to use +for jdir in $JDK_DIRS; do + if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then + JAVA_HOME="$jdir" + fi +done +export JAVA_HOME + +# Define other required variables +PID_FILE=/var/run/$NAME.pid + +DAEMON=/usr/share/opentsdb/bin/tsdb +DAEMON_OPTS=tsd + +case "$1" in +start) + + if [ -z "$JAVA_HOME" ]; then + log_failure_msg "no JDK found - please set JAVA_HOME" + exit 1 + fi + + log_action_begin_msg "Starting TSD" + if start-stop-daemon --test --start --pidfile "$PID_FILE" \ + --user "$TSD_USER" --exec "$JAVA_HOME/bin/java" \ + >/dev/null; then + + touch "$PID_FILE" && chown "$TSD_USER":"$TSD_GROUP" "$PID_FILE" + + if [ -n "$MAX_OPEN_FILES" ]; then + ulimit -n $MAX_OPEN_FILES + fi + + # start the daemon + start-stop-daemon --start -b --user "$TSD_USER" -c "$TSD_USER" \ + --make-pidfile --pidfile "$PID_FILE" \ + --exec /bin/bash -- -c "$DAEMON $DAEMON_OPTS" + + sleep 1 + if start-stop-daemon --test --start --pidfile "$PID_FILE" \ + --user "$TSD_USER" --exec "$JAVA_HOME/bin/java" \ + >/dev/null; then + + if [ -f "$PID_FILE" ]; then + rm -f "$PID_FILE" + fi + + log_failure_msg "Failed to start the TSD" + else + log_action_end_msg 0 + fi + + else + log_action_cont_msg "TSD is already running" + + log_action_end_msg 0 + fi + ;; + +stop) + log_action_begin_msg "Stopping TSD" + set +e + if [ -f "$PID_FILE" ]; then + start-stop-daemon --stop --pidfile "$PID_FILE" \ + --user "$TSD_USER" --retry=TERM/20/KILL/5 >/dev/null + if [ $? -eq 1 ]; then + log_action_cont_msg "TSD is not running but pid file exists, cleaning up" + elif [ $? -eq 3 ]; then + PID="`cat $PID_FILE`" + log_failure_msg "Failed to stop TSD (pid $PID)" + exit 1 + fi + rm -f "$PID_FILE" + else + log_action_cont_msg "TSD was not running" + fi + log_action_end_msg 0 + set -e + ;; + +restart|force-reload) + if [ -f "$PID_FILE" ]; then + $0 stop + sleep 1 + fi + $0 start + ;; +*) + echo "Usage: /etc/init.d/opentsdb {start|stop|restart}" + exit 1 + ;; +esac + +exit 0 diff --git a/build-aux/deb/logback.xml b/build-aux/deb/logback.xml new file mode 100644 index 0000000000..7f0fb57694 --- /dev/null +++ b/build-aux/deb/logback.xml @@ -0,0 +1,45 @@ + + + + + + + %d{ISO8601} %-5level [%thread] %logger{0}: %msg%n + + + + + + 1024 + + + + /var/log/opentsdb/opentsdb.log + true + + + /var/log/opentsdb/opentsdb.log.%i + 1 + 3 + + + + 128MB + + + + + %d{HH:mm:ss.SSS} %-5level [%logger{0}.%M] - %msg%n + + + + + + + + + + + + diff --git a/build-aux/deb/opentsdb.conf b/build-aux/deb/opentsdb.conf new file mode 100644 index 0000000000..d95b65efe2 --- /dev/null +++ b/build-aux/deb/opentsdb.conf @@ -0,0 +1,63 @@ +# --------- NETWORK ---------- +# The TCP port TSD should use for communications +# *** REQUIRED *** +tsd.network.port = 4242 + +# The IPv4 network address to bind to, defaults to all addresses +# tsd.network.bind = 0.0.0.0 + +# Enables Nagel's algorithm to reduce the number of packets sent over the +# network, default is True +#tsd.network.tcpnodelay = true + +# Determines whether or not to send keepalive packets to peers, default +# is True +#tsd.network.keepalive = true + +# Determines if the same socket should be used for new connections, default +# is True +#tsd.network.reuseaddress = true + +# Number of worker threads dedicated to Netty, defaults to # of CPUs * 2 +#tsd.network.worker_threads = 8 + +# Whether or not to use NIO or tradditional blocking IO, defaults to True +#tsd.network.async_io = true + +# ----------- HTTP ----------- +# The location of static files for the HTTP GUI interface. +# *** REQUIRED *** +tsd.http.staticroot = /usr/share/opentsdb/static/ + +# Where TSD should write it's cache files to +# *** REQUIRED *** +tsd.http.cachedir = /tmp/opentsdb + +# --------- CORE ---------- +# Whether or not to automatically create UIDs for new metric types, default +# is False +#tsd.core.auto_create_metrics = false + +# Full path to a directory containing plugins for OpenTSDB +tsd.core.plugin_path = /usr/share/opentsdb/plugins + +# --------- STORAGE ---------- +# Whether or not to enable data compaction in HBase, default is True +#tsd.storage.enable_compaction = true + +# How often, in milliseconds, to flush the data point queue to storage, +# default is 1,000 +# tsd.storage.flush_interval = 1000 + +# Name of the HBase table where data points are stored, default is "tsdb" +#tsd.storage.hbase.data_table = tsdb + +# Name of the HBase table where UID information is stored, default is "tsdb-uid" +#tsd.storage.hbase.uid_table = tsdb-uid + +# Path under which the znode for the -ROOT- region is located, default is "/hbase" +#tsd.storage.hbase.zk_basedir = /hbase + +# A space separated list of Zookeeper hosts to connect to, with or without +# port specifiers, default is "localhost" +#tsd.storage.hbase.zk_quorum = localhost diff --git a/tsdb.in b/tsdb.in index 1e1fc356a1..ebf6e3d6a6 100644 --- a/tsdb.in +++ b/tsdb.in @@ -9,6 +9,7 @@ mydir=`dirname "$0"` abs_srcdir='@abs_srcdir@' abs_builddir='@abs_builddir@' pkgdatadir='@pkgdatadir@' +configdir='@configdir@' # Either we've been installed and pkgdatadir exists, or we haven't been # installed and abs_srcdir / abs_builddir aren't empty. test -d "$pkgdatadir" || test -n "$abs_srcdir$abs_builddir" || { @@ -23,6 +24,20 @@ if test -n "$pkgdatadir"; then done # Add pkgdatadir itself so we can find logback.xml CLASSPATH="$CLASSPATH:$pkgdatadir" + + if test -d "$pkgdatadir/bin"; then + CLASSPATH="$CLASSPATH:$pkgdatadir/bin" + fi + + if test -d "$pkgdatadir/lib"; then + for jar in "$pkgdatadir"/lib/*.jar; do + CLASSPATH="$CLASSPATH:$jar" + done + fi + + if test -n "$configdir" && test -d "$configdir"; then + CLASSPATH="$CLASSPATH:$configdir" + fi else localdir="$abs_builddir" # If we're running out of the build tree, it's especially important that we