#!/bin/sh # # Copyright (c) 2004-2007 - Consultas, PKG.fr # # This file is part of A2P. # # A2P is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # A2P is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with A2P; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # $Id: a2p-stat.sh 3 2007-10-18 16:20:19Z g $ # # a2p-stat: This is the init script for starting up a2p-stat.pl # # chkconfig: 345 99 10 # description: Starts and stops a2p-stat daemon # that handles job statistics # processname: a2p-stat # pidfile: /var/run/a2p-stat.pid # Source function library. . /etc/init.d/functions # See how we were called. # Strip service name from Sxx/Kxx if started during boot or during shutdown prog="`basename $0|sed -re 's/^S[0-9]{2}//' -e 's/^K[0-9]{2}//'`" pid="`pidof $prog`" # Delete PID file if service is not running [ -z "$pid" -a -s /var/run/$prog.pid ] && rm -f /var/run/$prog.pid # Optional conf integration if [ -n "$prog" -a -e "/etc/afp2print/${prog}.conf" ]; then . "/etc/afp2print/${prog}.conf" fi [ -z "$LOCKID" ] && LOCKID="`hostname -s|tr 'a-z' 'A-Z'`" export LOCKID # Perl library path options to help service to found its needed modules PERLOPT="" [ -d "$AFP2PRINT_PATH/A2P" ] && PERLOPT="$PERLOPT -I$AFP2PRINT_PATH" # Prepare Perl binary environment # Also unset JAVA_HOME in case it is in our ENV as it should exist only during # launch by Eclipse IDE, we need a LOCKID to ask process to load its conf PERLENV="unset JAVA_HOME ; LANG=C LOCKID=\"$LOCKID\"" # These defaults can be overided in confs : ${AFP2PRINT_USER:=afp2print} : ${SERVICE_PROG:=$AFP2PRINT_PATH/a2p-stat.pl} : ${SERVICE_DEBUG:=0} : ${PERL:=/usr/bin/perl} : ${NICE:=nice -19} : ${LOGFILENAME:=/var/log/a2p.debug} start() { # For SELinux we need to use 'runuser' not 'su' SU=su if [ -s /etc/redhat-release ]; then if ! fgrep -q "Red Hat Enterprise Linux ES release 3" /etc/redhat-release; then [ -x /sbin/runuser ] && SU=runuser fi fi echo -n "Starting $prog: " if [ -e /var/lock/subsys/$prog ]; then if [ -s /var/run/$prog.pid ] && [ -e /proc/`< /var/run/$prog.pid` ]; then echo -n "cannot start $prog: $prog is already running."; failure "cannot start $prog: $prog already running."; echo return 1 fi fi # Prepare pid file touch /var/run/${prog}.pid chown $AFP2PRINT_USER /var/run/${prog}.pid chmod 664 /var/run/${prog}.pid # Check user will be able to output in LOGFILENAME if (( DEBUG_IN_FILE > 0 || LOGFILE_VS_SYSLOG > 0 )); then touch $LOGFILENAME chown $AFP2PRINT_USER $LOGFILENAME chmod 664 $LOGFILENAME fi # Touch the service debug file in case we need to keep some information # Usefull when debugging Perl compilation problems if (( SERVICE_DEBUG > 0 )); then touch /var/run/${prog}.debug chown $AFP2PRINT_USER /var/run/${prog}.debug if [ "$1" == "debug" ]; then PERLOPT="$PERLOPT -dt" echo -n "" >/var/run/${prog}.trace chown $AFP2PRINT_USER /var/run/${prog}.trace chmod 664 /var/run/${prog}.trace PERLENV="$PERLENV PERLDB_OPTS=\"NonStop=1 LineInfo=/var/run/${prog}.trace frame=4 dieLevel=2\"" fi else rm -f /var/run/$prog.debug fi # Start service $NICE $SU - $AFP2PRINT_USER -c "$PERLENV $PERL $PERLOPT $SERVICE_PROG /var/run/$prog.pid" RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog && success $prog; echo while [ ! -s /var/run/$prog.pid -a $RETVAL -eq 0 ] do usleep 100000 done if [ -n "$1" -a -x "/usr/bin/$1" -a -s /var/run/$prog.pid ]; then pid=`