Skip to content

Instantly share code, notes, and snippets.

@nickethier
Created October 17, 2011 17:40
Show Gist options
  • Save nickethier/1293220 to your computer and use it in GitHub Desktop.
Save nickethier/1293220 to your computer and use it in GitHub Desktop.
Logstash + Jenkins / FPM
#!/usr/bin/env bash
ruby_version="1.9.2-p180"
rpm_version="0.2"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
#make sure we have rvm
no_rvm=$(which rvm | grep 'no rvm')
if [ "$no_rvm" ] ; then
echo "install rvm"
exit 1
fi
run() {
echo "$@"
"$@"
}
#make sure we have the correct ruby version
if ! rvm list | grep "$ruby_version"; then
run rvm pkg install zlib
run rvm pkg install readline
run rvm pkg install openssl
run rvm install "$ruby_version" -C --with-zlib-dir=$rvm_path/usr --with-readline-dir=$rvm_path/usr --with-openssl-dir=$rvm_path/usr
fi
#make sure we have a fpm gemset
found=''
our_ruby=''
while read LINE
do
if [ "$our_ruby" ]
then
found=$(echo $LINE | grep 'fpm')
if [ "$found" ]; then
break;
fi
next_ruby=$(echo $LINE | grep 'gemsets for')
if [ "$next_ruby" ]; then
break;
fi
fi
if [ -z "$our_ruby" ]; then
our_ruby=$(echo $LINE | grep "$ruby_version")
fi
done < <(rvm gemset list_all)
#create the fpm gemset if it isn't available
if [ -z "$found" ]; then
echo "creating 'fpm' gemset and installing bundler"
run rvm use "$ruby_version@fpm" --create
run rvm "$ruby_version@fpm" gem install fpm
fi
run rvm "$ruby_version@fpm" exec fpm -s dir -t rpm -C ./build -a x86_64 -n logstash -v $rpm_version -x .svn --post-install post-install.sh --post-uninstall post-uninstall.sh home/logstash
#!/bin/bash
#
# Init file for logstash log collection daemon
#
# chkconfig: 2345 80 20
# description: logstash log collection daemon
#
# pidfile: /var/run/logstash.pid
# source function library
. /etc/rc.d/init.d/functions
RETVAL=0
prog="logstash"
HOME="/home/logstash"
USER="logstash"
PROCESS="rvm 1.9.2@logstash exec bundle exec ruby $HOME/bin/logstash agent -f $HOME/config/logstash.conf 2>> $HOME/logs/logstash.log"
PIDFILE=/var/run/logstash.pid
# totally cheating here because I couldn't get the daemon function working how I wanted...
getPid()
{
if [ -f $PIDFILE ]
then
pid=`cat $PIDFILE`
return 0
fi
pid=$(ps -eo pid,args | grep "\/home\/logstash\/bin\/logstash agent" | cut -c1-6)
}
status()
{
echo "Checking Logstash Status..."
getPid
if [ -n "$pid" ]
then
echo_running
echo
return 0
else
echo_stopped
echo
return 0
fi
}
echo_running() {
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
echo -n "["
[ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
echo -n $"RUNNING"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "]"
echo -ne "\r"
return 0
}
echo_stopped() {
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
echo -n "["
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo -n $"STOPPED"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "]"
echo -ne "\r"
return 1
}
start()
{
echo -n $"Starting Logstash... "
getPid
if [ -n "$pid" ]
then
echo "Logstash is already running: $pid"
echo_failure
echo
return 1
fi
runuser -s /bin/bash - $USER -c "$PROCESS &"
getPid
echo "$pid" > $PIDFILE
echo_success
echo
}
stop()
{
echo -n $"Stopping Logstash... "
getPid
if [ -z "$pid" ] || [ ! -f $PIDFILE ]
then
echo "Logstash is not running"
echo_failure
echo
return 1
fi
killproc -p $PIDFILE
echo
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac
exit $RETVAL
/usr/sbin/useradd -r -d /home/logstash logstash
chown -R logstash:logstash /home/logstash
ln -s /home/logstash/etc/logstash /etc/init.d/logstash
chmod 755 /etc/init.d/logstash
chkconfig --add logstash
/usr/sbin/userdel logstash
rm -rf /home/logstash
rm /etc/init.d/logstash
sudo git clone git://github.com/logstash/logstash.git /home/logstash
sudo /usr/sbin/useradd -r -d /home/logstash logstash
sudo su - logstash
curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
. ~/.bashrc
rvm pkg install readline
rvm pkg install zlib
rvm install 1.9.2 –with-zlib-dir=$rvm_path/usr –with-readline-dir=$rvm_path/usr
rvm 1.9.2@logstash –create
gem install bundler –pre
bundle install
rm -rf docs/ etc/ misc/ screencast/
mkdir logs config
touch logs/logstash.log
touch etc/logstash
touch config/logstash.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment