aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/initscripts/initscripts-1.0/functions
blob: 944e3a59b05647e73fdd1bce319fff5e8f008b33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*-Shell-script-*-
#
# functions     This file contains functions to be used by most or all
#               shell scripts in the /etc/init.d directory.
#
# NOTE: The pidofproc () doesn't support the process which is a script unless
#       the pidof supports "-x" option. If you want to use it for such a
#       process:
#       1) If there is no "pidof -x", replace the "pidof $1" with another
#          command like(for core-image-minimal):
#            ps | awk '/'"$1"'/ {print $1}'
#       Or
#       2) If there is "pidof -x", replace "pidof" with "pidof -x".
#
# pidofproc - print the pid of a process
# $1: the name of the process
pidofproc () {

	# pidof output null when no program is running, so no "2>/dev/null".
	pid=`pidof $1`
	status=$?
	case $status in
	0)
		echo $pid
		return 0
		;;
	127)
		echo "ERROR: command pidof not found" >&2
		exit 127
		;;
	*)
		return $status
		;;
	esac
}

machine_id() { # return the machine ID
	awk 'BEGIN { FS=": " } /Hardware/ \
		{ gsub(" ", "_", $2); print tolower($2) } ' </proc/cpuinfo
}

killproc() { # kill the named process(es)
	pid=`pidofproc $1` && kill $pid
}

status() {
    local pid
    if [ "$#" = 0 ]; then
        echo "Usage: status {program}"
        return 1
    fi
    pid=`pidofproc $1`
    if [ -n "$pid" ]; then
        echo "$1 (pid $pid) is running..."
    else
        echo "$1 is stopped"
    fi
    return 3
}