Changeset 1d02f01 in bootscripts-standard for clfs/init.d/functions
- Timestamp:
- Oct 23, 2007, 1:07:58 AM (17 years ago)
- Branches:
- master
- Children:
- 1680407
- Parents:
- d8a3177
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
clfs/init.d/functions
rd8a3177 r1d02f01 51 51 WCOL=$((${COL} - 2)) 52 52 53 ## Set Cursor Position Commands, used via echo -e 53 ## Provide an echo that supports -e and -n 54 # If formatting is needed, $ECHO should be used 55 case "`echo -e -n test`" in 56 -[en]*) 57 ECHO=/bin/echo 58 ;; 59 *) 60 ECHO=echo 61 ;; 62 esac 63 64 ## Set Cursor Position Commands, used via $ECHO 54 65 SET_COL="\\033[${COL}G" # at the $COL char 55 66 SET_WCOL="\\033[${WCOL}G" # at the $WCOL char 56 67 CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char 57 68 58 ## Set color commands, used via echo -e69 ## Set color commands, used via $ECHO 59 70 # Please consult `man console_codes for more information 60 71 # under the "ECMA-48 Set Graphics Rendition" section … … 115 126 116 127 ## Figure out the length of what is to be printed to be used 117 ## for warning messges. 118 STRING_LENGTH="`echo "${1}" | sed \ 119 -e 's,.,.,g' -e 'l 1' | grep -c \$`" 128 ## for warning messages. 129 STRING_LENGTH=$((${#1} + 1)) 120 130 121 131 # Print the message to the screen 122 echo ${ECHOPARM} -e "${2}${1}" 123 if [ "$LOGGING" ]; then 124 DISPLAYLOG="${1}" 125 fi 132 ${ECHO} ${ECHOPARM} -e "${2}${1}" 126 133 127 134 } … … 147 154 echo_ok() 148 155 { 149 echo -n -e "${CURS_UP}${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]"150 echo -e "${NORMAL}"151 boot_mesg_flush "[ OK ]"152 156 if [ "$LCD_PROG" ]; then 153 157 if [ "$LCD_LINES" = "2" ]; then … … 157 161 LCD_OUT2="${LCD_OUT1:0:12} OK" 158 162 $LCD_PROG "$LCD_OUT2" > /dev/null 2>&1 159 fi 160 fi 163 fi 164 fi 165 ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]" 166 ${ECHO} -e "${NORMAL}" 167 boot_mesg_flush 161 168 } 162 169 163 170 echo_failure() 164 171 { 165 echo -n -e "${CURS_UP}${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]"166 echo -e "${NORMAL}"167 boot_mesg_flush "[ FAIL ]"168 172 if [ "$LCD_PROG" ]; then 169 173 if [ "$LCD_LINES" = "2" ]; then … … 175 179 fi 176 180 fi 181 ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]" 182 ${ECHO} -e "${NORMAL}" 183 boot_mesg_flush 177 184 } 178 185 179 186 echo_warning() 180 187 { 181 echo -n -e "${CURS_UP}${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]"182 echo -e "${NORMAL}"183 188 if [ "$LCD_PROG" ]; then 184 189 if [ "$LCD_LINES" = "2" ]; then … … 188 193 LCD_OUT2="${LCD_OUT1:0:10} WARN" 189 194 $LCD_PROG "$LCD_OUT2" > /dev/null 2>&1 190 fi 191 fi 192 boot_mesg_flush "[ WARN ]" 195 fi 196 fi 197 ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]" 198 ${ECHO} -e "${NORMAL}" 199 boot_mesg_flush 193 200 } 194 201 … … 198 205 # $i is inherited by the rc script 199 206 boot_log "\n\n${i} failed and exited with a return value of ${error_value}." 200 boot_mesg_flush201 207 boot_mesg -n "FAILURE:\n\nYou should not be reading this error message.\n\n" ${FAILURE} 202 208 boot_mesg -n " It means that an unforeseen error took" … … 209 215 boot_mesg " clfs-dev@cross-lfs.org.\n" 210 216 boot_mesg_flush 211 if [ "$INTERACTIVE" ]; then 212 boot_mesg -n "Press Enter to continue..." ${INFO} 213 boot_mesg "" ${NORMAL} 214 if [ "$LCD_PROG" ]; then 215 sleep 10 216 else 217 read ENTER 218 fi 219 fi 217 boot_mesg -n "Press Enter to continue..." ${INFO} 218 boot_mesg "" ${NORMAL} 219 read ENTER 220 220 } 221 221 … … 258 258 fi 259 259 260 # boot_mesg_flush261 # echo_warning262 263 260 case "${1}" in 264 261 … … 272 269 case "${2}" in 273 270 running) 274 echo-e -n "${CURS_UP}"275 echo-e -n "\\033[${STRING_LENGTH}G "271 ${ECHO} -e -n "${CURS_UP}" 272 ${ECHO} -e -n "\\033[${STRING_LENGTH}G " 276 273 boot_mesg "Already running." ${WARNING} 277 274 echo_warning 278 275 ;; 279 276 not_running) 280 echo-e -n "${CURS_UP}"281 echo-e -n "\\033[${STRING_LENGTH}G "277 ${ECHO} -e -n "${CURS_UP}" 278 ${ECHO} -e -n "\\033[${STRING_LENGTH}G " 282 279 boot_mesg "Not running." ${WARNING} 283 280 echo_warning 284 281 ;; 285 282 not_available) 286 echo-e -n "${CURS_UP}"287 echo-e -n "\\033[${STRING_LENGTH}G "283 ${ECHO} -e -n "${CURS_UP}" 284 ${ECHO} -e -n "\\033[${STRING_LENGTH}G " 288 285 boot_mesg "Not available." ${WARNING} 289 286 echo_warning … … 307 304 reloadproc() 308 305 { 309 if [ "${#}" = "0" ]; then 310 echo "Usage: reloadproc [{program}]" 311 exit 1 312 fi 313 314 getpids "${1}" 306 local pidfile="" 307 local failure=0 308 309 while true 310 do 311 case "${1}" in 312 -p) 313 pidfile="${2}" 314 shift 2 315 ;; 316 -*) 317 log_failure_msg "Unknown Option: ${1}" 318 return 2 319 ;; 320 *) 321 break 322 ;; 323 esac 324 done 325 326 if [ "${#}" -lt "1" ]; then 327 log_failure_msg "Usage: reloadproc [-p pidfile] pathname" 328 return 2 329 fi 330 331 # This will ensure compatibility with previous CLFS Bootscripts 332 if [ -n "${PIDFILE}" ]; then 333 pidfile="${PIDFILE}" 334 fi 335 336 # Is the process running? 337 if [ -z "${pidfile}" ]; then 338 pidofproc -s "${1}" 339 else 340 pidofproc -s -p "${pidfile}" "${1}" 341 fi 315 342 316 343 if [ -n "${pidlist}" ]; then 317 failure="0"318 344 for pid in ${pidlist} 319 345 do … … 332 358 statusproc() 333 359 { 334 if [ "${#}" = "0" ] 335 then 336 echo "Usage: statusproc {program}" 337 exit 1 338 fi 339 340 getpids "${1}" 360 local pidfile="" 361 local base="" 362 local ret="" 363 364 while true 365 do 366 case "${1}" in 367 -p) 368 pidfile="${2}" 369 shift 2 370 ;; 371 -*) 372 log_failure_msg "Unknown Option: ${1}" 373 return 2 374 ;; 375 *) 376 break 377 ;; 378 esac 379 done 380 381 if [ "${#}" != "1" ]; then 382 shift 1 383 log_failure_msg "Usage: statusproc [-p pidfile] pathname" 384 return 2 385 fi 386 387 # Get the process basename 388 base="${1##*/}" 389 390 # This will ensure compatibility with previous CLFS Bootscripts 391 if [ -n "${PIDFILE}" ]; then 392 pidfile="${PIDFILE}" 393 fi 394 395 # Is the process running? 396 if [ -z "${pidfile}" ]; then 397 pidofproc -s "${1}" 398 else 399 pidofproc -s -p "${pidfile}" "${1}" 400 fi 401 402 # Store the return status 403 ret=$? 341 404 342 405 if [ -n "${pidlist}" ]; then 343 echo-e "${INFO}${base} is running with Process"\406 ${ECHO} -e "${INFO}${base} is running with Process"\ 344 407 "ID(s) ${pidlist}.${NORMAL}" 345 408 else 346 409 if [ -n "${base}" -a -e "/var/run/${base}.pid" ]; then 347 echo-e "${WARNING}${1} is not running but"\410 ${ECHO} -e "${WARNING}${1} is not running but"\ 348 411 "/var/run/${base}.pid exists.${NORMAL}" 349 412 else 350 if [ -n "${ PIDFILE}" -a -e "${PIDFILE}" ]; then351 echo-e "${WARNING}${1} is not running"\352 "but ${ PIDFILE} exists.${NORMAL}"413 if [ -n "${pidfile}" -a -e "${pidfile}" ]; then 414 ${ECHO} -e "${WARNING}${1} is not running"\ 415 "but ${pidfile} exists.${NORMAL}" 353 416 else 354 echo-e "${INFO}${1} is not running.${NORMAL}"417 ${ECHO} -e "${INFO}${1} is not running.${NORMAL}" 355 418 fi 356 419 fi 357 420 fi 421 422 # Return the status from pidofproc 423 return $ret 358 424 } 359 425 … … 426 492 do 427 493 if [ "${pid}" -ne "$$" -a "${pid}" -ne "${PPID}" ]; then 428 kill -0 "${pid}" >/dev/null &&494 kill -0 "${pid}" 2>/dev/null && 429 495 pidlist="${pidlist} ${pid}" 430 496 fi 431 497 432 if [ "${silent}" -ne"1" ]; then498 if [ "${silent}" != "1" ]; then 433 499 echo "${pidlist}" 434 500 fi … … 443 509 else 444 510 pidlist=`pidof -o $$ -o $PPID -x "$1"` 445 if [ " x${silent}" != "x1" ]; then511 if [ "${silent}" != "1" ]; then 446 512 echo "${pidlist}" 447 513 fi … … 592 658 { 593 659 local pidfile="" 594 local killsig= ""660 local killsig=TERM # default signal is SIGTERM 595 661 pidlist="" 596 662 597 # This will ensure compatibility with previous CLFS Bootscripts663 # This will ensure compatibility with previous CLFS Bootscripts 598 664 if [ -n "${PIDFILE}" ]; then 599 665 pidfile="${PIDFILE}" … … 610 676 log_failure_msg "Unknown Option: ${1}" 611 677 return 2 612 ;;678 ;; 613 679 *) 614 680 break … … 625 691 fi 626 692 693 # Is the process running? 627 694 if [ -z "${pidfile}" ]; then 628 695 pidofproc -s "${1}" … … 631 698 fi 632 699 633 # Change....700 # If running, send the signal 634 701 if [ -n "${pidlist}" ]; then 635 702 for pid in ${pidlist} 636 703 do 637 kill -${killsig:-TERM} ${pid} 2>/dev/null 638 if [ -z "${killsig}" ]; then 639 # Wait up to 3 seconds, for ${pid} to terminate 640 local dtime=${KILLDELAY} 704 kill -${killsig} ${pid} 2>/dev/null 705 706 # Wait up to 3 seconds, for ${pid} to terminate 707 case "${killsig}" in 708 TERM|SIGTERM|KILL|SIGKILL) 709 # sleep in 1/10ths of seconds and 710 # multiply KILLDELAY by 10 711 local dtime="${KILLDELAY}0" 641 712 while [ "${dtime}" != "0" ] 642 713 do 643 714 kill -0 ${pid} 2>/dev/null || break 644 sleep 1715 sleep 0.1 645 716 dtime=$(( ${dtime} - 1)) 646 717 done 647 718 # If ${pid} is still running, kill it 648 719 kill -0 ${pid} 2>/dev/null && kill -KILL ${pid} 2>/dev/null 649 fi 720 ;; 721 esac 650 722 done 651 723 652 if [ -z "${killsig}" ]; then 653 pidofproc -s "${1}" 724 # Check if the process is still running if we tried to stop it 725 case "${killsig}" in 726 TERM|SIGTERM|KILL|SIGKILL) 727 if [ -z "${pidfile}" ]; then 728 pidofproc -s "${1}" 729 else 730 pidofproc -s -p "${pidfile}" "${1}" 731 fi 654 732 655 733 # Program was terminated 656 734 if [ "$?" != "0" ]; then 657 # Pidfile Exists735 # Remove the pidfile if necessary 658 736 if [ -f "${pidfile}" ]; then 659 737 rm -f "${pidfile}" … … 665 743 return 4 # Unknown Status 666 744 fi 667 else 668 if [ -z "${pidfile}" ]; then 669 pidofproc -s "${1}" 670 else 671 pidofproc -s -p "${pidfile}" "${1}" 672 fi 673 fi 674 675 evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts 676 677 else 745 ;; 746 *) 747 # Just see if the kill returned successfully 748 evaluate_retval 749 ;; 750 esac 751 else # process not running 678 752 print_status warning not_running 679 753 fi … … 697 771 log_success_msg() 698 772 { 699 echo-n -e "${BOOTMESG_PREFIX}${@}"700 echo-e "${SET_COL}""${BRACKET}""[""${SUCCESS}"" OK ""${BRACKET}""]""${NORMAL}"773 ${ECHO} -n -e "${BOOTMESG_PREFIX}${@}" 774 ${ECHO} -e "${SET_COL}""${BRACKET}""[""${SUCCESS}"" OK ""${BRACKET}""]""${NORMAL}" 701 775 return 0 702 776 } … … 717 791 #******************************************************************************* 718 792 log_failure_msg() { 719 echo-n -e "${BOOTMESG_PREFIX}${@}"720 echo-e "${SET_COL}""${BRACKET}""[""${FAILURE}"" FAIL ""${BRACKET}""]""${NORMAL}"793 ${ECHO} -n -e "${BOOTMESG_PREFIX}${@}" 794 ${ECHO} -e "${SET_COL}""${BRACKET}""[""${FAILURE}"" FAIL ""${BRACKET}""]""${NORMAL}" 721 795 return 0 722 796 } … … 737 811 #******************************************************************************* 738 812 log_warning_msg() { 739 echo-n -e "${BOOTMESG_PREFIX}${@}"740 echo-e "${SET_COL}""${BRACKET}""[""${WARNING}"" WARN ""${BRACKET}""]""${NORMAL}"813 ${ECHO} -n -e "${BOOTMESG_PREFIX}${@}" 814 ${ECHO} -e "${SET_COL}""${BRACKET}""[""${WARNING}"" WARN ""${BRACKET}""]""${NORMAL}" 741 815 return 0 742 816 }
Note:
See TracChangeset
for help on using the changeset viewer.