[clue-tech] request for Fedora script

marcus hall marcus at tuells.org
Wed Jun 27 12:16:21 MDT 2007


On Wed, Jun 27, 2007 at 05:51:01PM +0000, dennisjperkins at comcast.net wrote:
> I'm looking at some Linux bootscripts and I would like to see how Fedora is handling something.  Could someone send me the script that contains the pidofproc function?  Fedora probably has it in /lib/lsb/init-functions or /etc/rc.d/init.d/functions.  Thanks.

In /etc/init.d/functions:

pidofproc() {
        local RC pid pid_file=

        # Test syntax.
        if [ "$#" = 0 ]; then
                echo $"Usage: pidofproc [-p pidfile] {program}"
                return 1
        fi
        if [ "$1" = "-p" ]; then
                pid_file=$2
                shift 2
        fi
        fail_code=3 # "Program is not running"

        # First try "/var/run/*.pid" files
        __pids_var_run "$1" "$pid_file"
        RC=$?
        if [ -n "$pid" ]; then
                echo $pid
                return 0
        fi

        [ -n "$pid_file" ] && return $RC
        __pids_pidof "$1" || return $RC
}

other routines:

# __proc_pids {program} [pidfile]
# Set $pid to pids from /var/run* for {program}.  $pid should be declared
# local in the caller.
# Returns LSB exit code for the 'status' action.
__pids_var_run() {
        local base=${1##*/}
        local pid_file=${2:-/var/run/$base.pid}

        pid=
        if [ -f "$pid_file" ] ; then
                local line p
                read line < "$pid_file"
                for p in $line ; do
                        [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
                done
                if [ -n "$pid" ]; then
                        return 0
                fi
                return 1 # "Program is dead and /var/run pid file exists"
        fi
        return 3 # "Program is not running"
}

# Output PIDs of matching processes, found using pidof
__pids_pidof() {
        pidof -c -o $$ -o $PPID -o %PPID -x "$1" || \
                pidof -c -o $$ -o $PPID -o %PPID -x "${1##*/}"
}

-- 
Marcus Hall
marcus at tuells.org



More information about the clue-tech mailing list