106 lines
2.4 KiB
Bash
106 lines
2.4 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
# LSB 2.0 Init script Functions
|
||
|
# <http://www.linuxbase.org/spec/book/LSB-generic/LSB-generic/iniscrptfunc.html>
|
||
|
# Copyright (c) 2005-2007,2011 by Davide Madrisan <davide.madrisan@gmail.com>
|
||
|
|
||
|
. /etc/sysconfig/rc
|
||
|
. $rc_functions
|
||
|
|
||
|
# function:
|
||
|
# start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...]]
|
||
|
# description:
|
||
|
# runs the specified program as a daemon.
|
||
|
# The start_daemon function shall check if the program is already running
|
||
|
# using the algorithm given above. If so, it shall not start another copy of
|
||
|
# the daemon unless the -f option is given.
|
||
|
# The -n option specifies a nice level. See nice.
|
||
|
# return value:
|
||
|
# It shall return 0 if the program has been successfully started or is
|
||
|
# running and not 0 otherwise.
|
||
|
|
||
|
start_daemon () {
|
||
|
TEMP=`LANG=C POSIXLY_CORRECT=1 getopt "fn:p:" $*`
|
||
|
if [ $? -ne 0 -o $# -eq 0 ]; then
|
||
|
echo "Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname"
|
||
|
return 1
|
||
|
fi
|
||
|
|
||
|
local nice= force= pidfile=
|
||
|
eval set -- "$TEMP"
|
||
|
while :; do
|
||
|
case $1 in
|
||
|
-f) force="--force" ;;
|
||
|
-n) nice=$2; shift ;;
|
||
|
-p) pidfile="--pidfile=$2"; shift ;;
|
||
|
--) shift; break ;;
|
||
|
*) echo "Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname"
|
||
|
return 1 ;;
|
||
|
esac
|
||
|
shift
|
||
|
done
|
||
|
|
||
|
LSB=LSB-2.0 daemon ${force:-} ${nice:-} $*
|
||
|
return $?
|
||
|
}
|
||
|
|
||
|
# function:
|
||
|
# killproc [-p pidfile] pathname [signal]
|
||
|
#
|
||
|
# ( implemented in /etc/init.d/functions )
|
||
|
|
||
|
# function:
|
||
|
# pidofproc [-p pidfile] pathname
|
||
|
#
|
||
|
# ( implemented in /etc/init.d/functions )
|
||
|
|
||
|
log_msg () {
|
||
|
action=$1
|
||
|
shift
|
||
|
case "$action" in
|
||
|
success)
|
||
|
echo -n $*
|
||
|
success "$*"
|
||
|
echo
|
||
|
;;
|
||
|
failure)
|
||
|
echo -n $*
|
||
|
failure "$*"
|
||
|
echo
|
||
|
;;
|
||
|
warning)
|
||
|
echo -n $*
|
||
|
warning "$*"
|
||
|
echo
|
||
|
;;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
# function:
|
||
|
# log_success_msg message
|
||
|
# description:
|
||
|
# The log_success_msg function shall cause the system to print a success message.
|
||
|
|
||
|
log_success_msg () {
|
||
|
log_msg success $*
|
||
|
}
|
||
|
|
||
|
# function:
|
||
|
# log_failure_msg message
|
||
|
# description:
|
||
|
# The log_failure_msg function shall cause the system to print a failure message.
|
||
|
|
||
|
log_failure_msg () {
|
||
|
log_msg failure $*
|
||
|
}
|
||
|
|
||
|
# function:
|
||
|
# log_warning_msg message
|
||
|
# description:
|
||
|
# The log_warning_msg function shall cause the system to print a warning message.
|
||
|
|
||
|
log_warning_msg () {
|
||
|
log_msg warning $*
|
||
|
}
|
||
|
|