source: bootscripts/contrib/lsb-v3/init.d/lfs-functions@ 12bc336

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 6.4 6.5 6.6 6.7 6.8 7.0 7.1 7.2 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 12bc336 was 1c48007, checked in by Bruce Dubbs <bdubbs@…>, 16 years ago

Moved bootscripts and udev-config to BOOK
Updated Makefile to automatically generate bootscript and udev-config tarballs
Updated licesnse to be the same as BLFS

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@8548 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 7.3 KB
Line 
1# Begin /etc/init.d/lfs-functions
2# Provides LFS specific functions for LSB style bootscripts
3
4################################# chkstat() ###################################
5# chk_stat checks the status of a script by checking for both a binary file #
6# to execute, and if set, a config file that may be needed for the program #
7# to run successfully. The calling script will exit with a return value of 5 #
8# if the binary does not exist, and a value of 6 if the needed config file is #
9# unavailable as per LSB requirements. This function accepts zero, one, or #
10# two string arguments. If arguments are passed, the first must be a bin #
11# file. If a second argument is passed, it is interpreted as the config #
12# file. Optionally, zero arguments can be passed if BIN_FILE, and optinally #
13# CONFIG_FILE are set in the calling script. #
14###############################################################################
15chk_stat()
16{
17 if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
18 BIN_FILE="${1}"
19 if [ -z "${2}" ]; then
20 CONFIG_FILE=""
21 else
22 CONFIG_FILE="${2}"
23 fi
24 elif [ -z "${BIN_FILE}" ]; then
25 echo "Usage: 'chk_stat BIN_FILE CONFIG_FILE'"
26 exit 1 # Generic Error
27 fi
28
29 if [ ! -e "${BIN_FILE}" ]; then
30 log_failure_msg "${BIN_FILE} not installed" &&
31 exit 5
32 fi
33
34 if [ ! -z "${CONFIG_FILE}" ]; then
35 if [ ! -e "${CONFIG_FILE}" ]; then
36 log_failure_msg "${CONFIG_FILE} does not exist" &&
37 exit 6
38 fi
39 fi
40}
41
42################################ loadproc() ###################################
43# loadproc is just a wraper to start_daemon for simple scripts, which will #
44# require no arguments if $BIN_FILE is set. #
45###############################################################################
46loadproc()
47{
48 start_daemon "${BIN_FILE}" "${@}"
49}
50
51################################ endproc() ####################################
52# endproc, like loadproc, is just a wraper to killproc for simplicity and is #
53# dependent on $BIN_FILE being set. #
54###############################################################################
55endproc()
56{
57 killproc "${BIN_FILE}" "${@}"
58}
59
60############################### statusproc() ##################################
61# statusproc checks the status of a particular binary and displays the #
62# appropriate message (running or not running) and exits on the return value #
63# of pidofproc. This function accepts two string arguments or zero arguments #
64# if BIN_FILE and MESSAGE are set, else it requires the bin file as the first #
65# argument, and the message as the second. Both must be enclosed in quotes. #
66###############################################################################
67statusproc()
68{
69 if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
70 BIN_FILE="${1}"
71 MESSAGE="${2}"
72 elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then
73 echo "Usage: 'statusproc BIN_FILE MESSAGE'"
74 exit 1 # Generic Error
75 fi
76
77 pidlist=`pidofproc "${BIN_FILE}"`
78 STATUS=$?
79 echo "Checking ${MESSAGE} status:"
80 if [ "${STATUS}" = "0" ]; then
81 log_success_msg "Running with PID(s) ${pidlist}"
82 else
83
84 log_warning_msg "Not running!"
85 fi
86
87 return "${STATUS}"
88}
89
90############################### reloadproc() ##################################
91# reloadproc sends a HUP signal to the running program (relaod configuration) #
92# It optionally, using the -force switch, checks the status of a particular #
93# program and starts it if it is not already running. This function accepts #
94# one optional switch (must be the first argument), and either two, or zero #
95# string arguments. If BIN_FILE and MESSAGE are set in the script's #
96# environment, it will use those values, else it requires the bin file as #
97# the first argument (following -force if used), and the message as the #
98# second. Both must be enclosed in quotes. If the force option is used, it #
99# follows the LSB definition of 'force-reload' - the program is started if #
100# not already running. #
101###############################################################################
102reloadproc()
103{
104 local force="0"
105 if [ "${#}" -gt "0" -a "${1}" = "-force" ]; then
106 force="1"
107 shift 1
108 fi
109
110 if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
111 BIN_FILE="${1}"
112 MESSAGE="${2}"
113 elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then
114 echo "Usage: 'reloadproc BIN_FILE MESSAGE'"
115 exit 1 # Generic Error
116 fi
117
118
119
120}
121
122############################## evaluate_retval() ###############################
123# evaluate_retval requires that you pass exactly one evaluation parameter of #
124# (start, stop, other) based on the previous action that is being evaluated. #
125# This function is intended for use with start_daemon and killproc to #
126# interpret the LSB exit codes properly, othewise the checks only for success #
127# or failure. #
128################################################################################
129evaluate_retval()
130{
131 local error_value="${?}"
132
133 # Handle LSB defined return values
134 case "${1}" in
135
136 start)
137 case "${error_value}" in
138 0)
139 log_success_msg "Starting ${MESSAGE} "
140 return "${error_value}"
141 ;;
142 2)
143 log_failure_msg "Starting ${MESSAGE} Error: Invalid argument!"
144 return "${error_value}"
145 ;;
146 5)
147 log_failure_msg "Starting ${MESSAGE} Error: Not available!"
148 return "${error_value}"
149 ;;
150 *)
151 log_failure_msg "Starting ${MESSAGE} Error: General failure!"
152 return "${error_value}"
153 ;;
154 esac
155 ;;
156
157 stop)
158 case "${error_value}" in
159 0)
160 log_success_msg "Stopping ${MESSAGE} "
161 return "${error_value}"
162 ;;
163 2)
164 log_failure_msg "Stopping ${MESSAGE} Error: Invalid argument!"
165 return "${error_value}"
166 ;;
167 5)
168 log_failure_msg "Stopping ${MESSAGE} Error: Not available!"
169 return "${error_value}"
170 ;;
171 7)
172 log_warning_msg "Stopping ${MESSAGE} Warning: Not running!"
173 return "${error_value}"
174 ;;
175 *)
176 log_failure_msg "Stopping ${MESSAGE} Error: General failure!"
177 return "${error_value}"
178 ;;
179 esac
180 ;;
181
182 force-reload)
183 message="Forcefully reloading "
184 ;;
185
186 reload)
187 message="Reloading "
188 ;;
189
190 restart)
191 message="Restarting "
192 ;;
193
194 try-restart)
195 message="Trying restart "
196 ;;
197
198 standard)
199 # $message or $MESSAGE must be set, but not both in order
200 # to use the 'standard' target.
201 ;;
202 esac
203
204 # Print messages for the generic force-reload, reload, restart,
205 # and try-restart targets
206 if [ "${error_value}" = "0" ]
207 then
208 log_success_msg "${message}${MESSAGE} "
209 return "${error_value}"
210 else
211 log_failure_msg "${message}${MESSAGE} "
212 return "${error_value}"
213 fi
214}
215
Note: See TracBrowser for help on using the repository browser.