rc.subr (115950) | rc.subr (116097) |
---|---|
1# $NetBSD: rc.subr,v 1.49 2002/05/21 12:31:01 lukem Exp $ | 1# $NetBSD: rc.subr,v 1.49 2002/05/21 12:31:01 lukem Exp $ |
2# $FreeBSD: head/etc/rc.subr 115950 2003-06-07 10:31:17Z mtm $ | 2# $FreeBSD: head/etc/rc.subr 116097 2003-06-09 17:31:06Z mtm $ |
3# 4# Copyright (c) 1997-2002 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# This code is derived from software contributed to The NetBSD Foundation 8# by Luke Mewburn. 9# 10# Redistribution and use in source and binary forms, with or without --- 432 unchanged lines hidden (view full) --- 443# 444# rc_fast Not empty if "fast" was provided (q.v.) 445# 446# rc_force Not empty if "force" was provided (q.v.) 447# 448# 449run_rc_command() 450{ | 3# 4# Copyright (c) 1997-2002 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# This code is derived from software contributed to The NetBSD Foundation 8# by Luke Mewburn. 9# 10# Redistribution and use in source and binary forms, with or without --- 432 unchanged lines hidden (view full) --- 443# 444# rc_fast Not empty if "fast" was provided (q.v.) 445# 446# rc_force Not empty if "force" was provided (q.v.) 447# 448# 449run_rc_command() 450{ |
451 _return=0 |
|
451 rc_arg=$1 452 if [ -z "$name" ]; then 453 err 3 'run_rc_command: $name is not set.' 454 fi 455 456 case "$rc_arg" in 457 fast*) # "fast" prefix; don't check pid 458 rc_arg=${rc_arg#fast} --- 71 unchanged lines hidden (view full) --- 530 # run that instead of the default 531 # 532 eval _cmd=\$${rc_arg}_cmd _precmd=\$${rc_arg}_precmd \ 533 _postcmd=\$${rc_arg}_postcmd 534 if [ -n "$_cmd" ]; then 535 # if the precmd failed and force 536 # isn't set, exit 537 # | 452 rc_arg=$1 453 if [ -z "$name" ]; then 454 err 3 'run_rc_command: $name is not set.' 455 fi 456 457 case "$rc_arg" in 458 fast*) # "fast" prefix; don't check pid 459 rc_arg=${rc_arg#fast} --- 71 unchanged lines hidden (view full) --- 531 # run that instead of the default 532 # 533 eval _cmd=\$${rc_arg}_cmd _precmd=\$${rc_arg}_precmd \ 534 _postcmd=\$${rc_arg}_postcmd 535 if [ -n "$_cmd" ]; then 536 # if the precmd failed and force 537 # isn't set, exit 538 # |
538 [ -n "$_precmd" ] && 539 debug "run_rc_command: evaluating ${_precmd}()." 540 if ! eval $_precmd && [ -z "$rc_force" ]; then 541 return 1 | 539 if [ -n "$_precmd" ]; then 540 debug "run_rc_command: evaluating ${_precmd}()." 541 eval $_precmd 542 _return=$? 543 [ $_return -ne 0 ] && [ -z "$rc_force" ] && 544 return 1 |
542 fi 543 | 545 fi 546 |
544 [ -n "$_cmd" ] && 545 debug "run_rc_command: evaluating ${_cmd}()." 546 if ! eval $_cmd && [ -z "$rc_force" ]; then 547 return 1 | 547 if [ -n "$_cmd" ]; then 548 debug "run_rc_command: evaluating ${_cmd}()." 549 eval $_cmd 550 _return=$? 551 [ $_return -ne 0 ] && [ -z "$rc_force" ] && 552 return 1 |
548 fi 549 | 553 fi 554 |
550 [ -n "$_postcmd" ] && 551 debug "run_rc_command: evaluating ${_postcmd}()." 552 eval $_postcmd 553 return 0 | 555 if [ -n "$_postcmd" ]; then 556 debug "run_rc_command: evaluating ${_postcmd}()." 557 eval $_postcmd 558 _return=$? 559 fi 560 return $_return |
554 fi 555 556 case "$rc_arg" in # default operations... 557 558 status) 559 if [ -n "$rc_pid" ]; then 560 echo "${name} is running as pid $rc_pid." 561 else --- 39 unchanged lines hidden (view full) --- 601 return 1 602 fi 603 fi 604 done 605 606 # if the precmd failed and force 607 # isn't set, exit 608 # | 561 fi 562 563 case "$rc_arg" in # default operations... 564 565 status) 566 if [ -n "$rc_pid" ]; then 567 echo "${name} is running as pid $rc_pid." 568 else --- 39 unchanged lines hidden (view full) --- 608 return 1 609 fi 610 fi 611 done 612 613 # if the precmd failed and force 614 # isn't set, exit 615 # |
609 [ -n "${_precmd}" ] && 610 debug "run_rc_command: evaluating ${_precmd}()." 611 if ! eval $_precmd && [ -z "$rc_force" ]; then 612 return 1 | 616 if [ -n "${_precmd}" ]; then 617 debug "run_rc_command: evaluating ${_precmd}()." 618 eval $_precmd 619 _return=$? 620 [ $_return -ne 0 ] && [ -z "$rc_force" ] && 621 return 1 |
613 fi 614 615 # setup the command to run, and run it 616 # 617 echo "Starting ${name}." 618 if [ -n "$_chroot" ]; then 619 _doit="\ 620${_nice:+nice -n $_nice }\ --- 8 unchanged lines hidden (view full) --- 629 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 630 fi 631 fi 632 633 # if the cmd failed and force 634 # isn't set, exit 635 # 636 debug "run_rc_command: _doit: $_doit" | 622 fi 623 624 # setup the command to run, and run it 625 # 626 echo "Starting ${name}." 627 if [ -n "$_chroot" ]; then 628 _doit="\ 629${_nice:+nice -n $_nice }\ --- 8 unchanged lines hidden (view full) --- 638 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 639 fi 640 fi 641 642 # if the cmd failed and force 643 # isn't set, exit 644 # 645 debug "run_rc_command: _doit: $_doit" |
637 if ! eval $_doit && [ -z "$rc_force" ]; then 638 return 1 639 fi | 646 eval $_doit 647 _return=$? 648 [ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1 |
640 641 # finally, run postcmd 642 # | 649 650 # finally, run postcmd 651 # |
643 [ -n "${_postcmd}" ] && 644 debug "run_rc_command: evaluating ${_postcmd}()." 645 eval $_postcmd | 652 if [ -n "${_postcmd}" ]; then 653 debug "run_rc_command: evaluating ${_postcmd}()." 654 eval $_postcmd 655 fi |
646 ;; 647 648 stop) 649 if [ -z "$rc_pid" ]; then 650 if [ -n "$pidfile" ]; then 651 echo \ 652 "${name} not running? (check $pidfile)." 653 else 654 echo "${name} not running?" 655 fi 656 exit 1 657 fi 658 659 # if the precmd failed and force 660 # isn't set, exit 661 # | 656 ;; 657 658 stop) 659 if [ -z "$rc_pid" ]; then 660 if [ -n "$pidfile" ]; then 661 echo \ 662 "${name} not running? (check $pidfile)." 663 else 664 echo "${name} not running?" 665 fi 666 exit 1 667 fi 668 669 # if the precmd failed and force 670 # isn't set, exit 671 # |
662 if ! eval $_precmd && [ -z "$rc_force" ]; then 663 return 1 | 672 if [ -n $_precmd ]; then 673 eval $_precmd 674 _return=$? 675 [ $_return -ne 0 ] && [ -z "$rc_force" ] && 676 return 1 |
664 fi 665 666 # send the signal to stop 667 # 668 echo "Stopping ${name}." 669 _doit="kill -${sig_stop:-TERM} $rc_pid" 670 if [ -n "$_user" ]; then 671 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 672 fi 673 674 # if the stop cmd failed and force 675 # isn't set, exit 676 # | 677 fi 678 679 # send the signal to stop 680 # 681 echo "Stopping ${name}." 682 _doit="kill -${sig_stop:-TERM} $rc_pid" 683 if [ -n "$_user" ]; then 684 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 685 fi 686 687 # if the stop cmd failed and force 688 # isn't set, exit 689 # |
677 if ! eval $_doit && [ -z "$rc_force" ]; then 678 return 1 679 fi | 690 eval $_doit 691 _return=$? 692 [ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1 |
680 681 # wait for the command to exit, 682 # and run postcmd. 683 wait_for_pids $rc_pid | 693 694 # wait for the command to exit, 695 # and run postcmd. 696 wait_for_pids $rc_pid |
684 eval $_postcmd | 697 if [ -n "$_postcmd" ]; then 698 eval $_postcmd 699 _return=$? 700 fi |
685 ;; 686 687 reload) 688 if [ -z "$rc_pid" ]; then 689 if [ -n "$pidfile" ]; then 690 echo \ 691 "${name} not running? (check $pidfile)." 692 else 693 echo "${name} not running?" 694 fi 695 exit 1 696 fi 697 echo "Reloading ${name} config files." | 701 ;; 702 703 reload) 704 if [ -z "$rc_pid" ]; then 705 if [ -n "$pidfile" ]; then 706 echo \ 707 "${name} not running? (check $pidfile)." 708 else 709 echo "${name} not running?" 710 fi 711 exit 1 712 fi 713 echo "Reloading ${name} config files." |
698 if ! eval $_precmd && [ -z "$rc_force" ]; then 699 return 1 | 714 if [ -n "$_precmd" ]; then 715 eval $_precmd 716 _return=$? 717 [ $_return -ne 0 ] && [ -z "$rc_force" ] && 718 return 1 |
700 fi 701 _doit="kill -${sig_reload:-HUP} $rc_pid" 702 if [ -n "$_user" ]; then 703 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 704 fi | 719 fi 720 _doit="kill -${sig_reload:-HUP} $rc_pid" 721 if [ -n "$_user" ]; then 722 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 723 fi |
705 if ! eval $_doit && [ -z "$rc_force" ]; then 706 return 1 | 724 eval $_doit 725 _return=$? 726 [ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1 727 if [ -n "$_postcmd" ]; then 728 eval $_postcmd 729 _return=$? |
707 fi | 730 fi |
708 eval $_postcmd | |
709 ;; 710 711 restart) | 731 ;; 732 733 restart) |
712 if ! eval $_precmd && [ -z "$rc_force" ]; then 713 return 1 | 734 if [ -n "$_precmd" ]; then 735 eval $_precmd 736 _return=$? 737 [ $_return -ne 0 ] && [ -z "$rc_force" ] && 738 return 1 |
714 fi 715 # prevent restart being called more 716 # than once by any given script 717 # 718 if [ -n "$_rc_restart_done" ]; then 719 return 0 720 fi 721 _rc_restart_done=YES 722 723 ( $0 ${rc_force:+force}stop ) 724 $0 ${rc_force:+force}start 725 | 739 fi 740 # prevent restart being called more 741 # than once by any given script 742 # 743 if [ -n "$_rc_restart_done" ]; then 744 return 0 745 fi 746 _rc_restart_done=YES 747 748 ( $0 ${rc_force:+force}stop ) 749 $0 ${rc_force:+force}start 750 |
726 eval $_postcmd | 751 if [ -n "$_postcmd" ]; then 752 eval $_postcmd 753 _return=$? 754 fi |
727 ;; 728 729 poll) 730 if [ -n "$rc_pid" ]; then 731 wait_for_pids $rc_pid 732 fi 733 ;; 734 --- 8 unchanged lines hidden (view full) --- 743 fi 744 ;; 745 746 *) 747 rc_usage "$_keywords" 748 ;; 749 750 esac | 755 ;; 756 757 poll) 758 if [ -n "$rc_pid" ]; then 759 wait_for_pids $rc_pid 760 fi 761 ;; 762 --- 8 unchanged lines hidden (view full) --- 771 fi 772 ;; 773 774 *) 775 rc_usage "$_keywords" 776 ;; 777 778 esac |
751 return 0 | 779 return $_return |
752 done 753 754 echo 1>&2 "$0: unknown directive '$rc_arg'." 755 rc_usage "$_keywords" 756 exit 1 757} 758 759# --- 248 unchanged lines hidden --- | 780 done 781 782 echo 1>&2 "$0: unknown directive '$rc_arg'." 783 rc_usage "$_keywords" 784 exit 1 785} 786 787# --- 248 unchanged lines hidden --- |