live $ ˆl–ßi~”ªClÊi@†ã-Üh bÑ¿Æ „ Â?ÅÄÃ?÷ # -*-Shell-script-*- # # functions This file contains functions to be used by most or all # shell scripts in the /etc/init.d directory. # TEXTDOMAIN=initscripts # Make sure umask is sane umask 022 # Set up a default search path. PATH="/sbin:/usr/sbin:/bin:/usr/bin" export PATH if [ $PPID -ne 1 -a -z "$SYSTEMCTL_SKIP_REDIRECT" ] && \ [ -d /run/systemd/system ] ; then case "$0" in /etc/init.d/*|/etc/rc.d/init.d/*) _use_systemctl=1 ;; esac fi systemctl_redirect () { local s local prog=${1##*/} local command=$2 local options="" case "$command" in start) s=$"Starting $prog (via systemctl): " ;; stop) s=$"Stopping $prog (via systemctl): " ;; reload|try-reload) s=$"Reloading $prog configuration (via systemctl): " ;; restart|try-restart|condrestart) s=$"Restarting $prog (via systemctl): " ;; esac if [ -n "$SYSTEMCTL_IGNORE_DEPENDENCIES" ] ; then options="--ignore-dependencies" fi if ! systemctl show "$prog.service" > /dev/null 2>&1 || \ systemctl show -p LoadState "$prog.service" | grep -q 'not-found' ; then action $"Reloading systemd: " /bin/systemctl daemon-reload fi action "$s" /bin/systemctl $options $command "$prog.service" } # Get a sane screen width [ -z "${COLUMNS:-}" ] && COLUMNS=80 # Read in our configuration if [ -z "${BOOTUP:-}" ]; then if [ -f /etc/sysconfig/init ]; then . /etc/sysconfig/init else # verbose ->> very (very!) old bootup look (prior to RHL-6.0?) # color ->> default bootup look # other ->> default bootup look without ANSI colors or positioning BOOTUP=color # Column to start "[ OK ]" label in: RES_COL=60 # terminal sequence to move to that column: MOVE_TO_COL="echo -en \\033[${RES_COL}G" # Terminal sequence to set color to a 'success' (bright green): SETCOLOR_SUCCESS="echo -en \\033[1;32m" # Terminal sequence to set color to a 'failure' (bright red): SETCOLOR_FAILURE="echo -en \\033[1;31m" # Terminal sequence to set color to a 'warning' (bright yellow): SETCOLOR_WARNING="echo -en \\033[1;33m" # Terminal sequence to reset to the default color: SETCOLOR_NORMAL="echo -en \\033[0;39m" # Verbosity of logging: LOGLEVEL=1 fi # NOTE: /dev/ttyS* is serial console. "not a tty" is such as # /dev/null associated when executed under systemd service units. if LANG=C tty | grep -q -e '\(/dev/ttyS\|not a tty\)'; then BOOTUP=serial MOVE_TO_COL= SETCOLOR_SUCCESS= SETCOLOR_FAILURE= SETCOLOR_WARNING= SETCOLOR_NORMAL= fi fi # Check if any of $pid (could be plural) are running checkpid() { local i for i in $* ; do [ -d "/proc/$i" ] && return 0 done return 1 } __kill_pids_term_kill_checkpids() { local base_stime=$1 shift 1 local pid= local pids=$* local remaining= local stat= local stime= for pid in $pids ; do [ ! -e "/proc/$pid" ] && continue read -r line < "/proc/$pid/stat" 2> /dev/null stat=($line) stime=${stat[21]} [ -n "$stime" ] && [ "$base_stime" -lt "$stime" ] && continue remaining+="$pid " done echo "$remaining" [ -n "$remaining" ] && return 1 return 0 } __kill_pids_term_kill() { local try=0 local delay=3; local pid= local stat= local base_stime= # We can't initialize stat & base_stime on the same line where 'local' # keyword is, otherwise the sourcing of this file will fail for ksh... stat=($(< /proc/self/stat)) base_stime=${stat[21]} if [ "$1" = "-d" ]; then delay=$2 shift 2 fi local kill_list=$* kill_list=$(__kill_pids_term_kill_checkpids $base_stime $kill_list) [ -z "$kill_list" ] && return 0 kill -TERM $kill_list >/dev