summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/initscripts/initscripts-1.0/functions
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/initscripts/initscripts-1.0/functions')
-rw-r--r--meta/recipes-core/initscripts/initscripts-1.0/functions60
1 files changed, 60 insertions, 0 deletions
diff --git a/meta/recipes-core/initscripts/initscripts-1.0/functions b/meta/recipes-core/initscripts/initscripts-1.0/functions
new file mode 100644
index 0000000000..8e15762f8a
--- /dev/null
+++ b/meta/recipes-core/initscripts/initscripts-1.0/functions
@@ -0,0 +1,60 @@
1# -*-Shell-script-*-
2#
3# functions This file contains functions to be used by most or all
4# shell scripts in the /etc/init.d directory.
5#
6# NOTE: The pidofproc () doesn't support the process which is a script unless
7# the pidof supports "-x" option. If you want to use it for such a
8# process:
9# 1) If there is no "pidof -x", replace the "pidof $1" with another
10# command like(for core-image-minimal):
11# ps | awk '/'"$1"'/ {print $1}'
12# Or
13# 2) If there is "pidof -x", replace "pidof" with "pidof -x".
14#
15# pidofproc - print the pid of a process
16# $1: the name of the process
17pidofproc () {
18
19 # pidof output null when no program is running, so no "2>/dev/null".
20 pid=`pidof $1`
21 status=$?
22 case $status in
23 0)
24 echo $pid
25 return 0
26 ;;
27 127)
28 echo "ERROR: command pidof not found" >&2
29 exit 127
30 ;;
31 *)
32 return $status
33 ;;
34 esac
35}
36
37machine_id() { # return the machine ID
38 awk 'BEGIN { FS=": " } /Hardware/ \
39 { gsub(" ", "_", $2); print tolower($2) } ' </proc/cpuinfo
40}
41
42killproc() { # kill the named process(es)
43 pid=`pidofproc $1` && kill $pid
44}
45
46status() {
47 local pid
48 if [ "$#" = 0 ]; then
49 echo "Usage: status {program}"
50 return 1
51 fi
52 pid=`pidofproc $1`
53 if [ -n "$pid" ]; then
54 echo "$1 (pid $pid) is running..."
55 return 0
56 else
57 echo "$1 is stopped"
58 fi
59 return 3
60}