Index: libexec/rc/rc.subr =================================================================== --- libexec/rc/rc.subr +++ libexec/rc/rc.subr @@ -804,7 +804,8 @@ # # ${name}_prepend n Command added before ${command}. # -# ${name}_setup n Command executed before ${command}. +# ${name}_setup n Command executed during a (re)start before +# ${command} or a reload before ${sig_reload}. # # ${name}_login_class n Login class to use, else "daemon". # @@ -1044,9 +1045,9 @@ return 1 fi - # if there's a custom ${XXX_cmd}, - # run that instead of the default - # + # if there's a custom ${XXX_cmd}, + # run that instead of the default + # eval _cmd=\$${rc_arg}_cmd \ _precmd=\$${rc_arg}_precmd \ _postcmd=\$${rc_arg}_postcmd @@ -1056,6 +1057,11 @@ eval "export -- $_env" fi _run_rc_precmd || return 1 + # service can redefine all so check for valid targets + if [ "$rc_arg" = 'start' -o "$rc_arg" = 'restart' -o \ + "$rc_arg" = 'reload' ]; then + _run_rc_setup || warn "failed to setup ${name}" + fi _run_rc_doit "$_cmd $rc_extra_args" || return 1 _run_rc_postcmd return $_return @@ -1151,24 +1157,20 @@ fi fi - if [ -n "$_setup" ]; then - if ! _run_rc_doit "$_setup"; then - warn "failed to setup ${name}" - fi - fi + _run_rc_setup || warn "failed to setup ${name}" - # Prepend default limits + # Prepend default limits _doit="$_cd limits -C $_login_class $_limits $_doit" - # run the full command - # + # run the full command + # if ! _run_rc_doit "$_doit"; then warn "failed to start ${name}" return 1 fi - # finally, run postcmd - # + # finally, run postcmd + # _run_rc_postcmd ;; @@ -1202,6 +1204,8 @@ _run_rc_precmd || return 1 + _run_rc_setup || warn "failed to setup ${name}" + _doit=$(_run_rc_killcmd "${sig_reload:-HUP}") _run_rc_doit "$_doit" || return 1 @@ -1324,6 +1328,7 @@ # _precmd R # _postcmd R # _return W +# _setup R # _run_rc_precmd() { @@ -1355,6 +1360,19 @@ return 0 } +_run_rc_setup() +{ + if [ -n "$_setup" ]; then + debug "run_rc_command: ${rc_arg}_setup: $_setup" + eval "$_setup" + _return=$? + if [ $_return -ne 0 ]; then + return 1 + fi + fi + return 0 +} + _run_rc_doit() { debug "run_rc_command: doit: $*"