#!/bin/sh - # vi:ts=3:ai ####################################################################### # This script controls services that are not registered as system # services which respond to calls from /sbin/chkconfig or # /sbin/services. # # USAGE: # service-control service action # Where: # service is any named service listed in KNOWN_SERVICES below, and # for which you have coded the actions in main() below. # action is any of those listed in KNOWN_ACTIONS below, and for which # code has been written in main() below. # # EXAMPLES: # service-control popauth restart # service-control popauth status # # Script Version: # 1.0 # Original Author: # William Kimball, Jr. # History: # 17 FEB 2006 : # Originated this source file. ####################################################################### ####################################################################### # OPTIONS #---------------------------------------------------------------------# # This set of _PATH options specify the absolute paths to some programs # which this script relies on. The recommended values come from # RHEL4/CentOS4 systems and may not fit your site's configuration. # While is is possible, and generally okay, to specify only a program # name without any pathing information, these options help in cases # where this script runs in an automated context (cron, at, etc.) # without an appropriate $PATH environment variable. # Power User Note: If you put these values in quotes, then you can # also specify additional options to these commands, which will precede # the arguments passed by this script. Doing this isn't recommended as # you will alter the expected behavior of this script beyond the intent # of its author, but the possibility is available to you. # # Recommended values: # ECHO_PATH=/bin/echo # PRINTF_PATH=/usr/bin/printf # TR_PATH=/usr/bin/tr # CAT_PATH=/bin/cat # SLEEP_PATH=/bin/sleep # KILL_PATH=/bin/kill #---------------------------------------------------------------------# ECHO_PATH=/bin/echo PRINTF_PATH=/usr/bin/printf TR_PATH=/usr/bin/tr CAT_PATH=/bin/cat SLEEP_PATH=/bin/sleep KILL_PATH=/bin/kill # END OPTIONS ####################################################################### # Initialize global variables. KNOWN_SERVICES="popauth pure-ftpd" KNOWN_ACTIONS="stop start restart status" # Lock the user preferences and script globals as constants. readonly KNOWN_SERVICES KNOWN_ACTIONS readonly ECHO_PATH PRINTF_PATH TR_PATH CAT_PATH SLEEP_PATH KILL_PATH ####################################################################### # Function: showerror # Purpose: Sends an error message to the stderr output. # Receives: # $1: The quoted error message. # Returns: # Sends text to the stderr output pipe. # Example: # showerror "Some error!" # Function Version: # 1.0 # History: # 10 FEB 2006 : # Originated this function. ####################################################################### showerror() { $ECHO_PATH Error from $0: $1 1>&2 } ####################################################################### # end showerror() ####################################################################### ####################################################################### # Function: main (implied) # Purpose: This serves as the main insertion point for script # execution. # Receives: # $1: Service name to act upon. # $2: Action to perform upon the indicated service. # Returns: # Standard Unix error codes (0 = success, else failure) # History: # 17 FEB 2006 : # Originated this function. ####################################################################### # Initialize local variables. service_name=$(echo ${1:-all} | tr A-Z a-z) action_phrase=$(echo ${2:-status} | tr A-Z a-z) exit_state=0 # Restart is a recursive call; preempt the service name check. if [ "restart" == $action_phrase ]; then $0 $service_name stop if ! $0 $service_name start; then exit_state=1 fi else # Take action on the selected service (or all). case $service_name in popauth) case $action_phrase in start) if [ ! -e /var/run/popauth.pid ]; then $PRINTF_PATH "Starting popauth: " /usr/local/sbin/popauth & $SLEEP_PATH 2 if [ -e /var/run/popauth.pid ]; then $PRINTF_PATH "[ OK ]\n" else $PRINTF_PATH "[FAILED]\n" exit_state=1 fi else $ECHO_PATH "popauth ($($CAT_PATH /var/run/popauth.pid)) is running already..." fi ;; stop) if [ -e /var/run/popauth.pid ]; then $PRINTF_PATH "Stopping popauth: " $KILL_PATH -HUP $($CAT_PATH /var/run/popauth.pid) $SLEEP_PATH 2 if [ ! -e /var/run/popauth.pid ]; then $PRINTF_PATH "[ OK ]\n" else $PRINTF_PATH "[FAILED]\n" exit_state=1 fi else $ECHO_PATH "popauth already is stopped." fi ;; status) if [ -e /var/run/popauth.pid ]; then $ECHO_PATH "popauth ($($CAT_PATH /var/run/popauth.pid)) is running..." else $ECHO_PATH "popauth is stopped." fi ;; *) showerror "Unknown action, $action_phrase, attempted on service, $service_name." exit_state=1 esac ;; pure-ftpd) case $action_phrase in start) if [ ! -e /var/run/pure-ftpd.pid ]; then $PRINTF_PATH "Starting pure-ftpd: " /usr/sbin/pure-ftpd -l mysql:/etc/pureftp/pure-mysql.conf & $SLEEP_PATH 2 if [ -e /var/run/pure-ftpd.pid ]; then $PRINTF_PATH "[ OK ]\n" else $PRINTF_PATH "[FAILED]\n" exit_state=1 fi else $ECHO_PATH "pure-ftpd ($($CAT_PATH /var/run/pure-ftpd.pid)) is running already..." fi ;; stop) if [ -e /var/run/pure-ftpd.pid ]; then $PRINTF_PATH "Stopping pure-ftpd: " $KILL_PATH -HUP $($CAT_PATH /var/run/pure-ftpd.pid) $SLEEP_PATH 2 if [ ! -e /var/run/pure-ftpd.pid ]; then $PRINTF_PATH "[ OK ]\n" else $PRINTF_PATH "[FAILED]\n" exit_state=1 fi else $ECHO_PATH "pure-ftpd already is stopped." fi ;; status) if [ -e /var/run/pure-ftpd.pid ]; then $ECHO_PATH "pure-ftpd ($($CAT_PATH /var/run/pure-ftpd.pid)) is running..." else $ECHO_PATH "pure-ftpd is stopped." fi ;; *) showerror "Unknown action, $action_phrase, attempted on service, $service_name." exit_state=1 esac ;; all) for recurse_service in $KNOWN_SERVICES; do $0 $recurse_service $action_phrase done ;; *) showerror "Unknown service, $service_name." exit_state=1 esac fi # Exit, reporting success/fail. exit $exit_state ####################################################################### # end main() (implied) #######################################################################