Gearmand 1.1.x on Debian (Wheezy)

From HostmasterWiki
Jump to: navigation, search

Prepare[edit]

$ sudo apt-get install \
libssl-dev \
libboost-dev \
libboost-program-options-dev \
libevent-dev \
uuid-dev \
libmysqlclient-dev \
gperf \
make \
gcc \
g++

$ wget https://launchpad.net/gearmand/1.2/1.1.12/+download/gearmand-1.1.12.tar.gz 
$ tar xvfz gearmand-1.1.12.tar.gz


Compile[edit]

$ cd gearmand-1.1.12

$ ./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--disable-libdrizzle \
--disable-libpq \
--disable-libtokyocabinet \
--disable-hiredis \
--enable-ssl

$ make
$ sudo make install

$ sudo addgroup --system gearman
$ sudo adduser \
--system \
--disabled-login \
--ingroup gearman \
--home /var/lib/gearman \
--gecos "Gearman Job Server" \
--shell /bin/false \
gearman

$ sudo mkdir -p /var/log/gearman-job-server
$ sudo chown gearman:gearman /var/log/gearman-job-server


Install[edit]

init.d[edit]

$ nano /etc/init.d/gearman-job-server


#!/bin/sh

# Gearman server and library
# Copyright (C) 2008 Brian Aker, Eric Day
# All rights reserved.
#
# Use and distribution licensed under the BSD license.  See
# the COPYING file in this directory for full text.

### BEGIN INIT INFO
# Provides:          gearman-job-server
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable gearman job server
### END INIT INFO

prefix=/usr
exec_prefix=${prefix}
NAME=gearmand
DAEMON=${exec_prefix}/sbin/gearmand
PIDDIR=/var/run/gearman
PIDFILE=${PIDDIR}/gearmand.pid
GEARMANUSER="gearman"
PARAMS=""

test -x ${DAEMON} || exit 0

. /lib/lsb/init-functions

test -f /etc/default/gearman-job-server && . /etc/default/gearman-job-server

start()
{
  log_daemon_msg "Starting Gearman Server" "gearmand"
  if ! test -d ${PIDDIR}
  then
    mkdir ${PIDDIR}
    chown ${GEARMANUSER} ${PIDDIR}
  fi
  if start-stop-daemon \
    --start \
    --exec $DAEMON \
    -- --pid-file=$PIDFILE \
       --user=$GEARMANUSER \
       --daemon \
       --log-file=/var/log/gearman-job-server/gearman.log \
       $PARAMS 
  then
    log_end_msg 0
  else
    log_end_msg 1
    log_warning_msg "Please take a look at the syslog"
    exit 1
  fi
}

stop()
{
  log_daemon_msg "Stopping Gearman Server" "gearmand"
  if start-stop-daemon \
    --stop \
    --oknodo \
    --exec $DAEMON \
    --pidfile $PIDFILE
  then
    log_end_msg 0
  else
    log_end_msg 1
    exit 1
  fi
}

status()
{
    status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
}

case "$1" in

  start)
    start
  ;;

  stop)
    stop
  ;;

  status)
    status
  ;;

  restart|force-reload)
    stop
    start
  ;;

  *)
    echo "Usage: $0 {start|stop|restart|force-reload|status}"
  ;;

esac


$ chmod +x /etc/init.d/gearman-job-server
$ update-rc.d gearman-job-server defaults


logrotate.d[edit]

$ nano /etc/logrotate.d/gearman-job-server


/var/log/gearman-job-server/*.log {
        daily
        rotate 4
        missingok
        compress
}


default[edit]

$ nano /etc/default/gearman-job-server


# Parameters to pass to gearmand.
PARAMS="--listen=127.0.0.1"


Munin Plugin[edit]

$ cd /usr/share/munin/plugins
$ sudo wget \
http://munin-monitoring.org/export/ddc595889f8d61a865df2d7f5486ecb5e14a098f/munin-contrib/plugins/gearman/gearman_queue \
http://munin-monitoring.org/export/ddc595889f8d61a865df2d7f5486ecb5e14a098f/munin-contrib/plugins/gearman/gearman_workers 
$ sudo chmod +x gearman_*

$ cd /etc/munin/plugins
$ sudo ln -s /usr/share/munin/plugins/gearman_queue gearman_queue && \
sudo ln -s /usr/share/munin/plugins/gearman_workers gearman_workers

$ sudo echo -ne "[gearman*]\nenv.host 127.0.0.1\n" > /etc/munin/plugin-conf.d/gearman
$ sudo /etc/init.d/munin-node restart