diff --git a/cmake/rpm_post_install.sh b/cmake/rpm_post_install.sh new file mode 100644 index 0000000000000000000000000000000000000000..2d4c320ee1207e427763edd9d1a17b68d5c9abeb --- /dev/null +++ b/cmake/rpm_post_install.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +echo "Creating a user and a group" +groupadd tarantool +useradd -r -g tarantool tarantool + +echo "Performing a single instance setup" +/usr/local/bin/tarantool_expand.sh --yes 1 diff --git a/cmake/tarantool_cpack.cmake b/cmake/tarantool_cpack.cmake index eb045821a9589334f549c74da521a889b48e538c..b7ff041bbab89c17ea2d8f99655c2f54955e4875 100644 --- a/cmake/tarantool_cpack.cmake +++ b/cmake/tarantool_cpack.cmake @@ -11,6 +11,7 @@ if ("${CPACK_GENERATOR}" STREQUAL "RPM") set (CPACK_RPM_PACKAGE_LICENSE "BSD") set (CPACK_RPM_PACKAGE_GROUP "MAIL.RU") set (CPACK_RPM_PACKAGE_DESCRIPTION "Tarantool in-memory DB storage") + set (CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/cmake/rpm_post_install.sh") set (CPACK_SET_DESTDIR "ON") set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") else() diff --git a/extra/CMakeLists.txt b/extra/CMakeLists.txt index 4501e13c6f466d74632f2310ace32aa644b0754d..13c3052c0ce8a7684ce5a6c2af29a7a49702e12d 100644 --- a/extra/CMakeLists.txt +++ b/extra/CMakeLists.txt @@ -2,16 +2,22 @@ # scripts for RPM package # if ("${CPACK_GENERATOR}" STREQUAL "RPM") - # chmod +x 655 - install (FILES tarantool_box DESTINATION etc/init.d - PERMISSIONS + # chmod +x 655 + install (FILES tarantool DESTINATION /etc/init.d + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - # chmod +x 755 - install (FILES tarantool_box.sh DESTINATION bin + # chmod +x 755 + install (FILES tarantool_multi.sh DESTINATION bin + PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE) + # chmod +x 755 + install (FILES tarantool_expand.sh DESTINATION bin PERMISSIONS - OWNER_READ OWNER_WRITE OWNER_EXECUTE + OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endif() diff --git a/extra/tarantool_box b/extra/tarantool similarity index 79% rename from extra/tarantool_box rename to extra/tarantool index cbbaf2608051d5f7e2de210a72e2a363a5fe6d63..192e4a7f8fd9a3404716dc1483cb6da2e48248ed 100755 --- a/extra/tarantool_box +++ b/extra/tarantool @@ -2,7 +2,7 @@ # /etc/rc.d/init.d/tarantool_box # -# chkconfig: 2345 99 99 +# chkconfig: 2345 99 99 # description: tarantool_box # processname: tarantool_box @@ -14,11 +14,17 @@ export PIDFILE="/var/${INST}/pid" export WRAP_PIDFILE="/var/${INST}/wrapper.pid" export OPTIONS="" -# We must not run immediate! -if [ "${INST}" == "tarantool_box" ] +# This script is normally invoked via a symlink. +# An own symlink is created for each instance. +# E.g., in case of 4 instances, there are symlinks +# tarantool0, tarantool1, tarantool2, tarantool3. +# If, for some reason, this script is invoked not via +# a symlink, do nothing. +# +if [ "${INST}" == "tarantool" ] then echo_failure - echo + echo exit fi @@ -32,7 +38,7 @@ start() { else echo_failure fi - echo + echo return ${RETVAL} } @@ -75,4 +81,3 @@ case "$1" in esac exit ${RETVAL} - diff --git a/extra/tarantool_expand.sh b/extra/tarantool_expand.sh new file mode 100755 index 0000000000000000000000000000000000000000..45adb282ce8e1fc86b1b3cc4cdbdca4be848760f --- /dev/null +++ b/extra/tarantool_expand.sh @@ -0,0 +1,226 @@ +#!/bin/sh + +# +# Copyright (C) 2012 Mail.RU +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +# +# Tarantool instance expansion script +# + +prompt_name=`basename $0` + +act_prompt=1 +act_status=0 +act_debug=0 +act_dry=0 +instance_current=0 + +error() { + echo "$prompt_name error: $*" 1>&2 + exit 1 +} + +log() { + echo "$prompt_name: $*" +} + +usage() { + echo "Tarantool expansion script: add more Tarantool instances." + echo "usage: tarantool_expand.sh [options] <instances>" + echo + echo " --prefix <path> installation path (/usr/local)" + echo " --prefix_etc <path> installation etc path (/etc)" + echo " --prefix_var <path> installation var path (/var)" + echo + echo " --status display deployment status" + echo " --dry don't create anything, show commands" + echo + echo " --debug show commands" + echo " --yes don't prompt" + echo " --help display this usage" + echo + exit $1 +} + +is_num_positive() { + num=$1 + [ $num -eq $num ] 2>/dev/null && [ $num -ge 0 ] 2>/dev/null || \ + return 1 +} + +rollback_instance() { + id=$1 + workdir="${prefix_var}/tarantool$id" + config="${prefix}/etc/tarantool$id.cfg" + rm -rf $workdir + rm -f $config + rm -f "${prefix}/bin/tarantool$id.sh" + rm -f "${prefix_etc}/init.d/tarantool$id" +} + +rollback() { + log ">>>> rolling back changes" + start=`expr $deploy_current + 1` + for instance in `seq $start $instance_current`; do + rollback_instance $instance + done + exit 1 +} + +try() { + cmd="$*" + [ $act_debug -gt 0 ] && log $cmd + if [ $act_dry -eq 0 ]; then + eval $cmd + if [ $? -gt 0 ]; then + rollback + fi + fi +} + +deploy_instance() { + id=$1 + workdir="${prefix_var}/tarantool$id" + config="${prefix}/etc/tarantool$id.cfg" + + log ">>>> deploying instance $id" + + # setting up work environment + try "mkdir -p $workdir/logs" + + # setting up startup snapshot + try "cp \"${prefix}/share/tarantool/00000000000000000001.snap\" $workdir" + try "chown tarantool:tarantool -R $workdir" + + # setting up configuration file + try "cp \"${prefix}/etc/tarantool.cfg\" $config" + try "echo \"work_dir = \"$workdir\"\" >> $config" + try "echo \"username = \"tarantool\"\" >> $config" + try "echo \"logger = \"cat - \>\> logs/tarantool.log\"\" >> $config" + + # setting up wrapper + try "ln -s \"${prefix}/bin/tarantool_multi.sh\" \"${prefix}/bin/tarantool$id.sh\"" + + # setting up startup script + try "ln -s \"${prefix_etc}/init.d/tarantool\" \"${prefix_etc}/init.d/tarantool$id\"" +} + +deploy() { + start=`expr $deploy_current + 1` + for instance in `seq $start $deploy_count`; do + instance_current=$instance + deploy_instance $instance + done +} + +commit() { + log ">>>> updating deploy config" + try "echo $deploy_count > $deploy_cfg" +} + +# processing command line arguments +if [ $# -eq 0 ]; then + usage 1 +fi + +deploy_count=0 +while [ $# -ge 1 ]; do + case $1 in + --yes) act_prompt=0 ; shift 1 ;; + --prefix) prefix=$2 ; shift 2 ;; + --prefix_var) prefix_var=$2 ; shift 2 ;; + --prefix_etc) prefix_etc=$2 ; shift 2 ;; + --dry) act_dry=1 ; act_debug=1 ; shift 1 ;; + --debug) act_debug=1; shift 1 ;; + --status) act_status=1 ; shift 1 ;; + --help) usage 0 ; shift 1 ;; + *) deploy_count=$1 ; shift 1 ; break ;; + esac +done + +set ${prefix:="/usr/local"} +set ${prefix_var:="/var"} +set ${prefix_etc:="/etc"} + +deploy_cfg="${prefix}/etc/tarantool_deploy.cfg" +deploy_exists=0 +deploy_current=0 + +# checking deployment configuration file +if [ -f $deploy_cfg ]; then + deploy_exists=1 + deploy_current=`cat $deploy_cfg` + [ $? -eq 0 ] || error "failed to read deploy config" + # validating instance number + is_num_positive $deploy_current + [ $? -eq 0 ] || error "bad deploy config instance number" + # dont' change deploy if it said so in configuration file + if [ $deploy_current -eq 0 ]; then + log "skipping deploy setup (cancel by config)" + exit 0 + fi +fi + +# displaying status +if [ $act_status -ne 0 ]; then + if [ $deploy_exists -eq 0 ]; then + log "no tarantool instances found." + else + log "$deploy_current tarantool instances deployed" + fi + exit 0 +fi + +# validating instance number +is_num_positive $deploy_count +[ $? -eq 0 ] && [ $deploy_count -gt 0 ] || error "bad instance number" + +if [ $deploy_count -le $deploy_current ]; then + error "expand only is supported (required instances number $deploy_count" \ + "is lower/equal than deployed $deploy_current)" +fi + +# asking permission to continue +if [ $act_prompt -eq 1 ]; then + [ $act_dry -ne 0 ] && log "(dry mode)" + log "About to extend tarantool instances from $deploy_current to $deploy_count." + log "Continue? [n/y]" + read answer + case "$answer" in + [Yy]) ;; + *) + log "aborting" + exit 0 + ;; + esac +fi + +deploy +commit + +log "done" + +# __EOF__ + diff --git a/extra/tarantool_box.sh b/extra/tarantool_multi.sh similarity index 95% rename from extra/tarantool_box.sh rename to extra/tarantool_multi.sh index c1180ed39d484d28a385d9e99820398789560012..e3948427355c5dfb338ab2fa525a714aa5f8eed0 100755 --- a/extra/tarantool_box.sh +++ b/extra/tarantool_multi.sh @@ -7,7 +7,7 @@ BINARY="/usr/local/bin/${NAME}" INST=$(basename $0 .sh) CONF="/usr/local/etc/${INST}.cfg" LOGDIR="/var/${INST}/logs" -CRONOLOG="/usr/sbin/cronolog" +WRAP_PIDFILE="/var/${INST}/wrapper.pid" exec <&- @@ -18,7 +18,6 @@ report() runtarantool() { - ulimit -n 40960 ${BINARY} ${OPTIONS} --config ${CONF} 2>&1 </dev/null & wait diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a73b0a7a6ce7f2920d39e5deb142520fcae9d7c2..e7e1fadb89454ac36f68cb6cfca8444139fda4fd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,7 +4,14 @@ add_custom_target(test add_subdirectory(box) add_subdirectory(connector_c) -install (FILES ${CMAKE_SOURCE_DIR}/test/box/tarantool.cfg - DESTINATION "${CMAKE_SYSCONF_DIR}") -install (FILES ${CMAKE_SOURCE_DIR}/test/box/00000000000000000001.snap - DESTINATION "${CMAKE_LOCALSTATE_DIR}/lib/tarantool") +if ("${CPACK_GENERATOR}" STREQUAL "RPM") + install (FILES ${CMAKE_SOURCE_DIR}/test/box/tarantool.cfg + DESTINATION etc) + install (FILES ${CMAKE_SOURCE_DIR}/test/box/00000000000000000001.snap + DESTINATION share/tarantool) +else() + install (FILES ${CMAKE_SOURCE_DIR}/test/box/tarantool.cfg + DESTINATION "${CMAKE_SYSCONF_DIR}") + install (FILES ${CMAKE_SOURCE_DIR}/test/box/00000000000000000001.snap + DESTINATION "${CMAKE_LOCALSTATE_DIR}/lib/tarantool") +endif()