Changeset d93bdd1e for lsb-bootscripts/lib/lsb/init-functions
- Timestamp:
- 05/21/2011 05:22:20 PM (13 years ago)
- Branches:
- 10.0, 10.0-rc1, 10.1, 10.1-rc1, 11.0, 11.0-rc1, 11.0-rc2, 11.0-rc3, 11.1, 11.1-rc1, 11.2, 11.2-rc1, 11.3, 11.3-rc1, 12.0, 12.0-rc1, 12.1, 12.1-rc1, 12.2, 12.2-rc1, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.5-systemd, 7.6, 7.6-systemd, 7.7, 7.7-systemd, 7.8, 7.8-systemd, 7.9, 7.9-systemd, 8.0, 8.1, 8.2, 8.3, 8.4, 9.0, 9.1, arm, bdubbs/gcc13, ml-11.0, multilib, renodr/libudev-from-systemd, s6-init, trunk, xry111/arm64, xry111/arm64-12.0, xry111/clfs-ng, xry111/lfs-next, xry111/loongarch, xry111/loongarch-12.0, xry111/loongarch-12.1, xry111/loongarch-12.2, xry111/mips64el, xry111/multilib, xry111/pip3, xry111/rust-wip-20221008, xry111/update-glibc
- Children:
- ff8773d
- Parents:
- c2db087
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lsb-bootscripts/lib/lsb/init-functions
rc2db087 rd93bdd1e 9 9 fi 10 10 11 # Source the distro functions file 12 if [ "${DISTRO_MINI}" != "" ]; then 13 . "${RC_BASE}/init.d/${DISTRO_MINI}-functions" 14 fi 15 16 ################################################################################ 17 # start_daemon() # 18 # Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...] # 19 # # 20 # Purpose: This runs the specified program as a daemon # 21 # # 22 # Inputs: -f: (force) run the program even if it is already running. # 23 # -n nicelevel: specify a nice level. See 'man nice(1)'. # 24 # -p pidfile: use the specified file to determine PIDs. # 25 # pathname: the complete path to the specified program # 26 # args: additional arguments passed to the program (pathname) # 27 # # 28 # Return values (as defined by LSB exit codes): # 29 # 0 - program is running or service is OK # 30 # 1 - generic or unspecified error # 31 # 2 - invalid or excessive argument(s) # 32 # 5 - program is not installed # 33 ################################################################################ 11 ############################################################################### 12 # start_daemon() # 13 # Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...] # 14 # # 15 # Purpose: This runs the specified program as a daemon # 16 # # 17 # Inputs: -f: (force) run the program even if it is already running. # 18 # -n nicelevel: specify a nice level. See 'man nice(1)'. # 19 # -p pidfile: use the specified file to determine PIDs. # 20 # pathname: the complete path to the specified program # 21 # args: additional arguments passed to the program (pathname) # 22 # # 23 # Return values (as defined by LSB exit codes): # 24 # 0 - program is running or service is OK # 25 # 1 - generic or unspecified error # 26 # 2 - invalid or excessive argument(s) # 27 # 5 - program is not installed # 28 ############################################################################### 34 29 start_daemon() 35 30 { … … 128 123 } 129 124 130 ############################################################################### #131 # killproc() 132 # Usage: killproc [-p pidfile] pathname [signal] 133 # 134 # Purpose: Send control signals to running processes 135 # 136 # Inputs: -p pidfile, uses the specified pidfile 137 # pathname, pathname to the specified program 138 # signal, send this signal to pathname 139 # 140 # Return values (as defined by LSB exit codes): 141 # 0 - program (pathname) has stopped/is already stopped or a 142 # running program has been sent specified signal and stopped 143 # successfully 144 # 1 - generic or unspecified error 145 # 2 - invalid or excessive argument(s) 146 # 5 - program is not installed 147 # 7 - program is not running and a signal was supplied 148 ############################################################################### #125 ############################################################################### 126 # killproc() # 127 # Usage: killproc [-p pidfile] pathname [signal] # 128 # # 129 # Purpose: Send control signals to running processes # 130 # # 131 # Inputs: -p pidfile, uses the specified pidfile # 132 # pathname, pathname to the specified program # 133 # signal, send this signal to pathname # 134 # # 135 # Return values (as defined by LSB exit codes): # 136 # 0 - program (pathname) has stopped/is already stopped or a # 137 # running program has been sent specified signal and stopped # 138 # successfully # 139 # 1 - generic or unspecified error # 140 # 2 - invalid or excessive argument(s) # 141 # 5 - program is not installed # 142 # 7 - program is not running and a signal was supplied # 143 ############################################################################### 149 144 killproc() 150 145 { … … 336 331 } 337 332 338 ############################################################################### #339 # pidofproc() 340 # Usage: pidofproc [-p pidfile] pathname 341 # 342 # Purpose: This function returns one or more pid(s) for a particular daemon 343 # 344 # Inputs: -p pidfile, use the specified pidfile instead of pidof 345 # pathname, path to the specified program 346 # 347 # Return values (as defined by LSB status codes): 348 # 0 - Success (PIDs to stdout) 349 # 1 - Program is dead, PID file still exists (remaining PIDs output) 350 # 3 - Program is not running (no output) 351 ############################################################################### #333 ############################################################################### 334 # pidofproc() # 335 # Usage: pidofproc [-p pidfile] pathname # 336 # # 337 # Purpose: This function returns one or more pid(s) for a particular daemon # 338 # # 339 # Inputs: -p pidfile, use the specified pidfile instead of pidof # 340 # pathname, path to the specified program # 341 # # 342 # Return values (as defined by LSB status codes): # 343 # 0 - Success (PIDs to stdout) # 344 # 1 - Program is dead, PID file still exists (remaining PIDs output) # 345 # 3 - Program is not running (no output) # 346 ############################################################################### 352 347 pidofproc() 353 348 { … … 428 423 fi 429 424 } 430 ################################################################################ 431 # log_success_msg() # 432 # Usage: log_success_msg [$MESSAGE | "message"] # 433 # # 434 # Purpose: Print a successful status message to the screen and optionally # 435 # a boot log file. # 436 # # 437 # Inputs: accepts one string value, either a quoted string or optionally # 438 # the value of $MESSAGE if set in the running environment. # 439 # # 440 # Return values: Not used # 441 ################################################################################ 425 426 ############################################################################### 427 # log_success_msg() # 428 # Usage: log_success_msg [$MESSAGE | "message"] # 429 # # 430 # Purpose: Print a successful status message to the screen and optionally # 431 # a boot log file. # 432 # # 433 # Inputs: accepts one string value, either a quoted string or optionally # 434 # the value of $MESSAGE if set in the running environment. # 435 # # 436 # Return values: Not used # 437 ############################################################################### 442 438 log_success_msg() 443 439 { … … 457 453 } 458 454 459 ############################################################################### #460 # log_failure_msg() 461 # Usage: log_failure_msg [$MESSAGE | "message"] 462 # 463 # Purpose: Print a failure status message to the screen and optionally 464 # a boot log file. 465 # 466 # Inputs: accepts one string value, either a quoted string or optionally 467 # the value of $MESSAGE if set in the running environment. 468 # 469 # Return values: Not used 470 ############################################################################### #455 ############################################################################### 456 # log_failure_msg() # 457 # Usage: log_failure_msg [$MESSAGE | "message"] # 458 # # 459 # Purpose: Print a failure status message to the screen and optionally # 460 # a boot log file. # 461 # # 462 # Inputs: accepts one string value, either a quoted string or optionally # 463 # the value of $MESSAGE if set in the running environment. # 464 # # 465 # Return values: Not used # 466 ############################################################################### 471 467 log_failure_msg() 472 468 { … … 486 482 } 487 483 488 ############################################################################### #489 # log_warning_msg() 490 # Usage: log_warning_msg [$MESSAGE | "message"] 491 # 492 # Purpose: Print a warning status message to the screen and optionally 493 # a boot log file. 494 # 495 # Inputs: accepts one string value, either a quoted string or optionally 496 # the value of $MESSAGE if set in the running environment. 497 # 498 # Return values: Not used 499 ############################################################################### #484 ############################################################################### 485 # log_warning_msg() # 486 # Usage: log_warning_msg [$MESSAGE | "message"] # 487 # # 488 # Purpose: Print a warning status message to the screen and optionally # 489 # a boot log file. # 490 # # 491 # Inputs: accepts one string value, either a quoted string or optionally # 492 # the value of $MESSAGE if set in the running environment. # 493 # # 494 # Return values: Not used # 495 ############################################################################### 500 496 log_warning_msg() 501 497 { … … 515 511 } 516 512 517 ################################################################################ 518 # check_signal() # 519 # Usage: check_signal [ -{signal} | {signal} ] # 520 # # 521 # Purpose: Check for a valid signal. This is not defined by any LSB draft, # 522 # however, it is required to check the signals to determine if the # 523 # signals chosen are invalid arguments to the other functions. # 524 # # 525 # Inputs: accepts a single string value in the form or -{signal} or {signal} # 526 # # 527 # Return values: # 528 # 0 - Success (signal is valid # 529 # 1 - Signal is not valid # 530 ################################################################################ 513 # The remaining fucntions are distro specific and are not defined by the LSB 514 515 ############################################################################### 516 # check_signal() # 517 # Usage: check_signal [ -{signal} | {signal} ] # 518 # # 519 # Purpose: Check for a valid signal. This is not defined by any LSB draft, # 520 # however, it is required to check the signals to determine if the # 521 # signals chosen are invalid arguments to the other functions. # 522 # # 523 # Inputs: accepts a single string value in the form or -{signal} or {signal} # 524 # # 525 # Return values: # 526 # 0 - Success (signal is valid # 527 # 1 - Signal is not valid # 528 ############################################################################### 531 529 check_signal() 532 530 { … … 549 547 } 550 548 551 552 ################################################################################ 553 # check_sig_type() # 554 # Usage: check_signal [ -{signal} | {signal} ] # 555 # # 556 # Purpose: Check if signal is a program termination signal or a control signal # 557 # This is not defined by any LSB draft, however, it is required to # 558 # check the signals to determine if they are intended to end a # 559 # program or simply to control it. # 560 # # 561 # Inputs: accepts a single string value in the form or -{signal} or {signal} # 562 # # 563 # Return values: # 564 # 0 - Signal is used for program termination # 565 # 1 - Signal is used for program control # 566 ################################################################################ 549 ############################################################################### 550 # check_sig_type() # 551 # Usage: check_signal [ -{signal} | {signal} ] # 552 # # 553 # Purpose: Check if signal is a program termination signal or a control # 554 # signal. This is not defined by any LSB draft, however, it is # 555 # required to check the signals to determine if they are intended # 556 # to end a program or simply to control it. # 557 # # 558 # Inputs: accepts a single string value in the form or -{signal} or {signal} # 559 # # 560 # Return values: # 561 # 0 - Signal is used for program termination # 562 # 1 - Signal is used for program control # 563 ############################################################################### 567 564 check_sig_type() 568 565 { … … 581 578 } 582 579 580 ############################################################################### 581 # chkstat() # 582 # Usage: chckstat BIN_FILE {CONFIG_FILE} # 583 # # 584 # Purpose: chk_stat checks the status of a script by checking for both a # 585 # binary file to execute, and if set, a config file that may be # 586 # needed for the program to run successfully. # 587 # # 588 # Inputs: accepts first argument of an executable file, and optionally a # 589 # second arugument of a configuration file. If BIN_FILE and # 590 # CONFIG_FILE are set in the calling environment, either or both # 591 # arguments may be omitted. # 592 # # 593 # Return values: # 594 # 0 - The executable, and optionally the configuration file exists # 595 # 2 - Invalid or excessive arguments # 596 # 5 - BIN_FILE does not exist # 597 # 6 - CONFIG_FILE (if set) does not exist # 598 ############################################################################### 599 chk_stat() 600 { 601 if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then 602 BIN_FILE="${1}" 603 if [ -z "${2}" ]; then 604 CONFIG_FILE="" 605 else 606 CONFIG_FILE="${2}" 607 fi 608 elif [ -z "${BIN_FILE}" ]; then 609 echo "Usage: 'chk_stat BIN_FILE CONFIG_FILE'" 610 exit 1 # Generic Error 611 fi 612 613 if [ ! -e "${BIN_FILE}" ]; then 614 log_failure_msg "${BIN_FILE} not installed" && 615 exit 5 616 fi 617 618 if [ ! -z "${CONFIG_FILE}" ]; then 619 if [ ! -e "${CONFIG_FILE}" ]; then 620 log_failure_msg "${CONFIG_FILE} does not exist" && 621 exit 6 622 fi 623 fi 624 } 625 626 ############################################################################### 627 # loadproc() # 628 # Usage: loadproc {arguments} # 629 # # 630 # Purpose: loadproc is just a wrapper to start_daemon for simple scripts, # 631 # which will require no aruguments if $BIN_FILE is set. # 632 # # 633 # Inputs: Any optional arguments passed to loadproc will be passed on to the # 634 # executable defined by $BIN_FILE. # 635 # # 636 # Return values: (none) # 637 ############################################################################### 638 loadproc() 639 { 640 start_daemon "${BIN_FILE}" "${@}" 641 } 642 643 ############################################################################### 644 # endproc() # 645 # Usage: endproc {arguments} # 646 # # 647 # Purpose: endproc is just a wrapper to killproc for simple scripts, which # 648 # which will require no aruguments if $BIN_FILE is set. # 649 # # 650 # Inputs: Any optional arguments passed to endproc will be passed on to the # 651 # executable defined by $BIN_FILE. # 652 # # 653 # Return values: (none) # 654 ############################################################################### 655 endproc() 656 { 657 killproc "${BIN_FILE}" "${@}" 658 } 659 660 ############################################################################### 661 # statusproc() # 662 # Usage: statusproc $BIN_FILE $MESSAGE # 663 # # 664 # Purpose: stautsproc is just a wrapper to pidofproc for simple scripts, # 665 # which will require no aruguments if $BIN_FILE and MESSAGE are set. # 666 # # 667 # Inputs: accepts first argument of an executable file, and a second message # 668 # arugument "MESSAGE" to be displayed. If BIN_FILE and MESSAGE are # 669 # set in the calling environment, both arguments may be omitted. # 670 # # 671 # Return values: exit values of pidofproc # 672 ############################################################################### 673 statusproc() 674 { 675 if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then 676 BIN_FILE="${1}" 677 MESSAGE="${2}" 678 elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then 679 echo "Usage: 'statusproc BIN_FILE MESSAGE'" 680 exit 1 # Generic Error 681 fi 682 683 pidlist=`pidofproc "${BIN_FILE}"` 684 STATUS=$? 685 echo "Checking ${MESSAGE} status:" 686 if [ "${STATUS}" -eq "0" ]; then 687 log_success_msg "Running with PID(s) ${pidlist}" 688 else 689 log_warning_msg "Not running!" 690 fi 691 692 return "${STATUS}" 693 } 694 695 ############################################################################### 696 # reloadproc() # 697 # Usage: reloadproc {--force} $BIN_FILE $MESSAGE # 698 # # 699 # Purpose: reloadproc sends a HUP signal to the running program (relaod # 700 # configuration). It optionally, using the -force switch, checks the # 701 # status of a particular program and starts it if it is not already # 702 # running. # 703 # # 704 # Inputs: accepts one optional switch (must be the first argument), and # 705 # either two, or zero string arguments. If BIN_FILE and MESSAGE are # 706 # set in the calling envirnoment it will use those values, else it # 707 # requires the bin file as the first argument (following -force if # 708 # used), and the message as the second. If the --force argument is # 709 # given, it follows the LSB definition of 'force-reload' - the # 710 # program is started if not already running. # 711 # # 712 # Return values: 1 - generic error # 713 ############################################################################### 714 reloadproc() 715 { 716 local force="0" 717 if [ "${#}" -gt "0" -a "${1}" = "-force" ]; then 718 force="1" 719 shift 1 720 fi 721 722 if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then 723 BIN_FILE="${1}" 724 MESSAGE="${2}" 725 elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then 726 echo "Usage: 'reloadproc BIN_FILE MESSAGE'" 727 exit 1 # Generic Error 728 fi 729 } 730 731 ############################################################################### 732 # evaluate_retval() # 733 # Usage: evaluate_retval \ # 734 # [standard|start|stop|reload|force-reload|restart|try-restart] # 735 # # 736 # Purpose: determines the sucess or failure of a previous command based on # 737 # LSB exit values, and prints messages to the screen using the # 738 # log_*_msg() functions. # 739 # # 740 # Inputs: accepts one argument which determines the output of the message # 741 # displayed on the screen based on the LSB input values for init # 742 # scripts. The 'standard' argument makes no changes to the value of # 743 # $message or $MESSAGE, but only one can be set in the calling # 744 # environment. # 745 # # 746 # Return values: (none) # 747 ############################################################################### 748 evaluate_retval() 749 { 750 local error_value="${?}" 751 752 # Handle LSB defined return values 753 case "${1}" in 754 755 start) 756 case "${error_value}" in 757 0) 758 log_success_msg "Starting ${MESSAGE} " 759 return "${error_value}" 760 ;; 761 2) 762 log_failure_msg "Starting ${MESSAGE} Error: Invalid argument!" 763 return "${error_value}" 764 ;; 765 5) 766 log_failure_msg "Starting ${MESSAGE} Error: Not available!" 767 return "${error_value}" 768 ;; 769 *) 770 log_failure_msg "Starting ${MESSAGE} Error: General failure!" 771 return "${error_value}" 772 ;; 773 esac 774 ;; 775 776 stop) 777 case "${error_value}" in 778 0) 779 log_success_msg "Stopping ${MESSAGE} " 780 return "${error_value}" 781 ;; 782 2) 783 log_failure_msg "Stopping ${MESSAGE} Error: Invalid argument!" 784 return "${error_value}" 785 ;; 786 5) 787 log_failure_msg "Stopping ${MESSAGE} Error: Not available!" 788 return "${error_value}" 789 ;; 790 7) 791 log_warning_msg "Stopping ${MESSAGE} Warning: Not running!" 792 return "${error_value}" 793 ;; 794 *) 795 log_failure_msg "Stopping ${MESSAGE} Error: General failure!" 796 return "${error_value}" 797 ;; 798 esac 799 ;; 800 801 force-reload) 802 message="Forcefully reloading " 803 ;; 804 805 reload) 806 message="Reloading " 807 ;; 808 809 restart) 810 message="Restarting " 811 ;; 812 813 try-restart) 814 message="Trying restart " 815 ;; 816 817 standard) 818 # $message or $MESSAGE must be set, but not both in order 819 # to use the 'standard' target. 820 ;; 821 esac 822 823 # Print messages for the generic force-reload, reload, restart, 824 # and try-restart targets 825 if [ "${error_value}" -eq "0" ] 826 then 827 log_success_msg "${message}${MESSAGE} " 828 return "${error_value}" 829 else 830 log_failure_msg "${message}${MESSAGE} " 831 return "${error_value}" 832 fi 833 } 834 583 835 # End /lib/lsb/init-functions
Note:
See TracChangeset
for help on using the changeset viewer.