opt
/
kaspersky
/
kav4fs
/
lib
➕ New
📤 Upload
✎ Editing:
rcfunctions.sh
← Back
#!/bin/sh # kl_action <message> # kl_setrc <exit_code> # kl_reset # kl_status [-v] # kl_start_daemon [-p <pidfile>] </full/path/to/executable> [arguments for executable] # kl_killproc [-t <timeout>] [-p <pidfile>] </full/path/to/executable> [-(HUP|KILL|TERM|USR1|USR2)] # kl_checkproc [-p <pidfile>] </full/path/to/executable> # kl_exit # kl_get_value <filename> <valuename> kl_action() { local msg="$1" echo -n "$msg $KL_SERVICE_NAME " } kl_setrc() { return $1 } if [ -f /etc/SuSE-release ] ; then ############### SuSE Linux compatible functions ############### KL_OS='suse' # Check for missing binaries (stale symlinks should not happen) # Note: Special treatment of stop for LSB conformance if [ ! -x $KL_SERVICE_BIN ] ; then echo "$KL_SERVICE_BIN not installed"; [ "$1" = "stop" ] && exit 0 exit 5; fi # Check for existence of needed config file and read it if [ -n "$KL_SERVICE_CONFIG" -a ! -r "$KL_SERVICE_CONFIG" ] ; then echo "$KL_SERVICE_CONFIG not existing"; [ "$1" = "stop" ] && exit 0 exit 6 fi . /etc/rc.status # Reset status of this service rc_reset kl_reset() { rc_reset } kl_status() { # NOTE: rc_status knows that we called this init script with # "status" option and adapts its messages accordingly. rc_status $* } kl_start_daemon() { local opts='' if [ "$1" = "-p" ] ; then opts="$opts -p $2" shift 2 fi /sbin/start_daemon $opts $* return $? } kl_killproc() { local opts='' if [ "$1" = "-t" ] ; then opts="$opts -t $2" shift 2 fi local pid_opts='' if [ "$1" = "-p" ] ; then pid_opts="-p $2" shift 2 fi local DAEMON="$1" local SIGNAL="$2" if [ -n "$pid_opts" ] ; then [ -x "$DAEMON" ] || return 5 DAEMON=$(basename "$DAEMON") DAEMON=${DAEMON:0:15} /sbin/killproc $opts $pid_opts $SIGNAL $DAEMON else /sbin/killproc $opts $SIGNAL $DAEMON fi return $? } kl_checkproc() { # NOTE: kl_checkproc should returns LSB compliant values for *status* action local pid_opts="" if [ "$1" = "-p" ] ; then pid_opts="-p $2" shift 2 fi local DAEMON="$1" if [ -n "$pid_opts" ] ; then [ -x "$DAEMON" ] || return 5 DAEMON=$(basename "$DAEMON") DAEMON=${DAEMON:0:15} /sbin/checkproc $pid_opts $DAEMON else /sbin/checkproc $DAEMON fi return $? } kl_exit() { rc_exit } elif [ -f /etc/redhat-release -o -f /etc/MCBC-release -o -f /etc/redflag-release ] ; then ############### RedHat, Fedora, MCBC & Mandriva functions ############### KL_OS='redhat' [ -x $KL_SERVICE_BIN ] || exit 0 . /etc/init.d/functions KL_RC=0 KL_TODO="$1" kl_reset() { KL_RC=0 return 0 } kl_action() { local msg="$1" if [ "$KL_TODO" != 'status' ] ; then echo -n "$msg $KL_SERVICE_NAME " fi } kl_status() { KL_RC=$? test "$1" = '-v' || return $KL_RC if [ "$KL_TODO" != 'status' ] ; then [ $KL_RC -eq 0 ] && success || failure echo fi return $KL_RC } kl_start_daemon() { local opts='' if [ "$1" = "-p" ] ; then opts="$opts --pidfile $2" shift 2 fi daemon $opts $* return $? } kl_killproc() { local killopts='' local pidotps='' if [ "$1" = "-t" ] ; then killopts="$killopts -d $2" shift 2 fi if [ "$1" = "-p" ] ; then pidopts="-p $2" shift 2 fi local DAEMON="$1" local SIGNAL="$2" # return 7 according LSB if program is not running if ! kl_checkproc $pidopts $DAEMON >/dev/null ; then failure return 7 fi killproc $pidopts $killopts $DAEMON $SIGNAL return $? } kl_checkproc() { # NOTE: kl_checkproc should returns LSB compliant values for *status* action local opts='' if [ "$1" = "-p" ] ; then opts="$opts -p $2" shift 2 fi status $opts $1 return $? } kl_exit() { exit $RETVAL } elif [ -f /etc/debian_version ] ; then ############### Debian, Ubuntu functions ############### KL_OS='debian' test -f "$KL_SERVICE_BIN" || exit 0 . /lib/lsb/init-functions if [ "$(id -u)" != '0' ] ; then # log_to_console write messages to /dev/console # this is not possible when script executed with dropped privileges log_to_console () { [ "${loop:-n}" != y ] || return 0 [ "${QUIET:-no}" != yes ] || return 0 # Only output to the console when we're given /dev/null stdin=`readlink /proc/self/fd/0` [ "${stdin#/dev/null}" != "$stdin" ] || return 0 func=$1 shift loop=y $func "$@" || true } fi KL_RC=0 KL_TODO="$1" kl_reset() { KL_RC=0 return 0 } kl_action() { local msg="$1" log_daemon_msg "$msg $KL_SERVICE_TITLE" "$KL_SERVICE_NAME" } kl_status() { KL_RC=$? test "$1" = '-v' || return $KL_RC log_end_msg $KL_RC return $KL_RC } kl_start_daemon() { local opts="" if [ "$1" = "-p" ] ; then opts="$opts -p $2" shift 2 fi local DAEMON="$1" shift local service_name="$(expr substr "$KL_SERVICE_NAME" 1 15)" start-stop-daemon --start --quiet --oknodo $opts --name "$service_name" --exec "$DAEMON" -- $* return $? } kl_killproc() { local opts="" if [ "$1" = "-t" ] ; then shift opts="$opts --retry $1" shift fi if [ "$1" = "-p" ] ; then opts="$opts -p $2" shift 2 fi local DAEMON="$1" local SIGNAL="${2:--TERM}" case "$SIGNAL" in -HUP) opts="$opts --signal 1" ;; -KILL) opts="$opts --signal 9" ;; -TERM) opts="$opts --signal 15" ;; -USR1) opts="$opts --signal 10" ;; -USR2) opts="$opts --signal 12" ;; *) echo -n "Unknown signal $SIGNAL" return 1 ;; esac start-stop-daemon --stop --quiet --oknodo --exec "$DAEMON" $opts >/dev/null return $? } kl_checkproc() { # NOTE: kl_checkproc should returns LSB compliant values for *status* action local opts="" if [ "$1" = "-p" ] ; then opts="$opts -p $2" shift 2 fi local DAEMON="$1" [ -x "$DAEMON" ] || return 5 local pids="$(pidofproc $opts "$DAEMON")" if [ $? -eq 0 ] ; then [ -z "$pids" ] && return 3 return 0 fi return $? } kl_exit() { exit $KL_RC } elif [ -f /lib/lsb/init-functions ] ; then ############### LSB compatible function ############### KL_OS='lsb' KL_RC=0 [ -x $KL_SERVICE_BIN ] || exit 0 . /lib/lsb/init-functions kl_reset() { KL_RC=0 return 0 } kl_status() { KL_RC=$? test "$1" = '-v' || return $KL_RC if [ "$KL_RC" -eq 0 ] ; then log_success_msg else log_failure_msg fi return $KL_RC } kl_start_daemon() { local pidopts="" if [ "$1" = "-p" ] ; then pidopts="-p $2" shift 2 fi local DAEMON="$1" shift if kl_checkproc $pidopts $DAEMON ; then return 0 fi start_daemon $DAEMON $* return $? } kl_killproc() { local opts="" local timeout="" if [ "$1" = "-t" ] ; then timeout="$2" shift 2 fi if [ "$1" = "-p" ] ; then opts="$opts -p $2" shift 2 fi local DAEMON="$1" local SIGNAL="$2" killproc $opts $DAEMON $SIGNAL return $? } kl_checkproc() { # NOTE: kl_checkproc should returns LSB compliant values for *status* action local opts="" if [ "$1" = "-p" ] ; then opts="$opts -p $2" shift 2 fi local DAEMON="$1" [ -x "$DAEMON" ] || return 5 local pids=$(pidofproc $opts "$DAEMON") if [ $? -eq 0 ] ; then [ -z "$pids" ] && return 3 return 0 fi return $? } kl_exit() { exit $KL_RC } else ############### Simple functions for unknown OS ############### KL_OS='unknown' KL_RC=0 [ -x $KL_SERVICE_BIN ] || exit 0 kl_reset() { KL_RC=0 return 0 } kl_status() { KL_RC=$? test "$1" = '-v' || return $KL_RC if [ "$KL_RC" -eq 0 ] ; then echo "[OK]" else echo "[FAILED]" fi return $KL_RC } kl_start_daemon() { local pidopts if [ "$1" = "-p" ] ; then pidopts="$1 $2" shift 2 fi local DAEMON="$1" shift if kl_checkproc $pidopts $DAEMON ; then return 0 fi if [ -x /sbin/startproc ] ; then /sbin/startproc -q "$DAEMON" $* return $? elif [ -x /sbin/start-stop-daemon ] ; then if /sbin/start-stop-daemon --start --quiet --name "$KL_SERVICE_NAME" --exec "$DAEMON" -- $* ; then return 0 fi else if $DAEMON $* >/dev/null 2>&1 ; then return 0 fi fi return 1 } kl_killproc() { local opts="" if [ "$1" = "-t" ] ; then opts="$opts -t $2" shift 2 fi if [ "$1" = "-p" ] ; then opts="$opts -p $2" shift 2 fi local DAEMON="$1" local SIGNAL="$2" [ -x "$DAEMON" ] || return 5 local pids=$(pidof -x "$DAEMON") if [ $? -eq 0 ] ; then [ -z "$pids" ] && return 0 if kill $SIGNAL $pids ; then return 0 fi fi return 1 } kl_checkproc() { # NOTE: kl_checkproc should returns LSB compliant status values. local pidfile="" if [ "$1" = "-p" ] ; then pidfile="$2" shift 2 fi local DAEMON="$1" [ -x "$DAEMON" ] || return 5 local pids='' if [ -z "$pidfile" ] ; then pids=$(pidof -x "$DAEMON") else pids="$(cat "$pidfile" 2>/dev/null)" fi if [ $? -eq 0 ] ; then [ -z "$pids" ] && return 3 return 0 fi return 4 } kl_exit() { exit $KL_RC } fi # other functions kl_get_value() { local filename="$1" local name="$2" if [ -f "$filename" ] ; then awk -v "name=$name" '{ if ( $0 ~ "^[ \t\r\n]*" name "=" ) { gsub("(^[ \t]*" name "=|[ \t\r\n]*$)",""); print $1; } }' \ "$filename" </dev/null fi } # # vim:sw=4:ts=4:expandtab:syntax=sh #
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel