#! /bin/sh #------------------------------------------------------------------------------ # /etc/init.d/upseye - start/stop upseye daemon # # Copyright (c) 2006 Daniel Vogel # # Creation: 06.08.2006 dv # Last update: $Id$ # # This program 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. #---------------------------------------------------------------------------- #include eislib . /var/install/include/eislib #include config . /etc/config.d/upseye # path of the directory containig the 'upseye.pl' file SCRIPTPATH="/usr/sbin/microdowell" # perl script file to be run SCRIPTFILE="upseye.pl" # options for running perl OPTIONS="" # options for running 'upseye.pl' script PERLOPTIONS="-I /usr/sbin/microdowell " # path of the 'perl' command PERLPATH="/usr/bin/perl" # PID of the perl process to be killed PIDFILE="/usr/sbin/microdowell/thepid" # colors COLOR_RED='\033[1;31m' COLOR_NRM='\033[0;39m' # system if [ -z "${EISFAIR_SYSTEM}" ] then # get eisfair system-type . /var/install/include/check-eisfair-version fi log_end_msg () { COLUMNS=`tput cols 2>/dev/null` if [ -z "$COLUMNS" ] then COLUMNS="80" fi if [ "${EISFAIR_SYSTEM}" == "eisfair-1" ] then if [ ! "$1" -eq 0 ] then mecho -n " " mecho -error "FAILED" else echo fi else RES_COL=`expr ${COLUMNS} - 7` if [ "$1" -eq 0 ] then echo -e "\033[300C\\033[$[${COLUMNS}-${RES_COL}]D [ OK ]" else echo -e "\033[300C\\033[$[${COLUMNS}-${RES_COL}]D [${COLOR_RED}fail${COLOR_NRM}]" fi fi } show_message() { if [ "${EISFAIR_SYSTEM}" == "eisfair-1" ] then mecho -info -n "$1 ..." else echo -n " * $1" fi } log_failure_msg () { echo if [ "${EISFAIR_SYSTEM}" == "eisfair-1" ] then mecho -error -n "$1" else echo -e -n " ${COLOR_RED}*${COLOR_NRM} $1" fi } case $1 in start) show_message "starting upseye UPS daemon" if [ -f $PIDFILE ] then pid=$(cat $PIDFILE) if [ ! "$(ps ax | grep $pid | grep -v grep)" != "" ] then log_failure_msg "removing fake pid file: $PIDFILE" rm $PIDFILE else log_failure_msg "upseye UPS daemon is already running!" log_end_msg 1 exit 1 fi fi $PERLPATH $PERLOPTIONS $SCRIPTPATH/$SCRIPTFILE $OPTIONS 2> /dev/null if [ $? != 0 ] then log_end_msg 1 exit 1 else log_end_msg 0 fi ;; stop) show_message "stopping upseye UPS daemon" if [ -f $PIDFILE ] then pid=$(cat $PIDFILE) if [ ! "$(ps ax | grep $pid | grep -v grep)" != "" ] then log_failure_msg "removing fake pid file: $PIDFILE" log_end_msg 1 rm $PIDFILE exit 1 else kill -9 $pid rm $PIDFILE log_end_msg 0 fi else log_end_msg 1 exit 1 fi ;; status) if [ -f "$PIDFILE" ] then pid=$(cat $PIDFILE) if [ ! "$(ps ax | grep $pid | grep -v grep)" = "" ] then mecho -info "upseye UPS daemon is running!" else mecho -error "There is a fake pid file in /var/run" mecho -info "upseye UPS daemon is not running!" exit 1 fi else mecho -info "upseye UPS daemon is not running!" exit 1 fi ;; restart) /etc/init.d/upseye stop /etc/init.d/upseye start ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac exit 0