Skip to content

Commit

Permalink
Various fixes to generated .deb packages
Browse files Browse the repository at this point in the history
This resolves a few inconsistencies and issues in the generated packages
for Debian/Ubuntu:

  * Creates /etc/logstash/conf.d
  * Installs a basic defaults file in /etc/default/logstash (which also sets HOME)
  * Stops creating /var/run/logstash (unused)
  * Uses /var/lib/logstash as the home directory of the logstash user instead of /home/logstash
  * Defaults package files to be owned by root, fixes ownership in post-install script
  * Properly stops service when removing the package on Debian

The end result is that after installing, LogStash will pretty much "just
work" with only 2 changes:

1) Enable START=yes in /etc/default/logstash
2) Provide a config for the LogStash agent
  • Loading branch information
Tray Torrance committed Aug 14, 2013
1 parent dd13128 commit 8925b68
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.*.swp
*.gem
pkg/*.deb
pkg/*.rpm
*.class
.rbx
Gemfile.lock
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ clean:
-$(QUIET)rm -rf .bundle
-$(QUIET)rm -rf build
-$(QUIET)rm -rf vendor
-$(QUIET)rm -f pkg/*.deb

.PHONY: compile
compile: compile-grammar compile-runner | build/ruby
Expand Down
22 changes: 14 additions & 8 deletions pkg/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,26 @@ case $os@$release in
install -m755 logstash.sysv.redhat $destdir/etc/init.d/logstash
;;
ubuntu@*)
mkdir -p $destdir/etc/logstash/conf.d
mkdir -p $destdir/etc/logrotate.d
mkdir -p $destdir/etc/init
mkdir -p $destdir/var/log/logstash
mkdir -p $destdir/etc/sysconfig
touch $destdir/etc/sysconfig/logstash
install -m644 logrotate.conf $destdir/etc/logrotate.d/
mkdir -p $destdir/etc/default
touch $destdir/etc/default/logstash
install -m644 logrotate.conf $destdir/etc/logrotate.d/logstash
install -m644 logstash.default $destdir/etc/default/logstash
install -m755 logstash.upstart.ubuntu $destdir/etc/init/logstash.conf
;;
debian@*)
mkdir -p $destdir/etc/logstash/conf.d
mkdir -p $destdir/etc/logrotate.d
mkdir -p $destdir/etc/init.d
mkdir -p $destdir/var/lib/logstash
mkdir -p $destdir/var/run/logstash
mkdir -p $destdir/var/log/logstash
install -m644 logrotate.conf $destdir/etc/logrotate.d/
mkdir -p $destdir/etc/default
touch $destdir/etc/default/logstash
install -m644 logrotate.conf $destdir/etc/logrotate.d/logstash
install -m644 logstash.default $destdir/etc/default/logstash
install -m755 logstash.sysv.debian $destdir/etc/init.d/logstash
;;
*)
Expand All @@ -87,9 +92,10 @@ case $os in
fpm -s dir -t deb -n logstash -v "$VERSION" \
-a all --iteration 1-$os \
-d "java6-runtime" \
--before-install ubuntu/before-install.sh \
--before-remove ubuntu/before-remove.sh \
--after-install ubuntu/after-install.sh \
--deb-user root --deb-group root \
--before-install $os/before-install.sh \
--before-remove $os/before-remove.sh \
--after-install $os/after-install.sh \
-f -C $destdir .
;;
esac
5 changes: 3 additions & 2 deletions pkg/debian/after-install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh

mkdir -p /home/logstash
chown logstash:logstash /home/logstash
chown -R logstash:logstash /opt/logstash
chown logstash /var/log/logstash
chown logstash:logstash /var/lib/logstash
5 changes: 3 additions & 2 deletions pkg/debian/before-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fi

# create logstash user
if ! getent passwd logstash >/dev/null; then
useradd -r -g logstash -d /home/logstash \
-s /sbin/nologin -c "logstash" logstash
useradd -M -r -g logstash -d /var/lib/logstash \
-s /sbin/nologin -c "LogStash Service User" logstash
fi

8 changes: 2 additions & 6 deletions pkg/debian/before-remove.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/bin/sh

if [ $1 == "remove" ]; then
/etc/init.d/logstash > /dev/null 2>&1 || true
/etc/init.d/logstash stop >/dev/null 2>&1 || true

if getent passwd logstash >/dev/null ; then
userdel logstash
fi

if getent group logstash > /dev/null ; then
if getent group logstash >/dev/null ; then
groupdel logstash
fi

if [ -d "/home/logstash" ] ; then
rm -rf /home/logstash
fi
fi
45 changes: 45 additions & 0 deletions pkg/logstash.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# defaults for logstash

# Start logstash on boot?
START=no

# pulled in from the init script; makes things easier.
NAME=logstash

# location of java
JAVA=/usr/bin/java

# arguments to pass to java
LS_JAVA_OPTS="-Xmx256m -Djava.io.tmpdir=/var/lib/logstash/"

PIDFILE=/var/run/logstash.pid

# user id to be invoked as
LS_USER=logstash

# location of the logstas jar file
LS_JAR=/opt/logstash/logstash.jar

# logstash home location
LS_HOME=/var/lib/logstash

# logstash log directory
LOG_DIR=/var/log/logstash

# logstash log file
LOG_FILE=$LOG_DIR/$NAME.log

# logstash configuration directory
CONF_DIR=/etc/logstash/conf.d

# Open file limit
OPEN_FILES=2048

# Nice level
NICE=19

# Set LogStash options
LS_OPTS="--log ${LOG_FILE}"

# Set a home directory
HOME=/var/lib/logstash
5 changes: 3 additions & 2 deletions pkg/logstash.sysv.debian
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ LOG_FILE=$LOG_DIR/$NAME.log
# Open File limit
OPEN_FILES=2048


# LogStash options
LS_OPTS="--log ${LOG_DIR}/${NAME}.log"

# Nice level
NICE=19
Expand All @@ -71,7 +72,7 @@ fi
# Define other required variables
PID_FILE=/var/run/$NAME.pid
DAEMON=$LS_JAR
DAEMON_OPTS="agent -f ${CONF_DIR} --log ${LOG_FILE}"
DAEMON_OPTS="agent -f ${CONF_DIR} ${LS_OPTS}"

is_true() {
if [ "x$1" = "xtrue" -o "x$1" = "xyes" -o "x$1" = "x1" ] ; then
Expand Down
4 changes: 2 additions & 2 deletions pkg/logstash.upstart.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ setgid logstash

# You need to chdir somewhere writable because logstash needs to unpack a few
# temporary files on startup.
chdir /home/logstash
chdir /var/lib/logstash
console log
exec /usr/bin/java -jar logstash.jar agent -f /etc/logstash/agent.conf
exec /usr/bin/java -jar /opt/logstash/logstash.jar agent -f /etc/logstash/conf.d
5 changes: 3 additions & 2 deletions pkg/ubuntu/after-install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh

mkdir -p /home/logstash
chown logstash:logstash /home/logstash
chown -R logstash:logstash /opt/logstash
chown logstash /var/log/logstash
chown logstash:logstash /var/lib/logstash
4 changes: 2 additions & 2 deletions pkg/ubuntu/before-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fi

# create logstash user
if ! getent passwd logstash >/dev/null; then
useradd -r -g logstash -d /home/logstash \
-s /sbin/nologin -c "logstash" logstash
useradd -M -r -g logstash -d /var/lib/logstash \
-s /sbin/nologin -c "LogStash Service User" logstash
fi
8 changes: 2 additions & 6 deletions pkg/ubuntu/before-remove.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/bin/sh

if [ $1 == "remove" ]; then
stop logstash > /dev/null 2>&1 || true
stop logstash >/dev/null 2>&1 || true

if getent passwd logstash >/dev/null ; then
userdel logstash
fi

if getent group logstash > /dev/null ; then
if getent group logstash >/dev/null ; then
groupdel logstash
fi

if [ -d "/home/logstash" ] ; then
rm -rf /home/logstash
fi
fi

0 comments on commit 8925b68

Please sign in to comment.