Kouhei Sutou
null+****@clear*****
Mon Aug 13 17:35:17 JST 2012
Kouhei Sutou 2012-08-13 17:35:17 +0900 (Mon, 13 Aug 2012) New Revision: f3026de6a777fb440a2a50360c6fee7c15533b81 https://github.com/groonga/gcs/commit/f3026de6a777fb440a2a50360c6fee7c15533b81 Log: apt: add gcs service but it's not tested #80 Because gcs command doesn't have both --daemon and --pid-file option. Added files: packages/debian/gcs.default packages/debian/gcs.dirs packages/debian/gcs.init packages/debian/gcs.postinst packages/debian/gcs.postrm Added: packages/debian/gcs.default (+7 -0) 100644 =================================================================== --- /dev/null +++ packages/debian/gcs.default 2012-08-13 17:35:17 +0900 (3a4e7f5) @@ -0,0 +1,7 @@ +# Default +#USER=gcs +#GROUP=gcs +#PORT=7575 + +# Comment out this to disable Groonga CloudSearch daemon. +ENABLE=yes Added: packages/debian/gcs.dirs (+2 -0) 100644 =================================================================== --- /dev/null +++ packages/debian/gcs.dirs 2012-08-13 17:35:17 +0900 (4b3230a) @@ -0,0 +1,2 @@ +var/lib/gcs +var/run/gcs Added: packages/debian/gcs.init (+187 -0) 100755 =================================================================== --- /dev/null +++ packages/debian/gcs.init 2012-08-13 17:35:17 +0900 (b6bba48) @@ -0,0 +1,187 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: gcs +# Required-Start: $remote_fs $network +# Required-Stop: $remote_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Groonga CloudSearch's init script +# Description: Groonga CloudSearch is an Amazon CloudSearch compatible +# open source full text search server +### END INIT INFO + +# Author: Kouhei Sutou <kou �� clear-code.com> + +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="an Amazon CloudSearch compatible open source full text search server" +NAME=gcs +DAEMON=/usr/sbin/$NAME +USER=gcs +GROUP=gcs +PORT=7575 +PIDFILE=/var/run/gcs/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME +OPTION_ARGS="" +START_STOP_DAEMON_ARGS="" +ENABLE="no" + +DEFAULT_FILE=/etc/default/gcs + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Read configuration variable file if it is present +[ -r $DEFAEULT_FILE ] && . $DEFAULT_FILE + +[ "$ENABLE" = "yes" ] || exit 0 + +DAEMON_ARGS="--daemon --pid-file ${PIDFILE}" +if [ -n "${PORT}" ]; then + DAEMON_ARGS="${DAEMON_ARGS} --port ${PORT}" +fi + +mkdir -p $(dirname ${PIDFILE}) +if [ -n "${USER}" ]; then + if ! getent passwd | grep -q "^${USER}:"; then + echo "$0: user for running Groonga CloudSearch doesn't exist: ${USER}" >&2 + exit 1 + fi + chown -R ${USER} $(dirname ${PIDFILE}) + START_STOP_DAEMON_ARGS="${START_STOP_DAEMON_ARGS} --user ${USER}" +fi +if [ -n "${GROUP}" ]; then + if ! getent group | grep -q "^${GROUP}:"; then + echo "$0: group for running Groonga CloudSearch doesn't exist: ${GROUP}" >&2 + exit 1 + fi + START_STOP_DAEMON_ARGS="${START_STOP_DAEMON_ARGS} --group ${GROUP}" +fi +DAEMON_ARGS="${DAEMON_ARGS} ${OPTION_ARGS}" + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ + ${START_STOP_DAEMON_ARGS} --test > /dev/null || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ + ${START_STOP_DAEMON_ARGS} -- $DAEMON_ARGS || return 2 + # Add code here, if necessary, that waits for the process to be ready + # to handle requests from services started subsequently which depend + # on this one. As a last resort, sleep for some time. +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \ + --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + +do_status() { + if [ -z "${ADDRESS}" ]; then + ADDRESS="localhost" + fi + send_command status + return $? +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + reload|force-reload) + log_daemon_msg "Reloading $DESC" "$NAME" + do_reload + log_end_msg $? + ;; + restart) + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2 + exit 3 + ;; +esac + +: Added: packages/debian/gcs.postinst (+34 -0) 100755 =================================================================== --- /dev/null +++ packages/debian/gcs.postinst 2012-08-13 17:35:17 +0900 (f07bac9) @@ -0,0 +1,34 @@ +#! /bin/sh + +set -e + +prevver="$2" + +add_system_user() { + if ! getent passwd gcs >/dev/null; then + adduser --group --system --home /var/lib/gcs gcs + fi +} + +fixperms() { + dpkg-statoverride --list /var/run/gcs >/dev/null || \ + dpkg-statoverride --update --add gcs gcs 0755 /var/run/gcs + dpkg-statoverride --list /var/lib/gcs >/dev/null || \ + dpkg-statoverride --update --add gcs gcs 0755 /var/lib/gcs +} + +case "$1" in + configure) + add_system_user + fixperms + ;; + abort-upgrade|abort-deconfigure|abort-remove) + : + ;; + *) + echo "Called with unknown argument $1, bailing out." + exit 1 + ;; +esac + +#DEBHELPER# Added: packages/debian/gcs.postrm (+16 -0) 100755 =================================================================== --- /dev/null +++ packages/debian/gcs.postrm 2012-08-13 17:35:17 +0900 (62c3df8) @@ -0,0 +1,16 @@ +#! /bin/sh + +set -e + +if [ "$1" = "purge" ]; then + rm -f /var/run/gcs/* + dpkg-statoverride --remove /var/run/gcs + rm -rf /var/lib/gcs/* + dpkg-statoverride --remove /var/lib/gcs + + if getent passwd gcs >/dev/null; then + deluser --system --remove-all-files gcs + fi +fi + +#DEBHELPER# -------------- next part -------------- HTML����������������������������...Download