2 # Copyright 1999-2011 Pavel Stratil, senbonzakura.eu
3 # Some functions were taken from debian init script. Licensed under GPL-2
4 # Distributed under the terms of the GNU General Public License v2
7 #########################
8 ### Construct vars ######
9 #########################
12 SUFFIX=".${SVCNAME#*.}"
13 [ "${SUFFIX}" == ".drizzled" ] && SUFFIX=''
15 BASE_CNF="/etc/drizzle/drizzled"
16 BASE_PID="/var/run/drizzle/drizzled"
17 BASE_LOG="/var/log/drizzle/drizzled"
18 BASE_DIR="/var/lib/drizzle/drizzled"
20 PIDFILE="${BASE_PID}${SUFFIX}.pid"
21 CNFFILE="${BASE_CNF}${SUFFIX}.cnf"
22 LOGFILE="${BASE_LOG}${SUFFIX}.log"
23 DATADIR="${BASE_DIR}${SUFFIX}"
24 DRIZZLE="/usr/bin/drizzle"
25 DRIZZLE_USER="drizzle"
26 DRIZZLE_DAEMON="/usr/sbin/drizzled"
29 #########################
30 ### Helper functions ####
31 #########################
35 # drizzle_status() checks if there is a server running and if it is accessible.
36 # "check_alive" insists on a pingable server, "check_dead" also fails
37 # if there is a lost drizzled in the process list
38 # Usage: boolean drizzle_status [check_alive|check_dead] [warn|nowarn]
41 ping_output=`$DRIZZLE --ping 2>&1`; ping_alive=$(( ! $? ))
43 if [ -f "$PIDFILE" ] && ps `cat $PIDFILE` >/dev/null 2>&1; then ps_alive=1; fi
45 if [ "$1" = "check_alive" -a $ping_alive = 1 ] ||
46 [ "$1" = "check_dead" -a $ping_alive = 0 -a $ps_alive = 0 ]; then
47 return 0 # EXIT_SUCCESS
49 if [ "$2" = "warn" ]; then
50 echo -e "$ps_alive processes alive and '$DRIZZLE --ping' resulted in\n$ping_output\n"
52 return 1 # EXIT_FAILURE
56 #########################
57 ### Main ################
58 #########################
61 # TODO: --print-defaults no longer a valid option. Needs to be rewritten.
62 #CNFDATADIR=`drizzle_get_param datadir`
63 #if [ -z "${CNFDATADIR}" ] ; then
64 # ewarn "Datadir not set in ${CNFFILE}."
65 # ewarn "Trying to use ${DATADIR}"
67 DATADIR="${CNFDATADIR}"
70 if [[ ! -d "${DATADIR}" ]] ; then
71 eerror "Drizzle datadir is empty or invalid."
72 eerror "Please check your configuration ${CNFFILE} and DRIZZLE_EXTRA"
76 if [ ! -f "${CNFFILE}" ]; then
77 eerror "The configuration file $CNFFILE was not found!"
86 # TODO use drizzle_get_param() to decide if gearmand and memcached
87 # are needed. Then the useflag based sed-ing of this script
88 # can be removed from the ebuild.
93 ebegin "Stopping ${SVCNAME}"
94 start-stop-daemon --pidfile ${PIDFILE} --stop \
95 --exec ${DRIZZLE_DAEMON}
97 drizzle_status check_dead warn
102 ebegin "Starting ${SVCNAME}"
103 # Test if ${BASE_PID}, ${BASE_LOG} and ${LOG_FILE} exist, create if not.
104 [ ! -e ${BASE_PID} ] && mkdir -p ${BASE_PID} && chown ${DRIZZLE_USER}:nogroup ${BASE_PID}
105 [ ! -e ${BASE_LOG} ] && mkdir -p ${BASE_LOG} && chown ${DRIZZLE_USER}:nogroup ${BASE_LOG}
106 [ ! -e ${LOGFILE} ] && touch ${LOGFILE} && chown ${DRIZZLE_USER}:nogroup ${LOGFILE}
107 start-stop-daemon --background --pidfile ${PIDFILE} --stderr ${LOGFILE} \
108 --user ${DRIZZLE_USER} --start --exec ${DRIZZLE_DAEMON} -- \
109 --datadir=${DATADIR} --pid-file=${PIDFILE} --user=${DRIZZLE_USER} \
113 # TODO in order to have replication always working we should add the
114 # --server-id=# option. AFAIK only integers are allowed, though
115 # ${HOSTNAME}${SVCNAME}${SUFFIX} whould be much easier to handle.
117 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
119 if drizzle_status check_alive nowarn ; then break ; fi
121 if drizzle_status check_alive warn ; then
122 einfo "${SVCNAME} is alive!"
124 eerror "${SVCNAME} died!"
129 if drizzle_status check_alive nowarn; then
130 einfo "status: started"
132 einfo "status: stopped"