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')
-rwxr-xr-xmeta/recipes-core/initscripts/initscripts-1.0/functions91
1 files changed, 91 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 100755
index 0000000000..01ad1edd3e
--- /dev/null
+++ b/meta/recipes-core/initscripts/initscripts-1.0/functions
@@ -0,0 +1,91 @@
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
7NORMAL="\\033[0;39m" # Standard console grey
8SUCCESS="\\033[1;32m" # Success is green
9WARNING="\\033[1;33m" # Warnings are yellow
10FAILURE="\\033[1;31m" # Failures are red
11INFO="\\033[1;36m" # Information is light cyan
12BRACKET="\\033[1;34m" # Brackets are blue
13
14# NOTE: The pidofproc () doesn't support the process which is a script unless
15# the pidof supports "-x" option. If you want to use it for such a
16# process:
17# 1) If there is no "pidof -x", replace the "pidof $1" with another
18# command like(for core-image-minimal):
19# ps | awk '/'"$1"'/ {print $1}'
20# Or
21# 2) If there is "pidof -x", replace "pidof" with "pidof -x".
22#
23# pidofproc - print the pid of a process
24# $1: the name of the process
25pidofproc () {
26
27 # pidof output null when no program is running, so no "2>/dev/null".
28 pid=`pidof $1`
29 status=$?
30 case $status in
31 0)
32 echo $pid
33 return 0
34 ;;
35 127)
36 echo "ERROR: command pidof not found" >&2
37 exit 127
38 ;;
39 *)
40 return $status
41 ;;
42 esac
43}
44
45machine_id() { # return the machine ID
46 awk 'BEGIN { FS=": " } /Hardware/ \
47 { gsub(" ", "_", $2); print tolower($2) } ' </proc/cpuinfo
48}
49
50killproc() { # kill the named process(es)
51 pid=`pidofproc $1` && kill $pid
52}
53
54status() {
55 local pid
56 if [ "$#" = 0 ]; then
57 echo "Usage: status {program}"
58 return 1
59 fi
60 pid=`pidofproc $1`
61 if [ -n "$pid" ]; then
62 echo "$1 (pid $pid) is running..."
63 return 0
64 else
65 echo "$1 is stopped"
66 fi
67 return 3
68}
69
70success() {
71 echo -n -e "${BRACKET}[${SUCCESS} OK ${BRACKET}]${NORMAL}"
72 return 0
73}
74
75failure() {
76 local rc=$*
77 echo -n -e "${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
78 return $rc
79}
80
81warning() {
82 local rc=$*
83 echo -n -e "${BRACKET}[${WARNING} WARN ${BRACKET}]${NORMAL}"
84 return $rc
85}
86
87passed() {
88 local rc=$*
89 echo -n -e "${BRACKET}[${SUCCESS} PASS ${BRACKET}]${NORMAL}"
90 return $rc
91}