/[vps]/baselayout-vserver/branches/baselayout-1_12/sbin/rc-daemon.sh
Gentoo

Diff of /baselayout-vserver/branches/baselayout-1_12/sbin/rc-daemon.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 205 Revision 206
24RC_RETRY_TIMEOUT=1 24RC_RETRY_TIMEOUT=1
25RC_RETRY_COUNT=5 25RC_RETRY_COUNT=5
26RC_FAIL_ON_ZOMBIE="no" 26RC_FAIL_ON_ZOMBIE="no"
27RC_KILL_CHILDREN="no" 27RC_KILL_CHILDREN="no"
28RC_WAIT_ON_START="0.1" 28RC_WAIT_ON_START="0.1"
29
30# Override default settings with user settings ...
31[[ -f /etc/conf.d/rc ]] && source /etc/conf.d/rc
32 29
33# void rc_shift_args(void) 30# void rc_shift_args(void)
34# 31#
35# Proccess vars - makes things easier by using the shift command 32# Proccess vars - makes things easier by using the shift command
36# and indirect variables 33# and indirect variables
101 98
102 [[ -z ${cmd} ]] && cmd="${name}" 99 [[ -z ${cmd} ]] && cmd="${name}"
103 100
104 # We may want to launch the daemon with a custom command 101 # We may want to launch the daemon with a custom command
105 # This is mainly useful for debugging with apps like valgrind, strace 102 # This is mainly useful for debugging with apps like valgrind, strace
106 local bash_service=$( bash_variable "${myservice}" ) 103 local bash_service="$( bash_variable "${myservice}" )"
107 eval x=\"\$\{RC_DAEMON_${bash_service}\}\" 104 eval x=\"\$\{RC_DAEMON_${bash_service}\}\"
108 if [[ -n ${x} ]]; then 105 if [[ -n ${x} ]]; then
109 local -a d=( ${x} ) 106 local -a d=( ${x} )
110 if ${stopping}; then 107 if ${stopping}; then
111 args="--stop" 108 args="--stop"
118 for (( i=0; i<j; i++ )); do 115 for (( i=0; i<j; i++ )); do
119 [[ ${d[i]:0:1} != "-" ]] && break 116 [[ ${d[i]:0:1} != "-" ]] && break
120 args="${args} ${d[i]}" 117 args="${args} ${d[i]}"
121 unset d[i] 118 unset d[i]
122 done 119 done
123 d=$( "${d[@]}" ) 120 d=( "${d[@]}" )
124 121
125 eval args=\"${args} --exec '${d[0]}' -- ${d[@]:1} '${cmd}' ${eargs[@]}\" 122 eval args=\"${args} --exec '${d[0]}' -- ${d[@]:1} '${cmd}' ${eargs[@]}\"
126 ! ${stopping} && cmd="${d[0]}" 123 ! ${stopping} && cmd="${d[0]}"
127 fi 124 fi
128 125
146 if ${session} ; then 143 if ${session} ; then
147 if [[ -x /usr/bin/pkill ]]; then 144 if [[ -x /usr/bin/pkill ]]; then
148 pkill "-${signal}" -s "${pid}" 145 pkill "-${signal}" -s "${pid}"
149 pgrep -s "${pid}" >/dev/null || return 0 146 pgrep -s "${pid}" >/dev/null || return 0
150 else 147 else
151 local pids=$(ps -eo pid,sid | sed -n 's/'${pid}'$//p') 148 local pids="$(ps -eo pid,sid | sed -n 's/'${pid}'$//p')"
152 [[ -z ${pids} ]] && return 0 149 [[ -z ${pids} ]] && return 0
153 kill -s "${signal}" ${pids} 2>/dev/null 150 kill -s "${signal}" ${pids} 2>/dev/null
154 e=false 151 e=false
155 for p in ${pids}; do 152 for p in ${pids}; do
156 if [[ -d "/proc/${p}" ]]; then 153 if [[ -d "/proc/${p}" ]]; then
217 shift 214 shift
218 done 215 done
219 pidfile="$1" 216 pidfile="$1"
220 fi 217 fi
221 218
222 pids=$( pidof ${cmd} ) 219 pids="$( pidof ${cmd} )"
223 [[ -z ${pids} ]] && return 1 220 [[ -z ${pids} ]] && return 1
224 221
225 [[ -s ${pidfile} ]] || return 0 222 [[ -s ${pidfile} ]] || return 0
226 223
227 read pid < "${pidfile}" 224 read pid < "${pidfile}"
257 is_daemon_running ${cmd} "${pidfile}" 254 is_daemon_running ${cmd} "${pidfile}"
258 retval="$?" 255 retval="$?"
259 [[ ${retval} == "0" ]] && return 0 256 [[ ${retval} == "0" ]] && return 0
260 257
261 # Stop if we can to clean things up 258 # Stop if we can to clean things up
262 if [[ $( type -t stop ) == "function" ]]; then 259 [[ -n ${pidfile} ]] && rc_stop_daemon
263 stop >/dev/null # We don't want to echo ebegin/eend 260
264 elif [[ -n ${pidfile} ]]; then
265 rc_stop_daemon
266 fi
267 return "${retval}" 261 return "${retval}"
268} 262}
269 263
270# bool rc_stop_daemon(void) 264# bool rc_stop_daemon(void)
271# 265#
277 271
278 if [[ -n ${cmd} ]]; then 272 if [[ -n ${cmd} ]]; then
279 if ! is_daemon_running ${cmd} "${pidfile}" ; then 273 if ! is_daemon_running ${cmd} "${pidfile}" ; then
280 [[ ${RC_FAIL_ON_ZOMBIE} == "yes" ]] && return 1 274 [[ ${RC_FAIL_ON_ZOMBIE} == "yes" ]] && return 1
281 fi 275 fi
282 pids=$( pidof ${cmd} ) 276 pids="$( pidof ${cmd} )"
283 fi 277 fi
284 278
285 if [[ -s ${pidfile} ]]; then 279 if [[ -s ${pidfile} ]]; then
286 read pid < "${pidfile}" 280 read pid < "${pidfile}"
287 # Check that the given program is actually running the pid 281 # Check that the given program is actually running the pid
297 291
298 # We may not have pgrep to find our children, so we provide 292 # We may not have pgrep to find our children, so we provide
299 # two methods 293 # two methods
300 if [[ ${RC_KILL_CHILDREN} == "yes" ]]; then 294 if [[ ${RC_KILL_CHILDREN} == "yes" ]]; then
301 if [[ -x /usr/bin/pgrep ]]; then 295 if [[ -x /usr/bin/pgrep ]]; then
302 pids="${pids} $(pgrep -P ${pids// /,})" 296 pids="${pids} $(pgrep -P "${pids// /,}")"
303 else 297 else
304 local npids 298 local npids
305 for pid in ${pids} ; do 299 for pid in ${pids} ; do
306 npids="${npids} $(ps -eo pid,ppid | sed -n 's/'${pid}'$//p')" 300 npids="${npids} $(ps -eo pid,ppid | sed -n 's/'"${pid}"'$//p')"
307 done 301 done
308 pids="${pids} ${npids}" 302 pids="${pids} ${npids}"
309 fi 303 fi
310 fi 304 fi
311 305
360# 354#
361# Provide a wrapper to start-stop-daemon 355# Provide a wrapper to start-stop-daemon
362# Return the result of start_daemon or stop_daemon depending on 356# Return the result of start_daemon or stop_daemon depending on
363# how we are called 357# how we are called
364start-stop-daemon() { 358start-stop-daemon() {
365 local args=$( requote "$@" ) result i 359 local args="$( requote "$@" )" result i
366 local cmd pidfile pid stopping signal nothing=false 360 local cmd pidfile pid stopping signal nothing=false
367 local daemonfile="${svcdir}/daemons/${myservice}" 361 local daemonfile="${svcdir}/daemons/${myservice}"
368 local -a RC_DAEMONS=() RC_PIDFILES=() 362 local -a RC_DAEMONS=() RC_PIDFILES=()
369 363
370 [[ -e ${daemonfile} ]] && source "${daemonfile}" 364 [[ -e ${daemonfile} ]] && source "${daemonfile}"

Legend:
Removed from v.205  
changed lines
  Added in v.206

  ViewVC Help
Powered by ViewVC 1.1.20