#!/sbin/runscript # Copyright 1999-2012 Pavel Stratil, senbonzakura.eu # Some functions were taken from debian init script. Licensed under GPL-2 # Distributed under the terms of the GNU General Public License v2 # $Id$ ######################### ### Construct vars ###### ######################### SUFFIX=".${SVCNAME#*.}" [ "${SUFFIX}" == ".drizzled" ] && SUFFIX='' DIR_PID="/run/drizzle" DIR_LOG="/var/log/drizzle" BASE_CNF="/etc/drizzle/drizzled" BASE_PID="${DIR_PID}/drizzled" BASE_LOG="${DIR_LOG}/drizzled" BASE_DIR="/var/lib/drizzle/drizzled" CNFFILE="${BASE_CNF}${SUFFIX}.cnf" LOGFILE="${BASE_LOG}${SUFFIX}.log" DATADIR="${BASE_DIR}${SUFFIX}" DRIZZLE="/usr/bin/drizzle" DRIZZLE_USER="drizzle" pidfile="${BASE_PID}${SUFFIX}.pid" command="/usr/sbin/drizzled" command_args="--daemon --datadir=${DATADIR} --pid-file=${pidfile} --user=${DRIZZLE_USER} --syslog.errmsg-enable ${DRIZZLE_EXTRA}" start_stop_daemon_args="--user ${DRIZZLE_USER} --wait 5000" ######################### ### Helper functions #### ######################### # # drizzle_status() checks if there is a server running and if it is accessible. # "check_alive" insists on a pingable server, "check_dead" also fails # if there is a lost drizzled in the process list # Usage: boolean drizzle_status [check_alive|check_dead] [warn|nowarn] # drizzle_status() { ping_output=`$DRIZZLE --ping 2>&1`; ping_alive=$(( ! $? )) ps_alive=0 if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi if [ "$1" = "check_alive" -a $ping_alive = 1 ] || [ "$1" = "check_dead" -a $ping_alive = 0 -a $ps_alive = 0 ]; then return 0 # EXIT_SUCCESS else if [ "$2" = "warn" ]; then echo -e "$ps_alive processes alive and '$DRIZZLE --ping' resulted in\n$ping_output\n" fi return 1 # EXIT_FAILURE fi } ######################### ### Main ################ ######################### checkconfig() { # TODO: --print-defaults no longer a valid option. Needs to be rewritten. #CNFDATADIR=`drizzle_get_param datadir` #if [ -z "${CNFDATADIR}" ] ; then # ewarn "Datadir not set in ${CNFFILE}." # ewarn "Trying to use ${DATADIR}" #else DATADIR="${CNFDATADIR}" #fi if [[ ! -d "${DATADIR}" ]] ; then eerror "Drizzle datadir is empty or invalid." eerror "Please check your configuration ${CNFFILE} and DRIZZLE_EXTRA" return 1 fi if [ ! -f "${CNFFILE}" ]; then eerror "The configuration file $CNFFILE was not found!" fi } depend() { use localmount use logger use gearmand use memcached # TODO use drizzle_get_param() to decide if gearmand and memcached # are needed. Then the useflag based sed-ing of this script # can be removed from the ebuild. } start_pre() { checkpath -d -o ${DRIZZLE_USER}:nogroup ${DIR_PID} ${DIR_LOG} checkpath -f -o ${DRIZZLE_USER}:nogroup ${LOGFILE} } start_post() { for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do sleep 1 if drizzle_status check_alive nowarn ; then break ; fi done if drizzle_status check_alive warn ; then einfo "${SVCNAME} is alive!" else eerror "${SVCNAME} died!" fi } stop_post() { drizzle_status check_dead warn } status() { if drizzle_status check_alive nowarn; then mark_service_started drizzled einfo "status: started" else mark_service_stopped drizzled einfo "status: stopped" fi }