Skip to content

Instantly share code, notes, and snippets.

@eirc
Last active February 4, 2018 23:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eirc/15d0ee7d0de73777d3aa to your computer and use it in GitHub Desktop.
Save eirc/15d0ee7d0de73777d3aa to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
sudo aptitude install -y build-essential libtool automake autoconf libcurl4-gnutls-dev check libevent-dev libmemcached-dev memcached
git clone https://github.com/couchbase/libconflate.git
cd libconflate
git checkout 2.1.1r
git checkout -b 2.1.1r
./config/autorun.sh
./configure
make
sudo make install
cd ..
git clone https://github.com/couchbase/libvbucket.git
cd libvbucket
git checkout 2.1.1r
git checkout -b 2.1.1r
./config/autorun.sh
./configure
make
sudo make install
cd ..
git clone https://github.com/couchbase/moxi.git
cd moxi
git checkout 2.5.0
git checkout -b 2.5.0
./config/autorun.sh
./configure
make
sudo make install
cd ..
mkdir moxi-server_2.5.0-0eric1_x86_64
cd moxi-server_2.5.0-0eric1_x86_64
mkdir DEBIAN
cat > DEBIAN/control <<'__EOF'
Package: moxi-server
Version: 2.5.0-0eric1
Architecture: amd64
Maintainer: Errikos Koen <e.koen@pamediakopes.gr>
Installed-Size: 2276
Depends: lsb-base (>= 3.2), libhashkit2, libmemcached10
Section: web
Priority: extra
Homepage: http://couchbase.com
Description: Moxi Server
Moxi Server is the packaged distribution of the moxi
proxy for memcached and couchbase.
__EOF
cat > DEBIAN/preinst <<'__EOF'
#!/bin/sh
# preinst script for moxi software
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <new-preinst> `install'
# * <new-preinst> `install' <old-version>
# * <new-preinst> `upgrade' <old-version>
# * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
install|upgrade)
getent group moxi >/dev/null || \
groupadd -r moxi || exit 1
getent passwd moxi >/dev/null || \
useradd -r -g moxi -d /opt/moxi -s /bin/bash \
-c "Moxi system user" moxi || exit 1
exit 0
;;
abort-upgrade)
;;
*)
echo "preinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
exit 0
__EOF
cat > DEBIAN/postinst <<'__EOF'
#!/bin/sh
# postinst script for moxi-server
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
configure)
chown -R moxi:moxi /opt/moxi
cat << EOF
You have successfully installed Moxi Server.
Please next edit the configuration files: /opt/moxi/etc
Afterwards, to start the moxi server: /etc/init.d/moxi-server start
By using this software you agree to the End User License Agreement.
See: /opt/moxi/LICENSE.txt
EOF
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
# Automatically added by dh_installinit
if [ -x "/etc/init.d/moxi-server" ]; then
update-rc.d moxi-server defaults >/dev/null || exit $?
fi
# End automatically added section
exit 0
__EOF
cat > DEBIAN/prerm <<'__EOF'
#!/bin/sh
set -e
/etc/init.d/moxi-server stop || true
__EOF
cat > DEBIAN/postrm <<'__EOF'
#!/bin/sh
set -e
# Automatically added by dh_installinit
if [ "$1" = "purge" ] ; then
update-rc.d moxi-server remove >/dev/null
fi
# End automatically added section
__EOF
chmod +x DEBIAN/preinst
chmod +x DEBIAN/postinst
chmod +x DEBIAN/prerm
chmod +x DEBIAN/postrm
mkdir -p etc/init.d
mkdir -p opt/moxi/bin
mkdir -p opt/moxi/etc
mkdir -p opt/moxi/lib
mkdir -p usr/share/doc/moxi-server
cat > etc/init.d/moxi-server <<'__EOF'
#!/bin/sh
#
# Startup / shutdown script for the moxi server
#
# Copyright (c) 2011, Couchbase, Inc.
# All rights reserved
#
#
### BEGIN INIT INFO
# Provides: moxi-server
# Required-Start: $network $local_fs
# Required-Stop:
# Should-Start: $named
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: moxi server
# Description: moxi server
### END INIT INFO
. /lib/lsb/init-functions
exec /opt/moxi/etc/moxi-init.d "$@"
__EOF
cat > opt/moxi/bin/moxi <<'__EOF'
#!/bin/sh
MOXI_PREFIX=$(dirname $0)/..
LD_LIBRARY_PATH=${MOXI_PREFIX}/lib ${MOXI_PREFIX}/bin/moxi.actual $@
__EOF
cat > opt/moxi/etc/moxi-cluster.cfg <<'__EOF'
# Please point moxi at your membase cluster by specifying
# a membase REST URL.
#
# The moxi server won't start correctly until after you
# edit and uncomment the url line below...
#
# url=http://HOSTNAME:8091/pools/default/bucketsStreaming/default
__EOF
cat > opt/moxi/etc/moxi-init.d <<'__EOF'
#!/bin/sh
#
# Startup / shutdown script for the moxi server
#
# Copyright (c) 2011, Couchbase, Inc.
# All rights reserved
#
#
### BEGIN INIT INFO
# Provides: moxi-server
# Required-Start: $network $local_fs
# Required-Stop:
# Should-Start: $named
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: moxi server
# Description: moxi server
### END INIT INFO
. /lib/lsb/init-functions
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DAEMON=/opt/moxi/bin/moxi
PIDFILE=/var/run/moxi-server.pid
MOXI_CFG=/opt/moxi/etc/moxi.cfg
MOXI_CLUSTER_CFG=/opt/moxi/etc/moxi-cluster.cfg
test -f $DAEMON || exit 0
test -f $MOXI_CFG || exit 0
test -f $MOXI_CLUSTER_CFG || exit 0
start() {
touch $PIDFILE
chown moxi $PIDFILE
cd /var/run
ulimit -n 10240
ulimit -c unlimited
start_daemon $DAEMON -d -P $PIDFILE -Z $MOXI_CFG -z $MOXI_CLUSTER_CFG -u moxi
errcode=$?
return $errcode
}
wait_running() {
if running; then
return 0
fi
for i in 1 2 3 4 5 6 7 8; do
sleep 0.5
if running; then
return 0
fi
done
return 1
}
start_checking() {
start
if wait_running; then
true
else
log_failure_msg "Failed to start moxi server"
return 1
fi
}
stop() {
killproc -p $PIDFILE $DAEMON
errcode=$?
sleep 1
rm -f $PIDFILE
return $errcode
}
running() {
pidofproc -p $PIDFILE $DAEMON >/dev/null
errcode=$?
return $errcode
}
case $1 in
start)
if running ; then
log_warning_msg "moxi server is already started"
exit 0
fi
start_checking && log_success_msg "Started moxi server"
;;
stop)
if stop; then
log_success_msg "Stopped moxi server"
else
log_failure_msg "Failed to stop moxi server"
fi
;;
restart)
stop
log_success_msg "Stopped moxi server"
start
log_success_msg "Started moxi server"
;;
status)
if running ; then
log_success_msg "moxi server is running"
exit 0
else
log_success_msg "moxi server is not running"
exit 3
fi
;;
force-reload)
if running ; then
stop
if start_checking; then
log_success_msg "moxi server was restarted"
else
exit 1
fi
else
log_success_msg "moxi server is not running"
fi
;;
*)
echo "Usage: /etc/init.d/moxi-server {start|stop|restart|status|force-reload}" >&2
exit 3
esac
__EOF
cat > opt/moxi/etc/moxi.cfg <<'__EOF'
# usr=MEMBASE_REST_USER,
# pwd=MEMBASE_REST_PSWD,
port_listen=11211,
default_bucket_name=default,
downstream_max=1024,
downstream_conn_max=4,
downstream_conn_queue_timeout=200,
downstream_timeout=5000,
wait_queue_timeout=200,
connect_max_errors=5,
connect_retry_interval=30000,
connect_timeout=400,
auth_timeout=100,
cycle=200
__EOF
cp ../moxi/moxi opt/moxi/bin/moxi.actual
cp ../libconflate/.libs/libconflate.so.0 opt/moxi/lib/libconflate.so.0
cp ../libvbucket/.libs/libvbucket.so opt/moxi/lib/libvbucket.so.1
chmod +x etc/init.d/moxi-server
chmod +x opt/moxi/bin/moxi
chmod +x opt/moxi/bin/moxi.actual
chmod +x opt/moxi/etc/moxi-init.d
cd ..
fakeroot dpkg-deb --build moxi-server_2.5.0-0eric1_x86_64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment