#!/usr/bin/env bash # # RebuildQueue daemon control # AUTHOR: Jay Allen, Endevver Consulting, http://www.jayallen.org # $Id$ RQ=plugins/RebuildQueue/RebuildQueue man() { cat <1 An error occurred. DISCLAIMER The author of this utility will be held no responsibility for any damages and losses of data and/or files that may be caused by the use thereof. Use me at your own risk! AUTHOR Jay Allen, Endevver Consulting, http://jayallen.org COPYRIGHT Copyright 2008, Jay Allen This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. EOU exit 0 } usage() { [[ -n "$1" ]] && local error=-1 && echo "Error: $1" cat <>> $1"; shift; done } parse_options() { [[ -z "$1" ]] && usage while [[ "$1" =~ ^(-|start|stop|restart|test|help) ]]; do case "${1//-/}" in m | mt ) MT_HOME=$2; shift;; l | log ) RQLOG=$2; shift;; w | workers ) RQWORKERS=$2; shift;; v | verbose ) VERBOSE=1;; help ) man;; test ) TEST=1;; start ) START=1;; restart ) START=1;STOP=1;; stop ) STOP=1;; *) usage "Unknown option: $1";; esac shift done [ "$MT_HOME" ] || usage "MT home directory not specified" [ -d "$MT_HOME" ] || usage "$MT_HOME not found or is not a directory" [ -e "$MT_HOME/$RQ.pl" ] || usage "$MT_HOME/$RQ.pl not found" [[ "${RQLOG:=/dev/null}" =~ ^/ ]] || RQLOG="$MT_HOME/$RQLOG" RQWORKERS=${RQWORKERS:-1} export MT_HOME=${MT_HOME%%/} } show_config() { echo "Using the following values:" for I in MT_HOME RQLOG RQWORKERS STOP START TEST VERBOSE; do printf " %-10s %s\n" "$I:" "${!I}" done } stop() { if [[ $(ps ax 2>/dev/null) ]]; then psoptions="ax" # BSD systems else psoptions="-ef" # Other systems fi PSOUT="$(ps $psoptions | grep $MT_HOME/$RQ.pl | grep -v grep )" if [ "$PSOUT" ]; then PIDS=$(echo "$PSOUT" | awk {'print $1'} | xargs ) progress "RebuildQueue processes to kill:" echo "$PSOUT" dispatch "kill -INT $PIDS" else progress "No RebuildQueue processes exist" fi } start() { progress "Starting $RQWORKERS RebuildQueue daemon processes" while [[ $RQWORKERS -gt 0 ]]; do dispatch "MT_HOME='$MT_HOME' nohup nice -n 15 $MT_HOME/$RQ.pl --daemonize --worker $RQWORKERS >> $RQLOG 2>&1 &" RQWORKERS=$(($RQWORKERS-1)) done } parse_options "$@" [ $TEST ] && show_config [[ -n "$STOP" || -n "$TEST" ]] && stop [[ -n "$START" || -n "$TEST" ]] && start progress "Done." exit 0