2 # Copyright 1999-2012 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 DIR_PID="/run/drizzle"
16 DIR_LOG="/var/log/drizzle"
18 BASE_CNF="/etc/drizzle/drizzled"
19 BASE_PID="${DIR_PID}/drizzled"
20 BASE_LOG="${DIR_LOG}/drizzled"
21 BASE_DIR="/var/lib/drizzle/drizzled"
23 CNFFILE="${BASE_CNF}${SUFFIX}.cnf"
24 LOGFILE="${BASE_LOG}${SUFFIX}.log"
25 DATADIR="${BASE_DIR}${SUFFIX}"
26 DRIZZLE="/usr/bin/drizzle"
27 DRIZZLE_USER="drizzle"
29 pidfile="${BASE_PID}${SUFFIX}.pid"
30 command="/usr/sbin/drizzled"
31 command_args="--daemon --datadir=${DATADIR} --pid-file=${pidfile} --user=${DRIZZLE_USER} --syslog.errmsg-enable ${DRIZZLE_EXTRA}"
33 start_stop_daemon_args="--user ${DRIZZLE_USER} --wait 5000"
35 #########################
36 ### Helper functions ####
37 #########################
41 # drizzle_status() checks if there is a server running and if it is accessible.
42 # "check_alive" insists on a pingable server, "check_dead" also fails
43 # if there is a lost drizzled in the process list
44 # Usage: boolean drizzle_status [check_alive|check_dead] [warn|nowarn]
47 ping_output=`$DRIZZLE --ping 2>&1`; ping_alive=$(( ! $? ))
49 if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
51 if [ "$1" = "check_alive" -a $ping_alive = 1 ] ||
52 [ "$1" = "check_dead" -a $ping_alive = 0 -a $ps_alive = 0 ]; then
53 return 0 # EXIT_SUCCESS
55 if [ "$2" = "warn" ]; then
56 echo -e "$ps_alive processes alive and '$DRIZZLE --ping' resulted in\n$ping_output\n"
58 return 1 # EXIT_FAILURE
62 #########################
63 ### Main ################
64 #########################
67 # TODO: --print-defaults no longer a valid option. Needs to be rewritten.
68 #CNFDATADIR=`drizzle_get_param datadir`
69 #if [ -z "${CNFDATADIR}" ] ; then
70 # ewarn "Datadir not set in ${CNFFILE}."
71 # ewarn "Trying to use ${DATADIR}"
73 DATADIR="${CNFDATADIR}"
76 if [[ ! -d "${DATADIR}" ]] ; then
77 eerror "Drizzle datadir is empty or invalid."
78 eerror "Please check your configuration ${CNFFILE} and DRIZZLE_EXTRA"
82 if [ ! -f "${CNFFILE}" ]; then
83 eerror "The configuration file $CNFFILE was not found!"
93 # TODO use drizzle_get_param() to decide if gearmand and memcached
94 # are needed. Then the useflag based sed-ing of this script
95 # can be removed from the ebuild.
99 checkpath -d -o ${DRIZZLE_USER}:nogroup ${DIR_PID} ${DIR_LOG}
100 checkpath -f -o ${DRIZZLE_USER}:nogroup ${LOGFILE}
104 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
106 if drizzle_status check_alive nowarn ; then break ; fi
108 if drizzle_status check_alive warn ; then
109 einfo "${SVCNAME} is alive!"
111 eerror "${SVCNAME} died!"
116 drizzle_status check_dead warn
120 if drizzle_status check_alive nowarn; then
121 mark_service_started drizzled
122 einfo "status: started"
124 mark_service_stopped drizzled
125 einfo "status: stopped"