version 1.20, 2000/06/09 14:27:57 |
version 1.20.2.4, 2000/10/02 01:02:49 |
|
|
# force Set ${rcvar} to YES. |
# force Set ${rcvar} to YES. |
# |
# |
# The following globals are used: |
# The following globals are used: |
|
# |
# name needed function |
# name needed function |
# ---- ------ -------- |
# ---- ------ -------- |
# name y Name of script. |
# name y Name of script. |
|
# |
# command n Full path to command. |
# command n Full path to command. |
# Not needed if ${arg}_cmd is set for |
# Not needed if ${arg}_cmd is set for |
# each keyword. |
# each keyword. |
|
# |
# command_args n Optional args/shell directives for command. |
# command_args n Optional args/shell directives for command. |
|
# |
# extra_commands n List of extra commands supported. |
# extra_commands n List of extra commands supported. |
|
# |
# pidfile n If set, use check_pidfile $pidfile, else if |
# pidfile n If set, use check_pidfile $pidfile, else if |
# $command is set, use check_process $command. |
# $command is set, use check_process $command. |
# rcvar n If the default command is being run, this is |
# |
# checked with checkyesno to determine if |
# rcvar n This is checked with checkyesno to determine |
# the action should be run. |
# if the action should be run. |
# If this variable isn't set, ${name} is checked |
# |
# instead. |
# ${name}_chroot n Directory to chroot to before running ${command} |
# ${name}_chdir n Directory to cd to before running ${command}. |
# |
|
# ${name}_chdir n Directory to cd to before running ${command} |
|
# (if not using ${name}_chroot). |
|
# |
# ${name}_flags n Arguments to call ${command} with. |
# ${name}_flags n Arguments to call ${command} with. |
# NOTE: if $flags is set (e.g, from the parent |
# NOTE: $flags from the parent environment |
# environment), it overrides this. |
# can be used to override this. |
|
# |
# ${name}_nice n Nice level to run ${command} at. |
# ${name}_nice n Nice level to run ${command} at. |
# ${name}_user n User to run ${command} as. |
# |
|
# ${name}_user n User to run ${command} as, using su(1) if not |
|
# using ${name}_chroot. |
|
# |
|
# ${name}_group n Group to run chrooted ${command} as. |
|
# |
|
# ${name}_groups n Supplementary group list to run chrooted |
|
# ${command} with. |
|
# |
# ${_arg}_cmd n If set, use this as the action when invoked; |
# ${_arg}_cmd n If set, use this as the action when invoked; |
# $_arg is available to the action to use. |
# $_arg is available to the action to use. |
# Otherwise, use default command (see below) |
# Otherwise, use default command (see below) |
# NOTE: checkyesno ${rcvar} is NOT performed |
# |
# for ${_arg}_cmd; use ${_arg}_precmd to |
|
# do this. |
|
# ${_arg}_precmd n If set, run just before performing the main |
# ${_arg}_precmd n If set, run just before performing the main |
# action in the default command (i.e, after |
# action in the default command (i.e, after |
# checking for required bits and process |
# checking for required bits and process |
# (non)existance). |
# (non)existance). |
# If this completes with a non-zero exit code, |
# If this completes with a non-zero exit code, |
# don't run ${_arg}_cmd. |
# don't run ${_arg}_cmd. |
|
# |
# required_dirs n If set, check for the existence of the given |
# required_dirs n If set, check for the existence of the given |
# directories before running the default |
# directories before running the default |
# (re)start command. |
# (re)start command. |
|
# |
# required_files n If set, check for the readability of the given |
# required_files n If set, check for the readability of the given |
# files before running the default (re)start |
# files before running the default (re)start |
# command. |
# command. |
|
# |
# required_vars n If set, perform checkyesno on each of the |
# required_vars n If set, perform checkyesno on each of the |
# listed variables before running the default |
# listed variables before running the default |
# (re)start command. |
# (re)start command. |
# |
# |
# Default commands for a given arg: |
# Default commands for a given arg: |
|
# |
# arg default |
# arg default |
# --- ------- |
# --- ------- |
# status Show if ${command} is running, etc. |
# status Show if ${command} is running, etc. |
|
# |
# start if !running && checkyesno ${rcvar} |
# start if !running && checkyesno ${rcvar} |
# ${command} |
# ${command} |
|
# |
# stop if ${pidfile} |
# stop if ${pidfile} |
# kill $sig_stop `check_pidfile $pidfile` |
# kill $sig_stop `check_pidfile $pidfile` |
# else |
# else |
# kill $sig_stop `check_process $command` |
# kill $sig_stop `check_process $command` |
# $sig_stop defaults to TERM. |
# $sig_stop defaults to TERM. |
|
# |
# reload As stop, except use $sig_reload instead. |
# reload As stop, except use $sig_reload instead. |
# $sig_reload defaults to HUP. |
# $sig_reload defaults to HUP. |
|
# |
# restart Run `stop' then `start'. |
# restart Run `stop' then `start'. |
# |
# |
|
# |
run_rc_command() |
run_rc_command() |
{ |
{ |
_arg=$1 |
_arg=$1 |
_ckvar=${rcvar:-$name} |
if [ -z "$name" ]; then |
if [ -z "$_ckvar" ]; then |
err 3 '$name is not set.' |
err 3 'neither $rcvar or $name is set.' |
|
fi |
fi |
|
|
case "$_arg" in |
case "$_arg" in |
fast*) |
fast*) # "fast" prefix; don't check pid |
_arg=${_arg#fast} |
_arg=${_arg#fast} |
_rc_fast_run=YES |
_rc_fast_run=YES |
;; |
;; |
force*) |
force*) # "force prefix; always start |
_arg=${_arg#force} |
_arg=${_arg#force} |
eval ${_ckvar}=YES |
_rc_force_run=YES |
|
eval ${rcvar}=YES |
;; |
;; |
esac |
esac |
|
|
_keywords="start stop restart rcvar $extra_commands" |
_keywords="start stop restart rcvar $extra_commands" |
_pid= |
_pid= |
_pidcmd= |
_pidcmd= |
|
# setup pid check command if not fast |
if [ -z "$_rc_fast_run" ]; then |
if [ -z "$_rc_fast_run" ]; then |
if [ -n "$pidfile" ]; then |
if [ -n "$pidfile" ]; then |
_pidcmd='_pid=`check_pidfile '$pidfile' '$command'`' |
_pidcmd='_pid=`check_pidfile '$pidfile' '$command'`' |
Line 271 run_rc_command() |
|
Line 296 run_rc_command() |
|
eval _flags=\$${name}_flags |
eval _flags=\$${name}_flags |
fi |
fi |
eval _chdir=\$${name}_chdir |
eval _chdir=\$${name}_chdir |
|
eval _chroot=\$${name}_chroot |
eval _nice=\$${name}_nice |
eval _nice=\$${name}_nice |
eval _user=\$${name}_user |
eval _user=\$${name}_user |
|
eval _group=\$${name}_group |
|
eval _groups=\$${name}_groups |
|
|
eval $_pidcmd |
# if ${rcvar} is set and we're not |
|
# running `rcvar', then check it |
|
# |
|
if [ -n "${rcvar}" -a "$_arg" != "rcvar" ]; then |
|
if ! checkyesno ${rcvar}; then |
|
return 0 |
|
fi |
|
fi |
|
|
|
eval $_pidcmd # determine the pid if necessary |
|
|
for _elem in $_keywords; do |
for _elem in $_keywords; do |
if [ "$_elem" != "$_arg" ]; then |
if [ "$_elem" != "$_arg" ]; then |
continue |
continue |
fi |
fi |
|
|
|
# if there's a custom ${XXX_cmd}, |
|
# run that instead of the default |
|
# |
eval _cmd=\$${_arg}_cmd |
eval _cmd=\$${_arg}_cmd |
eval _precmd=\$${_arg}_precmd |
eval _precmd=\$${_arg}_precmd |
if [ -n "$_cmd" ]; then |
if [ -n "$_cmd" ]; then |
eval $_precmd || return 1 |
# if the precmd failed and force |
|
# isn't set, exit |
|
# |
|
if ! eval $_precmd && [ -z "$_rc_force_run" ]; then |
|
return 1 |
|
fi |
|
|
eval $_cmd |
eval $_cmd |
return 0 |
return 0 |
fi |
fi |
|
|
case "$_arg" in |
case "$_arg" in # default operations... |
|
|
status) |
status) |
if [ -n "$_pid" ]; then |
if [ -n "$_pid" ]; then |
Line 305 run_rc_command() |
|
Line 351 run_rc_command() |
|
exit 1 |
exit 1 |
fi |
fi |
|
|
if ! checkyesno ${_ckvar} || [ ! -x $command ]; then |
if [ ! -x $command ]; then |
return 0 |
return 0 |
fi |
fi |
|
|
|
# check for required variables, |
|
# directories, and files |
|
# |
for _f in $required_vars; do |
for _f in $required_vars; do |
if ! checkyesno $_f; then |
if ! checkyesno $_f; then |
warn \ |
warn "\$${_f} is not set." |
"\$${_f} is not set; ${name} not started." |
if [ -z "$_rc_force_run" ]; then |
return 1 |
return 1 |
|
fi |
fi |
fi |
done |
done |
for _f in $required_dirs; do |
for _f in $required_dirs; do |
if [ ! -d "${_f}/." ]; then |
if [ ! -d "${_f}/." ]; then |
warn \ |
warn "${_f} is not a directory." |
"${_f} is not a directory; ${name} not started." |
if [ -z "$_rc_force_run" ]; then |
return 1 |
return 1 |
|
fi |
fi |
fi |
done |
done |
for _f in $required_files; do |
for _f in $required_files; do |
if [ ! -r "${_f}" ]; then |
if [ ! -r "${_f}" ]; then |
warn \ |
warn "${_f} is not readable." |
"${_f} is not readable; ${name} not started." |
if [ -z "$_rc_force_run" ]; then |
return 1 |
return 1 |
|
fi |
fi |
fi |
done |
done |
|
|
eval $_precmd || return 1 |
# if the precmd failed and force |
|
# isn't set, exit |
|
# |
|
if ! eval $_precmd && [ -z "$_rc_force_run" ]; then |
|
return 1 |
|
fi |
|
|
|
|
|
# setup the command to run, and run it |
echo "Starting ${name}." |
echo "Starting ${name}." |
_doit="\ |
if [ -n "$_chroot" ]; then |
|
_doit="\ |
|
${_nice:+nice -n $_nice }\ |
|
chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\ |
|
$_chroot $command $_flags $command_args" |
|
else |
|
_doit="\ |
${_user:+su -m $_user -c 'sh -c \"}\ |
${_user:+su -m $_user -c 'sh -c \"}\ |
${_chdir:+cd $_chdir; }\ |
${_chdir:+cd $_chdir; }\ |
${_nice:+nice -n $_nice }\ |
${_nice:+nice -n $_nice }\ |
$command $_flags $command_args\ |
$command $_flags $command_args\ |
${_user:+\"'}" |
${_user:+\"'}" |
|
fi |
eval $_doit |
eval $_doit |
;; |
;; |
|
|
stop) |
stop) |
if [ -z "$_pid" ]; then |
if [ -z "$_pid" ]; then |
if checkyesno ${_ckvar}; then |
if [ -n "$pidfile" ]; then |
if [ -n "$pidfile" ]; then |
echo \ |
echo \ |
"${name} not running? (check $pidfile)." |
"${name} not running? (check $pidfile)." |
else |
else |
echo "${name} not running?" |
echo "${name} not running?" |
|
fi |
|
exit 1 |
|
fi |
fi |
return 0 |
exit 1 |
fi |
fi |
|
|
eval $_precmd || return 1 |
if ! eval $_precmd && [ -z "$_rc_force_run" ]; then |
|
return 1 |
|
fi |
echo "Stopping ${name}." |
echo "Stopping ${name}." |
_doit=\ |
_doit=\ |
"${_user:+su -m $_user -c '}kill -${sig_stop:-TERM} $_pid${_user:+'}" |
"${_user:+su -m $_user -c '}kill -${sig_stop:-TERM} $_pid${_user:+'}" |
|
|
|
|
reload) |
reload) |
if [ -z "$_pid" ]; then |
if [ -z "$_pid" ]; then |
if checkyesno ${_ckvar}; then |
if [ -n "$pidfile" ]; then |
if [ -n "$pidfile" ]; then |
echo \ |
echo \ |
|
"${name} not running? (check $pidfile)." |
"${name} not running? (check $pidfile)." |
else |
else |
echo "${name} not running?" |
echo "${name} not running?" |
fi |
|
exit 1 |
|
fi |
fi |
return 0 |
exit 1 |
fi |
fi |
echo "Reloading ${name} config files." |
echo "Reloading ${name} config files." |
eval $_precmd || return 1 |
if ! eval $_precmd && [ -z "$_rc_force_run" ]; then |
|
return 1 |
|
fi |
_doit=\ |
_doit=\ |
"${_user:+su -m $_user -c '}kill -${sig_reload:-HUP} $_pid${_user:+'}" |
"${_user:+su -m $_user -c '}kill -${sig_reload:-HUP} $_pid${_user:+'}" |
eval $_doit |
eval $_doit |
;; |
;; |
|
|
restart) |
restart) |
if ! checkyesno ${_ckvar}; then |
if ! eval $_precmd && [ -z "$_rc_force_run" ]; then |
return 0 |
return 1 |
fi |
fi |
eval $_precmd || return 1 |
|
( $0 stop ) |
( $0 stop ) |
sleep 1 |
sleep 1 |
$0 start |
$0 start |
|
|
|
|
rcvar) |
rcvar) |
echo "# $name" |
echo "# $name" |
if checkyesno ${_ckvar}; then |
if [ -n "$rcvar" ]; then |
echo "\$${_ckvar}=YES" |
if checkyesno ${rcvar}; then |
else |
echo "\$${rcvar}=YES" |
echo "\$${_ckvar}=NO" |
else |
|
echo "\$${rcvar}=NO" |
|
fi |
fi |
fi |
;; |
;; |
|
|
|
|
exitval=$1 |
exitval=$1 |
shift |
shift |
|
|
logger "$0: ERROR $*" |
logger "$0: ERROR: $*" |
echo 1>&2 "$0: ERROR $*" |
echo 1>&2 "$0: ERROR: $*" |
exit $exitval |
exit $exitval |
} |
} |
|
|
|
|
# |
# |
warn() |
warn() |
{ |
{ |
logger "$0: WARNING $*" |
logger "$0: WARNING: $*" |
echo 1>&2 "$0: WARNING $*" |
echo 1>&2 "$0: WARNING: $*" |
} |
} |