Skip to content

Commit

Permalink
Reorganize RPM package directories and support chaning to a non-root …
Browse files Browse the repository at this point in the history
…user.

- Renamed and moved src/opentsdb-init-d.sh to build-aux/init.d/opentsdb.
- Made the RPM directory structure similar to that of the Debian package.
- Copied build-aux/deb/opentsdb.conf to build-aux/rpm/opentsdb.conf.
- Copied jars to /usr/share/opentsdb/lib during installation.
- Left a TODO for the alternatives.
- Changed the owner of files touched by OpenTSDB.
*** For the existing OpenTSDB installations, we should modify the init script
symbolic links to point to the new target.

New directory structure:
-----------
rpmbuildroot/usr/share/opentsdb:
  bin/  etc/  lib/  static/  tools/
rpmbuildroot/usr/share/opentsdb/etc:
  init.d/  opentsdb/
rpmbuildroot/var/cache:
  opentsdb/

Signed-off-by: Chris Larsen <clarsen@euphoriaaudio.com>
  • Loading branch information
jesse5e authored and manolama committed Apr 18, 2014
1 parent a22d641 commit 2c0d526
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 21 deletions.
107 changes: 94 additions & 13 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ plugin_test_jar := plugin_test.jar
builddata_SRC := src/BuildData.java
BUILT_SOURCES = $(builddata_SRC)
nodist_bin_SCRIPTS = tsdb
dist_noinst_SCRIPTS = src/create_table.sh
# TODO: Move opentsdb-init-d.sh to /etc/init.d/opentsdb.
dist_pkgdata_SCRIPTS := src/mygnuplot.sh src/mygnuplot.bat src/opentsdb.conf src/opentsdb-init-d.sh src/opentsdb_restart.py
dist_noinst_DATA = pom.xml.in
dist_noinst_SCRIPTS = src/create_table.sh src/mygnuplot.sh src/mygnuplot.bat \
src/opentsdb.conf src/opentsdb_restart.py
dist_noinst_DATA = pom.xml.in build-aux/rpm/opentsdb.conf build-aux/rpm/init.d/opentsdb
tsdb_SRC := \
src/core/Aggregator.java \
src/core/Aggregators.java \
Expand Down Expand Up @@ -128,9 +127,6 @@ tsdb_DEPS = \
$(SUASYNC) \
$(ZOOKEEPER)

# Install all the .jar files in pkgdatadir.
pkgdata_DATA = $(tsdb_DEPS) $(jar)

test_SRC := \
test/core/TestAggregators.java \
test/core/TestCompactionQueue.java \
Expand Down Expand Up @@ -360,7 +356,8 @@ gwttsd: staticroot
# Ideally I'd like Automake to take care of this, but right now I don't see
# how to tell it to install a bunch of files recursively for which I don't
# know ahead of time what the file names are.
install-data-local: staticroot
install-data-local: staticroot install-data-lib install-data-tools \
install-data-bin install-data-etc
@$(NORMAL_INSTALL)
test -z "$(staticdir)" || $(mkdir_p) "$(DESTDIR)$(staticdir)"
@set -e; pwd; ls -lFh; cd "$(DEV_TSD_STATICROOT)"; \
Expand All @@ -374,7 +371,90 @@ install-data-local: staticroot
$(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(staticdir)/$$p"; \
done

uninstall-local:
install-data-lib: $(tsdb_DEPS) $(jar)
@$(NORMAL_INSTALL)
@list='$(tsdb_DEPS) $(jar)'; test -n "$(pkgdatadir)" || list=; \
destdatalibdir="$(DESTDIR)$(pkgdatadir)/lib" ; \
if test -n "$$list"; then \
echo " $(mkdir_p) $$destdatalibdir"; \
$(mkdir_p) "$$destdatalibdir" || exit 1; \
fi; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
done | $(am__base_list) | \
while read files; do \
echo " $(INSTALL_DATA) $$files '$$destdatalibdir'"; \
$(INSTALL_DATA) $$files "$$destdatalibdir" || exit $$?; \
done

uninstall-data-lib:
@$(NORMAL_UNINSTALL)
destdatalibdir="$(DESTDIR)$(pkgdatadir)/lib" ; \
echo " rm -rf $$destdatalibdir" ; \
rm -rf "$$destdatalibdir"

install-data-tools: $(tsdb_DEPS) $(jar)
@$(NORMAL_INSTALL)
destdatatoolsdir="$(DESTDIR)$(pkgdatadir)/tools" ; \
echo " $(mkdir_p) $$destdatatoolsdir"; \
$(mkdir_p) "$$destdatatoolsdir" || exit 1; \
echo " $(INSTALL_SCRIPT)" $(top_srcdir)/tools/* "$$destdatatoolsdir" ; \
$(INSTALL_SCRIPT) $(top_srcdir)/tools/* "$$destdatatoolsdir" || exit 1;

uninstall-data-tools:
@$(NORMAL_UNINSTALL)
destdatatoolsdir="$(DESTDIR)$(pkgdatadir)/tools" ; \
echo " rm -rf $$destdatatoolsdir" ; \
rm -rf "$$destdatatoolsdir"

install-data-bin: tsdb
@$(NORMAL_INSTALL)
destdatabindir="$(DESTDIR)$(pkgdatadir)/bin" ; \
echo " $(mkdir_p) $$destdatabindir"; \
$(mkdir_p) "$$destdatabindir" || exit 1; \
bins="$(top_srcdir)/src/create_table.sh" ; \
bins="$$bins $(top_srcdir)/src/mygnuplot.sh" ; \
bins="$$bins $(top_srcdir)/src/mygnuplot.bat" ; \
bins="$$bins $(top_srcdir)/src/opentsdb_restart.py" ; \
bins="$$bins $(DESTDIR)$(bindir)/tsdb" ; \
echo " $(INSTALL_SCRIPT)" $$bins "$$destdatabindir" ; \
$(INSTALL_SCRIPT) $$bins "$$destdatabindir" || exit 1;

uninstall-data-bin:
@$(NORMAL_UNINSTALL)
destdatabindir="$(DESTDIR)$(pkgdatadir)/bin" ; \
echo " rm -rf $$destdatabindir" ; \
rm -rf "$$destdatabindir"

# NOTE: We keep a copy of /etc files at the package data directory.
# Users should create symlinks to etc/init.d/opentsdb and
# etc/opentsdb/opentsdb.conf if they want to use the stock script and
# configuration.
install-data-etc:
@$(NORMAL_INSTALL)
destdataetcdir="$(DESTDIR)$(pkgdatadir)/etc" ; \
destdataconfdir="$$destdataetcdir/opentsdb" ; \
destdatainitdir="$$destdataetcdir/init.d" ; \
echo " $(mkdir_p) $$destdataconfdir"; \
$(mkdir_p) "$$destdataconfdir" || exit 1; \
echo " $(mkdir_p) $$destdatainitdir"; \
$(mkdir_p) "$$destdatainitdir" || exit 1; \
conf_files="$(top_srcdir)/build-aux/rpm/opentsdb.conf" ; \
echo " $(INSTALL_SCRIPT)" $$conf_files "$$destdataconfdir" ; \
$(INSTALL_DATA) $$conf_files "$$destdataconfdir" || exit 1; \
init_file="$(top_srcdir)/build-aux/rpm/init.d/opentsdb" ; \
echo " $(INSTALL_SCRIPT)" $$init_file "$$destdatainitdir" ; \
$(INSTALL_SCRIPT) $$init_file "$$destdatainitdir" || exit 1;

uninstall-data-etc:
@$(NORMAL_UNINSTALL)
destdataetcdir="$(DESTDIR)$(pkgdatadir)/etc" ; \
echo " rm -rf $$destdataetcdir" ; \
rm -rf "$$destdataetcdir"

uninstall-local: uninstall-data-lib uninstall-data-tools uninstall-data-bin \
uninstall-data-etc
@$(NORMAL_UNINSTALL)
rm -rf "$(DESTDIR)$(staticdir)"

Expand Down Expand Up @@ -517,20 +597,21 @@ pom.xml: pom.xml.in Makefile

TIMESTAMP := $(shell date +"%Y%m%d%H%M%S")
RPM_REVISION := 1
RPM := opentsdb-$(PACKAGE_VERSION)-$(RPM_REVISION).noarch.rpm
RPM_SNAPSHOT := opentsdb-$(PACKAGE_VERSION)-$(TIMESTAMP).noarch.rpm
RPM_TARGET := noarch
RPM := opentsdb-$(PACKAGE_VERSION)-$(RPM_REVISION).$(RPM_TARGET).rpm
RPM_SNAPSHOT := opentsdb-$(PACKAGE_VERSION)-$(RPM_REVISION)-$(TIMESTAMP)-"`whoami`".$(RPM_TARGET).rpm
SOURCE_TARBALL := opentsdb-$(PACKAGE_VERSION).tar.gz
rpm: $(RPM)

$(SOURCE_TARBALL): dist
$(RPM): $(SOURCE_TARBALL)
$(RPM): opentsdb.spec
rpmbuild --target=noarch --buildroot=`pwd`/rpmbuildroot -bb $<
rpmbuild --target=$(RPM_TARGET) --buildroot=`pwd`/rpmbuildroot -bb $<
test -f $@ || for rpm in noarch/$@ \
`awk '$$1=="Name:"{print $$2}' $<`.`awk '$$1=="BuildArch:"{print $$2}' $<`.rpm; do \
test -f "$$rpm" && mv "$$rpm" $(RPM_SNAPSHOT) && break; \
done
if test -d noarch; then rmdir noarch; fi
if test -d $(RPM_TARGET); then rmdir $(RPM_TARGET); fi

debian: dist staticroot
$(mkdir_p) $(distdir)/debian
Expand Down
41 changes: 35 additions & 6 deletions src/opentsdb-init-d.sh → build-aux/rpm/init.d/opentsdb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,41 @@ PROG_OPTS="tsd --config=${CONFIG}"

start() {
echo -n "Starting ${NAME}: "
curid="`id -u -n`"
if [ "$curid" != root ] && [ "$curid" != "$USER" ] ; then
echo "Must be run as root or $USER, but was run as $curid"
return 1
fi
# Sets the maximum number of open file descriptors allowed.
ulimit -n $MAX_OPEN_FILES

# TODO: Support non-root user and group. Currently running as root
# is required because /usr/share/opentsdb/opentsdb_restart.py
# must be called as root. This could be fixed with a sudo.
curulimit="`ulimit -n`"
if [ "$curulimit" -lt $MAX_OPEN_FILES ] ; then
echo "'ulimit -n' must be greater than or equal to $MAX_OPEN_FILES, is $curulimit"
return 1
fi

# Set a default value for JVMARGS
: ${JVMXMX:=-Xmx6000m}
: ${JVMARGS:=-DLOG_FILE_PREFIX=${LOG_FILE} -enableassertions -enablesystemassertions $JVMXMX -XX:OnOutOfMemoryError=/usr/share/opentsdb/opentsdb_restart.py}
: ${JVMARGS:=-DLOG_FILE_PREFIX=${LOG_FILE} -enableassertions -enablesystemassertions $JVMXMX -XX:OnOutOfMemoryError=/usr/share/opentsdb/bin/opentsdb_restart.py}
export JVMARGS
daemon --user $USER --pidfile $PID_FILE "$PROG $PROG_OPTS 1> ${LOG_FILE}opentsdb.out 2> ${LOG_FILE}opentsdb.err &"

if [ "`id -u -n`" == root ] ; then
# Changes the owner of the log directory to allow non-root OpenTSDB
# daemons to create and rename log files.
chown $USER: $LOG_DIR > /dev/null 2>&1
chown $USER: ${LOG_FILE}*opentsdb.log > /dev/null 2>&1
chown $USER: ${LOG_FILE}opentsdb.out > /dev/null 2>&1
chown $USER: ${LOG_FILE}opentsdb.err > /dev/null 2>&1

# Changes the owner of the lock, and the pid files to allow
# non-root OpenTSDB daemons to run /usr/share/opentsdb/bin/opentsdb_restart.py.
touch $LOCK_FILE && chown $USER: $LOCK_FILE
touch $PID_FILE && chown $USER: $PID_FILE
daemon --user $USER --pidfile $PID_FILE "$PROG $PROG_OPTS 1>> ${LOG_FILE}opentsdb.out 2>> ${LOG_FILE}opentsdb.err &"
else
# Don't have to change user.
daemon --pidfile $PID_FILE "$PROG $PROG_OPTS 1>> ${LOG_FILE}opentsdb.out 2>> ${LOG_FILE}opentsdb.err &"
fi
retval=$?
sleep 2
echo
Expand All @@ -86,6 +110,11 @@ stop() {
killproc -p $PID_FILE $NAME
retval=$?
echo
# Non-root users don't have enough permission to remove pid and lock files.
# So, the opentsdb_restart.py cannot get rid of the files, and the command
# "service opentsdb status" will complain about the existing pid file.
# Makes the pid file empty.
echo > $PID_FILE
[ $retval -eq 0 ] && (rm -f $PID_FILE && rm -f $LOCK_FILE)
return $retval
}
Expand Down
63 changes: 63 additions & 0 deletions build-aux/rpm/opentsdb.conf
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions opentsdb.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ make
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
mkdir -p %{buildroot}/var/cache/opentsdb
# TODO: Use alternatives to manage the init script and configuration.
# NOTE: Users should create symlinks to etc/init.d/opentsdb and
# etc/opentsdb/opentsdb.conf if they want to use the stock script and
# configuration.


%clean
Expand All @@ -65,8 +69,10 @@ rm -rf %{buildroot}
%files
%defattr(644,root,root,755)
%attr(0755,root,root) %{_bindir}/*
%attr(0755,root,root) %{_datarootdir}/opentsdb/*.sh
%attr(0755,root,root) %{_datarootdir}/opentsdb/*.py
%attr(0755,root,root) %{_datarootdir}/opentsdb/bin/*.sh
%attr(0755,root,root) %{_datarootdir}/opentsdb/bin/*.py
%attr(0755,root,root) %{_datarootdir}/opentsdb/tools/*
%attr(0755,root,root) %{_datarootdir}/opentsdb/etc/init.d/opentsdb
%doc
%{_datarootdir}/opentsdb
%{_bindir}/tsdb
Expand Down

0 comments on commit 2c0d526

Please sign in to comment.